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
31 --list <str> add str to list
35 -NUM set integer to NUM
37 --ambiguous positive ambiguity
38 --no-ambiguous negative ambiguity
41 --abbrev[=<n>] use <n> digits to display SHA-1s
42 -v, --verbose be verbose
48 test_expect_success 'test help' '
49 test_must_fail test-parse-options -h > output 2> output.err &&
50 test ! -s output.err &&
51 test_cmp expect output
68 test_expect_success 'short options' '
69 test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file \
70 > output 2> output.err &&
71 test_cmp expect output &&
87 test_expect_success 'long options' '
88 test-parse-options --boolean --integer 1729 --boolean --string2=321 \
89 --verbose --verbose --no-dry-run --abbrev=10 --file fi.le\
90 --obsolete > output 2> output.err &&
91 test ! -s output.err &&
92 test_cmp expect output
95 test_expect_success 'missing required value' '
96 test-parse-options -s;
98 test-parse-options --string;
100 test-parse-options --file;
119 test_expect_success 'intermingled arguments' '
120 test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
121 > output 2> output.err &&
122 test ! -s output.err &&
123 test_cmp expect output
138 test_expect_success 'unambiguously abbreviated option' '
139 test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
140 test ! -s output.err &&
141 test_cmp expect output
144 test_expect_success 'unambiguously abbreviated option with "="' '
145 test-parse-options --int=2 > output 2> output.err &&
146 test ! -s output.err &&
147 test_cmp expect output
150 test_expect_success 'ambiguously abbreviated option' '
151 test-parse-options --strin 123;
167 test_expect_success 'non ambiguous option (after two options it abbreviates)' '
168 test-parse-options --st 123 > output 2> output.err &&
169 test ! -s output.err &&
170 test_cmp expect output
173 cat > typo.err << EOF
174 error: did you mean \`--boolean\` (with two dashes ?)
177 test_expect_success 'detect possible typos' '
178 test_must_fail test-parse-options -boolean > output 2> output.err &&
180 test_cmp typo.err output.err
196 test_expect_success 'keep some options as arguments' '
197 test-parse-options --quux > output 2> output.err &&
198 test ! -s output.err &&
199 test_cmp expect output
215 test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' '
216 test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \
217 foo -q > output 2> output.err &&
218 test ! -s output.err &&
219 test_cmp expect output
235 test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
236 test-parse-options --length=four -b -4 > output 2> output.err &&
237 test ! -s output.err &&
238 test_cmp expect output
242 Callback: "not set", 1
245 test_expect_success 'OPT_CALLBACK() and callback errors work' '
246 test_must_fail test-parse-options --no-length > output 2> output.err &&
247 test_cmp expect output &&
248 test_cmp expect.err output.err
263 test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
264 test-parse-options --set23 -bbbbb --no-or4 > output 2> output.err &&
265 test ! -s output.err &&
266 test_cmp expect output
269 test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' '
270 test-parse-options --set23 -bbbbb --neg-or4 > output 2> output.err &&
271 test ! -s output.err &&
272 test_cmp expect output
287 test_expect_success 'OPT_BIT() works' '
288 test-parse-options -bb --or4 > output 2> output.err &&
289 test ! -s output.err &&
290 test_cmp expect output
293 test_expect_success 'OPT_NEGBIT() works' '
294 test-parse-options -bb --no-neg-or4 > output 2> output.err &&
295 test ! -s output.err &&
296 test_cmp expect output
299 test_expect_success 'OPT_BOOLEAN() with PARSE_OPT_NODASH works' '
300 test-parse-options + + + + + + > output 2> output.err &&
301 test ! -s output.err &&
302 test_cmp expect output
317 test_expect_success 'OPT_NUMBER_CALLBACK() works' '
318 test-parse-options -12345 > output 2> output.err &&
319 test ! -s output.err &&
320 test_cmp expect output
335 test_expect_success 'negation of OPT_NONEG flags is not ambiguous' '
336 test-parse-options --no-ambig >output 2>output.err &&
337 test ! -s output.err &&
338 test_cmp expect output
346 test_expect_success '--list keeps list of strings' '
347 test-parse-options --list foo --list=bar --list=baz >output &&
348 test_cmp expect output
351 test_expect_success '--no-list resets list' '
352 test-parse-options --list=other --list=irrelevant --list=options \
353 --no-list --list=foo --list=bar --list=baz >output &&
354 test_cmp expect output