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 -i, --integer <n> get a integer
15 -j <n> get a integer, too
20 --string2 <str> get another string
21 --st <st> get another string (pervert ordering)
22 -o <str> get another string
26 test_expect_success
'test help' '
27 ! test-parse-options -h > output 2> output.err &&
29 git diff expect.err output.err
38 test_expect_success
'short options' '
39 test-parse-options -s123 -b -i 1729 -b > output 2> output.err &&
40 git diff expect output &&
49 test_expect_success
'long options' '
50 test-parse-options --boolean --integer 1729 --boolean --string2=321 \
51 > output 2> output.err &&
52 test ! -s output.err &&
53 git diff expect output
65 test_expect_success
'intermingled arguments' '
66 test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
67 > output 2> output.err &&
68 test ! -s output.err &&
69 git diff expect output
78 test_expect_success
'unambiguously abbreviated option' '
79 test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
80 test ! -s output.err &&
81 git diff expect output
84 test_expect_success
'unambiguously abbreviated option with "="' '
85 test-parse-options --int=2 > output 2> output.err &&
86 test ! -s output.err &&
87 git diff expect output
90 test_expect_failure
'ambiguously abbreviated option' '
91 test-parse-options --strin 123;
101 test_expect_success
'non ambiguous option (after two options it abbreviates)' '
102 test-parse-options --st 123 > output 2> output.err &&
103 test ! -s output.err &&
104 git diff expect output
107 cat > expect.err
<< EOF
108 error: did you mean \`--boolean\` (with two dashes ?)
111 test_expect_success
'detect possible typos' '
112 ! test-parse-options -boolean > output 2> output.err &&
114 git diff expect.err output.err