]> git.ozlabs.org Git - ccan/blob - ccan/opt/test/run-usage.c
tdb2: extend test/layout to be able to place in file.
[ccan] / ccan / opt / test / run-usage.c
1 #define _GNU_SOURCE
2 #include <ccan/tap/tap.h>
3 #include <stdarg.h>
4 #include <setjmp.h>
5 #include <stdlib.h>
6 #include <stdarg.h>
7 #include "utils.h"
8 #include <ccan/opt/opt.c>
9 #include <ccan/opt/usage.c>
10 #include <ccan/opt/helpers.c>
11
12 static char *my_cb(void *p)
13 {
14         return NULL;
15 }
16
17 /* Test helpers. */
18 int main(int argc, char *argv[])
19 {
20         char *output;
21
22         plan_tests(38);
23         opt_register_table(subtables, NULL);
24         opt_register_noarg("--kkk|-k", my_cb, NULL, "magic kkk option");
25         opt_register_noarg("-?", opt_usage_and_exit, "<MyArgs>...",
26                            "This message");
27         output = opt_usage("my name", "ExTrA Args");
28         diag("%s", output);
29         ok1(strstr(output, "Usage: my name"));
30         ok1(strstr(output, "--jjj|-j|--lll|-l <arg>"));
31         ok1(strstr(output, "ExTrA Args"));
32         ok1(strstr(output, "-a "));
33         ok1(strstr(output, " Description of a\n"));
34         ok1(strstr(output, "-b <arg>"));
35         ok1(strstr(output, " Description of b (default: b)\n"));
36         ok1(strstr(output, "--ddd "));
37         ok1(strstr(output, " Description of ddd\n"));
38         ok1(strstr(output, "--eee <filename> "));
39         ok1(strstr(output, " (default: eee)\n"));
40         ok1(strstr(output, "long table options:\n"));
41         ok1(strstr(output, "--ggg|-g "));
42         ok1(strstr(output, " Description of ggg\n"));
43         ok1(strstr(output, "-h|--hhh <arg>"));
44         ok1(strstr(output, " Description of hhh\n"));
45         ok1(strstr(output, "--kkk|-k"));
46         ok1(strstr(output, "magic kkk option"));
47         /* This entry is hidden. */
48         ok1(!strstr(output, "--mmm|-m"));
49         free(output);
50
51         /* NULL should use string from registered options. */
52         output = opt_usage("my name", NULL);
53         diag("%s", output);
54         ok1(strstr(output, "Usage: my name"));
55         ok1(strstr(output, "--jjj|-j|--lll|-l <arg>"));
56         ok1(strstr(output, "<MyArgs>..."));
57         ok1(strstr(output, "-a "));
58         ok1(strstr(output, " Description of a\n"));
59         ok1(strstr(output, "-b <arg>"));
60         ok1(strstr(output, " Description of b (default: b)\n"));
61         ok1(strstr(output, "--ddd "));
62         ok1(strstr(output, " Description of ddd\n"));
63         ok1(strstr(output, "--eee <filename> "));
64         ok1(strstr(output, " (default: eee)\n"));
65         ok1(strstr(output, "long table options:\n"));
66         ok1(strstr(output, "--ggg|-g "));
67         ok1(strstr(output, " Description of ggg\n"));
68         ok1(strstr(output, "-h|--hhh <arg>"));
69         ok1(strstr(output, " Description of hhh\n"));
70         ok1(strstr(output, "--kkk|-k"));
71         ok1(strstr(output, "magic kkk option"));
72         /* This entry is hidden. */
73         ok1(!strstr(output, "--mmm|-m"));
74         free(output);
75
76         return exit_status();
77 }