make sure parsed wildcard refspec ends with slash
[alt-git.git] / t / t0040-parse-options.sh
blob03dbe00102626e05c37e45d8a3b1364b99644942
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes Schindelin
6 test_description='our own option parser'
8 . ./test-lib.sh
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>
22 String options
23 -s, --string <string>
24 get a string
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
30 Magic arguments
31 --quux means --quux
33 Standard options
34 --abbrev[=<n>] use <n> digits to display SHA-1s
35 -v, --verbose be verbose
36 -n, --dry-run dry run
37 -q, --quiet be quiet
39 EOF
41 test_expect_success 'test help' '
42 test_must_fail test-parse-options -h > output 2> output.err &&
43 test ! -s output &&
44 test_cmp expect.err output.err
47 cat > expect << EOF
48 boolean: 2
49 integer: 1729
50 string: 123
51 abbrev: 7
52 verbose: 2
53 quiet: no
54 dry run: yes
55 EOF
57 test_expect_success 'short options' '
58 test-parse-options -s123 -b -i 1729 -b -vv -n > output 2> output.err &&
59 test_cmp expect output &&
60 test ! -s output.err
63 cat > expect << EOF
64 boolean: 2
65 integer: 1729
66 string: 321
67 abbrev: 10
68 verbose: 2
69 quiet: no
70 dry run: no
71 EOF
73 test_expect_success 'long options' '
74 test-parse-options --boolean --integer 1729 --boolean --string2=321 \
75 --verbose --verbose --no-dry-run --abbrev=10 \
76 > output 2> output.err &&
77 test ! -s output.err &&
78 test_cmp expect output
81 test_expect_success 'missing required value' '
82 test-parse-options -s;
83 test $? = 129 &&
84 test-parse-options --string;
85 test $? = 129
88 cat > expect << EOF
89 boolean: 1
90 integer: 13
91 string: 123
92 abbrev: 7
93 verbose: 0
94 quiet: no
95 dry run: no
96 arg 00: a1
97 arg 01: b1
98 arg 02: --boolean
99 EOF
101 test_expect_success 'intermingled arguments' '
102 test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
103 > output 2> output.err &&
104 test ! -s output.err &&
105 test_cmp expect output
108 cat > expect << EOF
109 boolean: 0
110 integer: 2
111 string: (not set)
112 abbrev: 7
113 verbose: 0
114 quiet: no
115 dry run: no
118 test_expect_success 'unambiguously abbreviated option' '
119 test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
120 test ! -s output.err &&
121 test_cmp expect output
124 test_expect_success 'unambiguously abbreviated option with "="' '
125 test-parse-options --int=2 > output 2> output.err &&
126 test ! -s output.err &&
127 test_cmp expect output
130 test_expect_success 'ambiguously abbreviated option' '
131 test-parse-options --strin 123;
132 test $? = 129
135 cat > expect << EOF
136 boolean: 0
137 integer: 0
138 string: 123
139 abbrev: 7
140 verbose: 0
141 quiet: no
142 dry run: no
145 test_expect_success 'non ambiguous option (after two options it abbreviates)' '
146 test-parse-options --st 123 > output 2> output.err &&
147 test ! -s output.err &&
148 test_cmp expect output
151 cat > typo.err << EOF
152 error: did you mean \`--boolean\` (with two dashes ?)
155 test_expect_success 'detect possible typos' '
156 test_must_fail test-parse-options -boolean > output 2> output.err &&
157 test ! -s output &&
158 test_cmp typo.err output.err
161 cat > expect <<EOF
162 boolean: 0
163 integer: 0
164 string: (not set)
165 abbrev: 7
166 verbose: 0
167 quiet: no
168 dry run: no
169 arg 00: --quux
172 test_expect_success 'keep some options as arguments' '
173 test-parse-options --quux > output 2> output.err &&
174 test ! -s output.err &&
175 test_cmp expect output
178 cat > expect <<EOF
179 boolean: 0
180 integer: 1
181 string: default
182 abbrev: 7
183 verbose: 0
184 quiet: yes
185 dry run: no
186 arg 00: foo
189 test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' '
190 test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \
191 foo -q > output 2> output.err &&
192 test ! -s output.err &&
193 test_cmp expect output
196 cat > expect <<EOF
197 Callback: "four", 0
198 boolean: 5
199 integer: 4
200 string: (not set)
201 abbrev: 7
202 verbose: 0
203 quiet: no
204 dry run: no
207 test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
208 test-parse-options --length=four -b -4 > output 2> output.err &&
209 test ! -s output.err &&
210 test_cmp expect output
213 cat > expect <<EOF
214 Callback: "not set", 1
217 test_expect_success 'OPT_CALLBACK() and callback errors work' '
218 test_must_fail test-parse-options --no-length > output 2> output.err &&
219 test_cmp expect output &&
220 test_cmp expect.err output.err
223 cat > expect <<EOF
224 boolean: 1
225 integer: 23
226 string: (not set)
227 abbrev: 7
228 verbose: 0
229 quiet: no
230 dry run: no
233 test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
234 test-parse-options --set23 -bbbbb --no-or4 > output 2> output.err &&
235 test ! -s output.err &&
236 test_cmp expect output
239 # --or4
240 # --no-or4
242 test_done