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
16 -i, --integer <n> get a integer
17 -j <n> get a integer, too
18 --set23 set integer to 23
19 -t <time> get timestamp of <time>
20 -L, --length <str> get length of <str>
25 --string2 <str> get another string
26 --st <st> get another string (pervert ordering)
27 -o <str> get another string
28 --default-string set string to default
34 --abbrev[=<n>] use <n> digits to display SHA-1s
35 -v, --verbose be verbose
41 test_expect_success 'test help' '
42 test_must_fail test-parse-options -h > output 2> output.err &&
44 test_cmp expect.err output.err
58 test_expect_success 'short options' '
59 test-parse-options -s123 -b -i 1729 -b -vv -n > output 2> output.err &&
60 test_cmp expect output &&
75 test_expect_success 'long options' '
76 test-parse-options --boolean --integer 1729 --boolean --string2=321 \
77 --verbose --verbose --no-dry-run --abbrev=10 \
78 > output 2> output.err &&
79 test ! -s output.err &&
80 test_cmp expect output
83 test_expect_success 'missing required value' '
84 test-parse-options -s;
86 test-parse-options --string;
104 test_expect_success 'intermingled arguments' '
105 test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
106 > output 2> output.err &&
107 test ! -s output.err &&
108 test_cmp expect output
122 test_expect_success 'unambiguously abbreviated option' '
123 test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
124 test ! -s output.err &&
125 test_cmp expect output
128 test_expect_success 'unambiguously abbreviated option with "="' '
129 test-parse-options --int=2 > output 2> output.err &&
130 test ! -s output.err &&
131 test_cmp expect output
134 test_expect_success 'ambiguously abbreviated option' '
135 test-parse-options --strin 123;
150 test_expect_success 'non ambiguous option (after two options it abbreviates)' '
151 test-parse-options --st 123 > output 2> output.err &&
152 test ! -s output.err &&
153 test_cmp expect output
156 cat > typo.err << EOF
157 error: did you mean \`--boolean\` (with two dashes ?)
160 test_expect_success 'detect possible typos' '
161 test_must_fail test-parse-options -boolean > output 2> output.err &&
163 test_cmp typo.err output.err
178 test_expect_success 'keep some options as arguments' '
179 test-parse-options --quux > output 2> output.err &&
180 test ! -s output.err &&
181 test_cmp expect output
196 test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' '
197 test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \
198 foo -q > output 2> output.err &&
199 test ! -s output.err &&
200 test_cmp expect output
215 test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
216 test-parse-options --length=four -b -4 > output 2> output.err &&
217 test ! -s output.err &&
218 test_cmp expect output
222 Callback: "not set", 1
225 test_expect_success 'OPT_CALLBACK() and callback errors work' '
226 test_must_fail test-parse-options --no-length > output 2> output.err &&
227 test_cmp expect output &&
228 test_cmp expect.err output.err
242 test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
243 test-parse-options --set23 -bbbbb --no-or4 > output 2> output.err &&
244 test ! -s output.err &&
245 test_cmp expect output