1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // configs/usage.cfa |
---|
8 | // Testing printing of usage for arguments |
---|
9 | // |
---|
10 | // Author : Thierry Delisle |
---|
11 | // Created On : Wed Oct 12 15:28:01 2022 |
---|
12 | // Last Modified By : |
---|
13 | // Last Modified On : |
---|
14 | // Update Count : |
---|
15 | // |
---|
16 | |
---|
17 | #include <parseargs.hfa> |
---|
18 | #include <fstream.hfa> |
---|
19 | |
---|
20 | #include "../meta/fork+exec.hfa" |
---|
21 | |
---|
22 | int main() { |
---|
23 | char * fake_argv[] = { "./usage" }; |
---|
24 | |
---|
25 | sout | "No args, no errors"; |
---|
26 | if(pid_t child = strict_fork(); child == 0) { |
---|
27 | cfa_option opts[0]; |
---|
28 | print_args_usage(1, fake_argv, opts, 0, "Test usage", false); |
---|
29 | } |
---|
30 | else { |
---|
31 | int status = do_wait(child); |
---|
32 | print_status(status); |
---|
33 | } |
---|
34 | |
---|
35 | sout | "No args, with errors"; |
---|
36 | if(pid_t child = strict_fork(); child == 0) { |
---|
37 | cfa_option opts[0]; |
---|
38 | print_args_usage(1, fake_argv, opts, 0, "Test usage", true); |
---|
39 | } |
---|
40 | else { |
---|
41 | int status = do_wait(child); |
---|
42 | print_status(status); |
---|
43 | } |
---|
44 | |
---|
45 | sout | "Args with short names only:"; |
---|
46 | if(pid_t child = strict_fork(); child == 0) { |
---|
47 | int a, b, c; |
---|
48 | cfa_option opts[] = { |
---|
49 | {'a', "", "First arg", a }, |
---|
50 | {'b', "", "Second arg", b }, |
---|
51 | {'c', "", "Third arg", c }, |
---|
52 | }; |
---|
53 | print_args_usage(1, fake_argv, opts, 3, "Test usage", false); |
---|
54 | } |
---|
55 | else { |
---|
56 | int status = do_wait(child); |
---|
57 | print_status(status); |
---|
58 | } |
---|
59 | |
---|
60 | sout | "Args with long names only:"; |
---|
61 | if(pid_t child = strict_fork(); child == 0) { |
---|
62 | int a, b, c; |
---|
63 | cfa_option opts[] = { |
---|
64 | {'\0', "AA", "First arg", a }, |
---|
65 | {'\0', "BB", "Second arg", b }, |
---|
66 | {'\0', "CC", "Third arg", c }, |
---|
67 | }; |
---|
68 | print_args_usage(1, fake_argv, opts, 3, "Test usage", false); |
---|
69 | } |
---|
70 | else { |
---|
71 | int status = do_wait(child); |
---|
72 | print_status(status); |
---|
73 | } |
---|
74 | |
---|
75 | sout | "Mix of short and long args:"; |
---|
76 | if(pid_t child = strict_fork(); child == 0) { |
---|
77 | int a, b, c; |
---|
78 | cfa_option opts[] = { |
---|
79 | {'a', "", "First arg", a }, |
---|
80 | {'b', "BBBB", "Second arg", b }, |
---|
81 | {'\0', "CC", "Third arg", c }, |
---|
82 | }; |
---|
83 | print_args_usage(1, fake_argv, opts, 3, "Test usage", false); |
---|
84 | } |
---|
85 | else { |
---|
86 | int status = do_wait(child); |
---|
87 | print_status(status); |
---|
88 | } |
---|
89 | |
---|
90 | sout | "Mix of short and long and some missing description:"; |
---|
91 | if(pid_t child = strict_fork(); child == 0) { |
---|
92 | int a, b, c; |
---|
93 | cfa_option opts[] = { |
---|
94 | {'a', "", "First arg", a }, |
---|
95 | {'b', "BBBB", "", b }, |
---|
96 | {'\0', "CC", "Third arg", c }, |
---|
97 | }; |
---|
98 | print_args_usage(1, fake_argv, opts, 3, "Test usage", false); |
---|
99 | } |
---|
100 | else { |
---|
101 | int status = do_wait(child); |
---|
102 | print_status(status); |
---|
103 | } |
---|
104 | |
---|
105 | sout | "Mix of short and long and some long description:"; |
---|
106 | if(pid_t child = strict_fork(); child == 0) { |
---|
107 | int a, b, c; |
---|
108 | cfa_option opts[] = { |
---|
109 | {'a', "", "First arg\nThe description has multiple lines,\n...for some reason", a }, |
---|
110 | {'b', "BBBB", "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", b }, |
---|
111 | {'\0', "CC", "Third arg", c }, |
---|
112 | }; |
---|
113 | print_args_usage(1, fake_argv, opts, 3, "Test usage", false); |
---|
114 | } |
---|
115 | else { |
---|
116 | int status = do_wait(child); |
---|
117 | print_status(status); |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | // no used |
---|
122 | static int true_main(const char * path, char * env[]) { return 0; } |
---|