t/helper: merge test-parse-options into test-tool
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Sep 9, 2018 at 19:36 UTC
2f17c78ceb0a861264f7d0335d6aadee14c765ad
5 files changed
+41
-38
Makefile
+1
-1
@@ -721,6 +721,7 @@ TEST_BUILTINS_OBJS += test-match-trees.o
721
TEST_BUILTINS_OBJS += test-mergesort.o
722
TEST_BUILTINS_OBJS += test-mktemp.o
723
TEST_BUILTINS_OBJS += test-online-cpus.o
724
+TEST_BUILTINS_OBJS += test-parse-options.o
725
TEST_BUILTINS_OBJS += test-path-utils.o
726
TEST_BUILTINS_OBJS += test-pkt-line.o
727
TEST_BUILTINS_OBJS += test-prio-queue.o
@@ -745,7 +746,6 @@ TEST_BUILTINS_OBJS += test-write-cache.o
746
TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
747
TEST_PROGRAMS_NEED_X += test-fake-ssh
748
TEST_PROGRAMS_NEED_X += test-line-buffer
748
-TEST_PROGRAMS_NEED_X += test-parse-options
749
TEST_PROGRAMS_NEED_X += test-svn-fe
750
TEST_PROGRAMS_NEED_X += test-tool
751
t/helper/test-parse-options.c
+3
-2
@@ -1,3 +1,4 @@
1
+#include "test-tool.h"
2
#include "cache.h"
3
#include "parse-options.h"
4
#include "string-list.h"
@@ -94,11 +95,11 @@ static void show(struct string_list *expect, int *status, const char *fmt, ...)
95
strbuf_release(&buf);
96
}
97
97
-int cmd_main(int argc, const char **argv)
98
+int cmd__parse_options(int argc, const char **argv)
99
{
100
const char *prefix = "prefix/";
101
const char *usage[] = {
101
- "test-parse-options <options>",
102
+ "test-tool parse-options <options>",
103
"",
104
"A helper function for the parse-options API.",
105
NULL
t/helper/test-tool.c
+1
@@ -26,6 +26,7 @@ static struct test_cmd cmds[] = {
26
{ "mergesort", cmd__mergesort },
27
{ "mktemp", cmd__mktemp },
28
{ "online-cpus", cmd__online_cpus },
29
+ { "parse-options", cmd__parse_options },
30
{ "path-utils", cmd__path_utils },
31
{ "pkt-line", cmd__pkt_line },
32
{ "prio-queue", cmd__prio_queue },
t/helper/test-tool.h
+1
@@ -22,6 +22,7 @@ int cmd__match_trees(int argc, const char **argv);
22
int cmd__mergesort(int argc, const char **argv);
23
int cmd__mktemp(int argc, const char **argv);
24
int cmd__online_cpus(int argc, const char **argv);
25
+int cmd__parse_options(int argc, const char **argv);
26
int cmd__path_utils(int argc, const char **argv);
27
int cmd__pkt_line(int argc, const char **argv);
28
int cmd__prio_queue(int argc, const char **argv);
t/t0040-parse-options.sh
+35
-35
@@ -8,7 +8,7 @@ test_description='our own option parser'
8
. ./test-lib.sh
9
10
cat >expect <<\EOF
11
-usage: test-parse-options <options>
11
+usage: test-tool parse-options <options>
12
13
A helper function for the parse-options API.
14
@@ -52,7 +52,7 @@ Standard options
52
EOF
53
54
test_expect_success 'test help' '
55
- test_must_fail test-parse-options -h >output 2>output.err &&
55
+ test_must_fail test-tool parse-options -h >output 2>output.err &&
56
test_must_be_empty output.err &&
57
test_i18ncmp expect output
58
'
@@ -64,7 +64,7 @@ check () {
64
shift &&
65
expect="$1" &&
66
shift &&
67
- test-parse-options --expect="$what $expect" "$@"
67
+ test-tool parse-options --expect="$what $expect" "$@"
68
}
69
70
check_unknown_i18n() {
@@ -75,7 +75,7 @@ check_unknown_i18n() {
75
echo error: unknown switch \`${1#-}\' >expect ;;
76
esac &&
77
cat expect.err >>expect &&
78
- test_must_fail test-parse-options $* >output 2>output.err &&
78
+ test_must_fail test-tool parse-options $* >output 2>output.err &&
79
test_must_be_empty output &&
80
test_i18ncmp expect output.err
81
}
@@ -133,7 +133,7 @@ file: prefix/my.file
133
EOF
134
135
test_expect_success 'short options' '
136
- test-parse-options -s123 -b -i 1729 -m 16k -b -vv -n -F my.file \
136
+ test-tool parse-options -s123 -b -i 1729 -m 16k -b -vv -n -F my.file \
137
>output 2>output.err &&
138
test_cmp expect output &&
139
test_must_be_empty output.err
@@ -153,7 +153,7 @@ file: prefix/fi.le
153
EOF
154
155
test_expect_success 'long options' '
156
- test-parse-options --boolean --integer 1729 --magnitude 16k \
156
+ test-tool parse-options --boolean --integer 1729 --magnitude 16k \
157
--boolean --string2=321 --verbose --verbose --no-dry-run \
158
--abbrev=10 --file fi.le --obsolete \
159
>output 2>output.err &&
@@ -162,9 +162,9 @@ test_expect_success 'long options' '
162
'
163
164
test_expect_success 'missing required value' '
165
- test_expect_code 129 test-parse-options -s &&
166
- test_expect_code 129 test-parse-options --string &&
167
- test_expect_code 129 test-parse-options --file
165
+ test_expect_code 129 test-tool parse-options -s &&
166
+ test_expect_code 129 test-tool parse-options --string &&
167
+ test_expect_code 129 test-tool parse-options --file
168
'
169
170
cat >expect <<\EOF
@@ -184,7 +184,7 @@ arg 02: --boolean
184
EOF
185
186
test_expect_success 'intermingled arguments' '
187
- test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
187
+ test-tool parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
188
>output 2>output.err &&
189
test_must_be_empty output.err &&
190
test_cmp expect output
@@ -204,21 +204,21 @@ file: (not set)
204
EOF
205
206
test_expect_success 'unambiguously abbreviated option' '
207
- test-parse-options --int 2 --boolean --no-bo >output 2>output.err &&
207
+ test-tool parse-options --int 2 --boolean --no-bo >output 2>output.err &&
208
test_must_be_empty output.err &&
209
test_cmp expect output
210
'
211
212
test_expect_success 'unambiguously abbreviated option with "="' '
213
- test-parse-options --expect="integer: 2" --int=2
213
+ test-tool parse-options --expect="integer: 2" --int=2
214
'
215
216
test_expect_success 'ambiguously abbreviated option' '
217
- test_expect_code 129 test-parse-options --strin 123
217
+ test_expect_code 129 test-tool parse-options --strin 123
218
'
219
220
test_expect_success 'non ambiguous option (after two options it abbreviates)' '
221
- test-parse-options --expect="string: 123" --st 123
221
+ test-tool parse-options --expect="string: 123" --st 123
222
'
223
224
cat >typo.err <<\EOF
@@ -226,7 +226,7 @@ error: did you mean `--boolean` (with two dashes ?)
226
EOF
227
228
test_expect_success 'detect possible typos' '
229
- test_must_fail test-parse-options -boolean >output 2>output.err &&
229
+ test_must_fail test-tool parse-options -boolean >output 2>output.err &&
230
test_must_be_empty output &&
231
test_cmp typo.err output.err
232
'
@@ -236,13 +236,13 @@ error: did you mean `--ambiguous` (with two dashes ?)
236
EOF
237
238
test_expect_success 'detect possible typos' '
239
- test_must_fail test-parse-options -ambiguous >output 2>output.err &&
239
+ test_must_fail test-tool parse-options -ambiguous >output 2>output.err &&
240
test_must_be_empty output &&
241
test_cmp typo.err output.err
242
'
243
244
test_expect_success 'keep some options as arguments' '
245
- test-parse-options --expect="arg 00: --quux" --quux
245
+ test-tool parse-options --expect="arg 00: --quux" --quux
246
'
247
248
cat >expect <<\EOF
@@ -260,7 +260,7 @@ arg 00: foo
260
EOF
261
262
test_expect_success 'OPT_DATE() works' '
263
- test-parse-options -t "1970-01-01 00:00:01 +0000" \
263
+ test-tool parse-options -t "1970-01-01 00:00:01 +0000" \
264
foo -q >output 2>output.err &&
265
test_must_be_empty output.err &&
266
test_cmp expect output
@@ -281,13 +281,13 @@ file: (not set)
281
EOF
282
283
test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
284
- test-parse-options --length=four -b -4 >output 2>output.err &&
284
+ test-tool parse-options --length=four -b -4 >output 2>output.err &&
285
test_must_be_empty output.err &&
286
test_cmp expect output
287
'
288
289
test_expect_success 'OPT_CALLBACK() and callback errors work' '
290
- test_must_fail test-parse-options --no-length >output 2>output.err &&
290
+ test_must_fail test-tool parse-options --no-length >output 2>output.err &&
291
test_must_be_empty output &&
292
test_must_be_empty output.err
293
'
@@ -306,31 +306,31 @@ file: (not set)
306
EOF
307
308
test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
309
- test-parse-options --set23 -bbbbb --no-or4 >output 2>output.err &&
309
+ test-tool parse-options --set23 -bbbbb --no-or4 >output 2>output.err &&
310
test_must_be_empty output.err &&
311
test_cmp expect output
312
'
313
314
test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' '
315
- test-parse-options --set23 -bbbbb --neg-or4 >output 2>output.err &&
315
+ test-tool parse-options --set23 -bbbbb --neg-or4 >output 2>output.err &&
316
test_must_be_empty output.err &&
317
test_cmp expect output
318
'
319
320
test_expect_success 'OPT_BIT() works' '
321
- test-parse-options --expect="boolean: 6" -bb --or4
321
+ test-tool parse-options --expect="boolean: 6" -bb --or4
322
'
323
324
test_expect_success 'OPT_NEGBIT() works' '
325
- test-parse-options --expect="boolean: 6" -bb --no-neg-or4
325
+ test-tool parse-options --expect="boolean: 6" -bb --no-neg-or4
326
'
327
328
test_expect_success 'OPT_COUNTUP() with PARSE_OPT_NODASH works' '
329
- test-parse-options --expect="boolean: 6" + + + + + +
329
+ test-tool parse-options --expect="boolean: 6" + + + + + +
330
'
331
332
test_expect_success 'OPT_NUMBER_CALLBACK() works' '
333
- test-parse-options --expect="integer: 12345" -12345
333
+ test-tool parse-options --expect="integer: 12345" -12345
334
'
335
336
cat >expect <<\EOF
@@ -347,7 +347,7 @@ file: (not set)
347
EOF
348
349
test_expect_success 'negation of OPT_NONEG flags is not ambiguous' '
350
- test-parse-options --no-ambig >output 2>output.err &&
350
+ test-tool parse-options --no-ambig >output 2>output.err &&
351
test_must_be_empty output.err &&
352
test_cmp expect output
353
'
@@ -358,38 +358,38 @@ list: bar
358
list: baz
359
EOF
360
test_expect_success '--list keeps list of strings' '
361
- test-parse-options --list foo --list=bar --list=baz >output &&
361
+ test-tool parse-options --list foo --list=bar --list=baz >output &&
362
test_cmp expect output
363
'
364
365
test_expect_success '--no-list resets list' '
366
- test-parse-options --list=other --list=irrelevant --list=options \
366
+ test-tool parse-options --list=other --list=irrelevant --list=options \
367
--no-list --list=foo --list=bar --list=baz >output &&
368
test_cmp expect output
369
'
370
371
test_expect_success 'multiple quiet levels' '
372
- test-parse-options --expect="quiet: 3" -q -q -q
372
+ test-tool parse-options --expect="quiet: 3" -q -q -q
373
'
374
375
test_expect_success 'multiple verbose levels' '
376
- test-parse-options --expect="verbose: 3" -v -v -v
376
+ test-tool parse-options --expect="verbose: 3" -v -v -v
377
'
378
379
test_expect_success '--no-quiet sets --quiet to 0' '
380
- test-parse-options --expect="quiet: 0" --no-quiet
380
+ test-tool parse-options --expect="quiet: 0" --no-quiet
381
'
382
383
test_expect_success '--no-quiet resets multiple -q to 0' '
384
- test-parse-options --expect="quiet: 0" -q -q -q --no-quiet
384
+ test-tool parse-options --expect="quiet: 0" -q -q -q --no-quiet
385
'
386
387
test_expect_success '--no-verbose sets verbose to 0' '
388
- test-parse-options --expect="verbose: 0" --no-verbose
388
+ test-tool parse-options --expect="verbose: 0" --no-verbose
389
'
390
391
test_expect_success '--no-verbose resets multiple verbose to 0' '
392
- test-parse-options --expect="verbose: 0" -v -v -v --no-verbose
392
+ test-tool parse-options --expect="verbose: 0" -v -v -v --no-verbose
393
'
394
395
test_done