3 # Copyright (c) 2007 Johannes Schindelin
6 test_description='our own option parser'
11 usage: test-parse-options <options>
13 -b, --boolean get a boolean
14 -4, --or4 bitwise-or boolean with ...0100
15 --neg-or4 same as --no-or4
17 -i, --integer <n> get a integer
18 -j <n> get a integer, too
19 --set23 set integer to 23
20 -t <time> get timestamp of <time>
21 -L, --length <str> get length of <str>
22 -F, --file <FILE> set file to <FILE>
27 --string2 <str> get another string
28 --st <st> get another string (pervert ordering)
29 -o <str> get another string
30 --default-string set string to default
34 -NUM set integer to NUM
36 --ambiguous positive ambiguity
37 --no-ambiguous negative ambiguity
40 --abbrev[=<n>] use <n> digits to display SHA-1s
41 -v, --verbose be verbose
47 test_expect_success 'test help' '
48 test_must_fail test-parse-options -h > output 2> output.err &&
49 test ! -s output.err &&
50 test_cmp expect output
67 test_expect_success 'short options' '
68 test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file \
69 > output 2> output.err &&
70 test_cmp expect output &&
86 test_expect_success 'long options' '
87 test-parse-options --boolean --integer 1729 --boolean --string2=321 \
88 --verbose --verbose --no-dry-run --abbrev=10 --file fi.le\
89 > output 2> output.err &&
90 test ! -s output.err &&
91 test_cmp expect output
94 test_expect_success 'missing required value' '
95 test-parse-options -s;
97 test-parse-options --string;
99 test-parse-options --file;
118 test_expect_success 'intermingled arguments' '
119 test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
120 > output 2> output.err &&
121 test ! -s output.err &&
122 test_cmp expect output
137 test_expect_success 'unambiguously abbreviated option' '
138 test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
139 test ! -s output.err &&
140 test_cmp expect output
143 test_expect_success 'unambiguously abbreviated option with "="' '
144 test-parse-options --int=2 > output 2> output.err &&
145 test ! -s output.err &&
146 test_cmp expect output
149 test_expect_success 'ambiguously abbreviated option' '
150 test-parse-options --strin 123;
166 test_expect_success 'non ambiguous option (after two options it abbreviates)' '
167 test-parse-options --st 123 > output 2> output.err &&
168 test ! -s output.err &&
169 test_cmp expect output
172 cat > typo.err << EOF
173 error: did you mean \`--boolean\` (with two dashes ?)
176 test_expect_success 'detect possible typos' '
177 test_must_fail test-parse-options -boolean > output 2> output.err &&
179 test_cmp typo.err output.err
195 test_expect_success 'keep some options as arguments' '
196 test-parse-options --quux > output 2> output.err &&
197 test ! -s output.err &&
198 test_cmp expect output
214 test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' '
215 test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \
216 foo -q > output 2> output.err &&
217 test ! -s output.err &&
218 test_cmp expect output
234 test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
235 test-parse-options --length=four -b -4 > output 2> output.err &&
236 test ! -s output.err &&
237 test_cmp expect output
241 Callback: "not set", 1
244 test_expect_success 'OPT_CALLBACK() and callback errors work' '
245 test_must_fail test-parse-options --no-length > output 2> output.err &&
246 test_cmp expect output &&
247 test_cmp expect.err output.err
262 test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
263 test-parse-options --set23 -bbbbb --no-or4 > output 2> output.err &&
264 test ! -s output.err &&
265 test_cmp expect output
268 test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' '
269 test-parse-options --set23 -bbbbb --neg-or4 > output 2> output.err &&
270 test ! -s output.err &&
271 test_cmp expect output
286 test_expect_success 'OPT_BIT() works' '
287 test-parse-options -bb --or4 > output 2> output.err &&
288 test ! -s output.err &&
289 test_cmp expect output
292 test_expect_success 'OPT_NEGBIT() works' '
293 test-parse-options -bb --no-neg-or4 > output 2> output.err &&
294 test ! -s output.err &&
295 test_cmp expect output
298 test_expect_success 'OPT_BOOLEAN() with PARSE_OPT_NODASH works' '
299 test-parse-options + + + + + + > output 2> output.err &&
300 test ! -s output.err &&
301 test_cmp expect output
316 test_expect_success 'OPT_NUMBER_CALLBACK() works' '
317 test-parse-options -12345 > output 2> output.err &&
318 test ! -s output.err &&
319 test_cmp expect output
334 test_expect_success 'negation of OPT_NONEG flags is not ambiguous' '
335 test-parse-options --no-ambig >output 2>output.err &&
336 test ! -s output.err &&
337 test_cmp expect output