3 #include <ccan/tap/tap.h>
10 /* We don't actually want it to exit... */
11 static jmp_buf exited;
12 #define failmsg save_and_jump
14 static void save_and_jump(const char *fmt, ...);
16 #include <ccan/opt/helpers.c>
17 #include <ccan/opt/opt.c>
18 #include <ccan/opt/usage.c>
19 #include <ccan/opt/parse.c>
21 static char *output = NULL;
23 static int saved_vprintf(const char *fmt, va_list ap)
26 int ret = vasprintf(&p, fmt, ap);
29 output = realloc(output, strlen(output) + strlen(p) + 1);
37 static void save_and_jump(const char *fmt, ...)
42 saved_vprintf(fmt, ap);
47 static void reset(void)
53 opt_count = opt_num_short = opt_num_short_arg = opt_num_long = 0;
56 int main(int argc, char *argv[])
62 exitval = setjmp(exited);
65 _opt_register("-a", OPT_SUBTABLE, (void *)opt_version_and_exit,
66 NULL, NULL, "1.2.3", "");
67 fail("_opt_register returned?");
70 ok1(strstr(output, "Option -a: unknown entry type"));
74 exitval = setjmp(exited);
76 /* NULL description. */
77 opt_register_noarg("-a", test_noarg, "", NULL);
78 fail("_opt_register returned?");
81 ok1(strstr(output, "Option -a: description cannot be NULL"));
85 exitval = setjmp(exited);
87 /* Bad option name. */
88 opt_register_noarg("a", test_noarg, "", "");
89 fail("_opt_register returned?");
92 ok1(strstr(output, "Option a: does not begin with '-'"));
97 exitval = setjmp(exited);
99 /* Bad option name. */
100 opt_register_noarg("--", test_noarg, "", "");
101 fail("_opt_register returned?");
104 ok1(strstr(output, "Option --: invalid long option '--'"));
109 exitval = setjmp(exited);
111 /* Bad option name. */
112 opt_register_noarg("--a|-aaa", test_noarg, "", "");
113 fail("_opt_register returned?");
117 "Option --a|-aaa: invalid short option '-aaa'"));
121 exitval = setjmp(exited);
123 /* Documentation for non-optios. */
124 opt_register_noarg("--a foo", test_noarg, "", "");
125 fail("_opt_register returned?");
129 "Option --a foo: does not take arguments 'foo'"));
133 exitval = setjmp(exited);
135 /* Documentation for non-optios. */
136 opt_register_noarg("--a=foo", test_noarg, "", "");
137 fail("_opt_register returned?");
141 "Option --a=foo: does not take arguments 'foo'"));
143 return exit_status();