]> git.ozlabs.org Git - ccan/blob - ccan/opt/test/run-usage.c
opt: Put actual options inside names.
[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
21         plan_tests(19);
22         opt_register_table(subtables, NULL);
23         opt_register_noarg("--kkk/-k", my_cb, NULL, "magic kkk option");
24         output = opt_usage("my name", "ExTrA Args");
25         diag("%s", output);
26         ok1(strstr(output, "Usage: my name"));
27         ok1(strstr(output, "--jjj/-j/--lll/-l <arg>"));
28         ok1(strstr(output, "ExTrA Args"));
29         ok1(strstr(output, "-a "));
30         ok1(strstr(output, " Description of a\n"));
31         ok1(strstr(output, "-b <arg>"));
32         ok1(strstr(output, " Description of b (default: b)\n"));
33         ok1(strstr(output, "--ddd "));
34         ok1(strstr(output, " Description of ddd\n"));
35         ok1(strstr(output, "--eee <arg> "));
36         ok1(strstr(output, " (default: eee)\n"));
37         ok1(strstr(output, "long table options:\n"));
38         ok1(strstr(output, "--ggg/-g "));
39         ok1(strstr(output, " Description of ggg\n"));
40         ok1(strstr(output, "-h/--hhh <arg>"));
41         ok1(strstr(output, " Description of hhh\n"));
42         ok1(strstr(output, "--kkk/-k"));
43         ok1(strstr(output, "magic kkk option"));
44         /* This entry is hidden. */
45         ok1(!strstr(output, "--mmm/-m"));
46
47         free(output);
48
49         return exit_status();
50 }