3 # Copyright (c) 2007 Johannes Schindelin
6 test_description='our own option parser'
10 cat > expect.err << EOF
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 &&
50 test_cmp expect.err output.err
65 test_expect_success 'short options' '
66 test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file \
67 > output 2> output.err &&
68 test_cmp expect output &&
84 test_expect_success 'long options' '
85 test-parse-options --boolean --integer 1729 --boolean --string2=321 \
86 --verbose --verbose --no-dry-run --abbrev=10 --file fi.le\
87 > output 2> output.err &&
88 test ! -s output.err &&
89 test_cmp expect output
92 test_expect_success 'missing required value' '
93 test-parse-options -s;
95 test-parse-options --string;
97 test-parse-options --file;
116 test_expect_success 'intermingled arguments' '
117 test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
118 > output 2> output.err &&
119 test ! -s output.err &&
120 test_cmp expect output
135 test_expect_success 'unambiguously abbreviated option' '
136 test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
137 test ! -s output.err &&
138 test_cmp expect output
141 test_expect_success 'unambiguously abbreviated option with "="' '
142 test-parse-options --int=2 > output 2> output.err &&
143 test ! -s output.err &&
144 test_cmp expect output
147 test_expect_success 'ambiguously abbreviated option' '
148 test-parse-options --strin 123;
164 test_expect_success 'non ambiguous option (after two options it abbreviates)' '
165 test-parse-options --st 123 > output 2> output.err &&
166 test ! -s output.err &&
167 test_cmp expect output
170 cat > typo.err << EOF
171 error: did you mean \`--boolean\` (with two dashes ?)
174 test_expect_success 'detect possible typos' '
175 test_must_fail test-parse-options -boolean > output 2> output.err &&
177 test_cmp typo.err output.err
193 test_expect_success 'keep some options as arguments' '
194 test-parse-options --quux > output 2> output.err &&
195 test ! -s output.err &&
196 test_cmp expect output
212 test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' '
213 test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \
214 foo -q > output 2> output.err &&
215 test ! -s output.err &&
216 test_cmp expect output
232 test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
233 test-parse-options --length=four -b -4 > output 2> output.err &&
234 test ! -s output.err &&
235 test_cmp expect output
239 Callback: "not set", 1
242 test_expect_success 'OPT_CALLBACK() and callback errors work' '
243 test_must_fail test-parse-options --no-length > output 2> output.err &&
244 test_cmp expect output &&
245 test_cmp expect.err output.err
260 test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
261 test-parse-options --set23 -bbbbb --no-or4 > output 2> output.err &&
262 test ! -s output.err &&
263 test_cmp expect output
266 test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' '
267 test-parse-options --set23 -bbbbb --neg-or4 > output 2> output.err &&
268 test ! -s output.err &&
269 test_cmp expect output
284 test_expect_success 'OPT_BIT() works' '
285 test-parse-options -bb --or4 > output 2> output.err &&
286 test ! -s output.err &&
287 test_cmp expect output
290 test_expect_success 'OPT_NEGBIT() works' '
291 test-parse-options -bb --no-neg-or4 > output 2> output.err &&
292 test ! -s output.err &&
293 test_cmp expect output
296 test_expect_success 'OPT_BOOLEAN() with PARSE_OPT_NODASH works' '
297 test-parse-options + + + + + + > output 2> output.err &&
298 test ! -s output.err &&
299 test_cmp expect output
314 test_expect_success 'OPT_NUMBER_CALLBACK() works' '
315 test-parse-options -12345 > output 2> output.err &&
316 test ! -s output.err &&
317 test_cmp expect output
332 test_expect_success 'negation of OPT_NONEG flags is not ambiguous' '
333 test-parse-options --no-ambig >output 2>output.err &&
334 test ! -s output.err &&
335 test_cmp expect output