]> git.ozlabs.org Git - ccan/blob - ccan/opt/test/run-usage.c
2e4ce40061e55b8425cdd44aa69fc6faaac71c64
[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
11 static char *my_cb(void *p)
12 {
13         return NULL;
14 }
15
16 /* Test helpers. */
17 int main(int argc, char *argv[])
18 {
19         char *output;
20         plan_tests(18);
21         opt_register_table(subtables, NULL);
22         opt_register_noarg("kkk", 'k', my_cb, NULL, "magic kkk option");
23         output = opt_usage("my name", "ExTrA Args");
24         diag("%s", output);
25         ok1(strstr(output, "Usage: my name"));
26         ok1(strstr(output, "--jjj/-j <arg>"));
27         ok1(strstr(output, "ExTrA Args"));
28         ok1(strstr(output, "-a "));
29         ok1(strstr(output, " Description of a\n"));
30         ok1(strstr(output, "-b <arg>"));
31         ok1(strstr(output, " Description of b (default: b)\n"));
32         ok1(strstr(output, "--ddd "));
33         ok1(strstr(output, " Description of ddd\n"));
34         ok1(strstr(output, "--eee <arg> "));
35         ok1(strstr(output, " (default: eee)\n"));
36         ok1(strstr(output, "long table options:\n"));
37         /* This table is hidden. */
38         ok1(!strstr(output, "--ggg/-g "));
39         ok1(!strstr(output, " Description of ggg\n"));
40         ok1(!strstr(output, "--hhh/-h <arg>"));
41         ok1(!strstr(output, " Description of hhh\n"));
42         ok1(strstr(output, "--kkk/-k"));
43         ok1(strstr(output, "magic kkk option"));
44         free(output);
45
46         return exit_status();
47 }