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
29 test_expect_success
'test help' '
30 ! test-parse-options -h > output 2> output.err &&
32 git diff expect.err output.err
41 test_expect_success
'short options' '
42 test-parse-options -s123 -b -i 1729 -b > output 2> output.err &&
43 git diff expect output &&
52 test_expect_success
'long options' '
53 test-parse-options --boolean --integer 1729 --boolean --string2=321 \
54 > output 2> output.err &&
55 test ! -s output.err &&
56 git diff expect output
68 test_expect_success
'intermingled arguments' '
69 test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
70 > output 2> output.err &&
71 test ! -s output.err &&
72 git diff expect output
81 test_expect_success
'unambiguously abbreviated option' '
82 test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
83 test ! -s output.err &&
84 git diff expect output
87 test_expect_success
'unambiguously abbreviated option with "="' '
88 test-parse-options --int=2 > output 2> output.err &&
89 test ! -s output.err &&
90 git diff expect output
93 test_expect_success
'ambiguously abbreviated option' '
94 test-parse-options --strin 123;
104 test_expect_success
'non ambiguous option (after two options it abbreviates)' '
105 test-parse-options --st 123 > output 2> output.err &&
106 test ! -s output.err &&
107 git diff expect output
110 cat > expect.err
<< EOF
111 error: did you mean \`--boolean\` (with two dashes ?)
114 test_expect_success
'detect possible typos' '
115 ! test-parse-options -boolean > output 2> output.err &&
117 git diff expect.err output.err
127 test_expect_success
'keep some options as arguments' '
128 test-parse-options --quux > output 2> output.err &&
129 test ! -s output.err &&
130 git diff expect output