Skip to content

Commit 2f17c78

Browse files
pcloudsgitster
authored andcommitted
t/helper: merge test-parse-options into test-tool
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8ea40cc commit 2f17c78

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ TEST_BUILTINS_OBJS += test-match-trees.o
721721
TEST_BUILTINS_OBJS += test-mergesort.o
722722
TEST_BUILTINS_OBJS += test-mktemp.o
723723
TEST_BUILTINS_OBJS += test-online-cpus.o
724+
TEST_BUILTINS_OBJS += test-parse-options.o
724725
TEST_BUILTINS_OBJS += test-path-utils.o
725726
TEST_BUILTINS_OBJS += test-pkt-line.o
726727
TEST_BUILTINS_OBJS += test-prio-queue.o
@@ -745,7 +746,6 @@ TEST_BUILTINS_OBJS += test-write-cache.o
745746
TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
746747
TEST_PROGRAMS_NEED_X += test-fake-ssh
747748
TEST_PROGRAMS_NEED_X += test-line-buffer
748-
TEST_PROGRAMS_NEED_X += test-parse-options
749749
TEST_PROGRAMS_NEED_X += test-svn-fe
750750
TEST_PROGRAMS_NEED_X += test-tool
751751

t/helper/test-parse-options.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "test-tool.h"
12
#include "cache.h"
23
#include "parse-options.h"
34
#include "string-list.h"
@@ -94,11 +95,11 @@ static void show(struct string_list *expect, int *status, const char *fmt, ...)
9495
strbuf_release(&buf);
9596
}
9697

97-
int cmd_main(int argc, const char **argv)
98+
int cmd__parse_options(int argc, const char **argv)
9899
{
99100
const char *prefix = "prefix/";
100101
const char *usage[] = {
101-
"test-parse-options <options>",
102+
"test-tool parse-options <options>",
102103
"",
103104
"A helper function for the parse-options API.",
104105
NULL

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static struct test_cmd cmds[] = {
2626
{ "mergesort", cmd__mergesort },
2727
{ "mktemp", cmd__mktemp },
2828
{ "online-cpus", cmd__online_cpus },
29+
{ "parse-options", cmd__parse_options },
2930
{ "path-utils", cmd__path_utils },
3031
{ "pkt-line", cmd__pkt_line },
3132
{ "prio-queue", cmd__prio_queue },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ int cmd__match_trees(int argc, const char **argv);
2222
int cmd__mergesort(int argc, const char **argv);
2323
int cmd__mktemp(int argc, const char **argv);
2424
int cmd__online_cpus(int argc, const char **argv);
25+
int cmd__parse_options(int argc, const char **argv);
2526
int cmd__path_utils(int argc, const char **argv);
2627
int cmd__pkt_line(int argc, const char **argv);
2728
int cmd__prio_queue(int argc, const char **argv);

t/t0040-parse-options.sh

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test_description='our own option parser'
88
. ./test-lib.sh
99

1010
cat >expect <<\EOF
11-
usage: test-parse-options <options>
11+
usage: test-tool parse-options <options>
1212
1313
A helper function for the parse-options API.
1414
@@ -52,7 +52,7 @@ Standard options
5252
EOF
5353

5454
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 &&
5656
test_must_be_empty output.err &&
5757
test_i18ncmp expect output
5858
'
@@ -64,7 +64,7 @@ check () {
6464
shift &&
6565
expect="$1" &&
6666
shift &&
67-
test-parse-options --expect="$what $expect" "$@"
67+
test-tool parse-options --expect="$what $expect" "$@"
6868
}
6969

7070
check_unknown_i18n() {
@@ -75,7 +75,7 @@ check_unknown_i18n() {
7575
echo error: unknown switch \`${1#-}\' >expect ;;
7676
esac &&
7777
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 &&
7979
test_must_be_empty output &&
8080
test_i18ncmp expect output.err
8181
}
@@ -133,7 +133,7 @@ file: prefix/my.file
133133
EOF
134134

135135
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 \
137137
>output 2>output.err &&
138138
test_cmp expect output &&
139139
test_must_be_empty output.err
@@ -153,7 +153,7 @@ file: prefix/fi.le
153153
EOF
154154

155155
test_expect_success 'long options' '
156-
test-parse-options --boolean --integer 1729 --magnitude 16k \
156+
test-tool parse-options --boolean --integer 1729 --magnitude 16k \
157157
--boolean --string2=321 --verbose --verbose --no-dry-run \
158158
--abbrev=10 --file fi.le --obsolete \
159159
>output 2>output.err &&
@@ -162,9 +162,9 @@ test_expect_success 'long options' '
162162
'
163163

164164
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
168168
'
169169

170170
cat >expect <<\EOF
@@ -184,7 +184,7 @@ arg 02: --boolean
184184
EOF
185185

186186
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 \
188188
>output 2>output.err &&
189189
test_must_be_empty output.err &&
190190
test_cmp expect output
@@ -204,29 +204,29 @@ file: (not set)
204204
EOF
205205

206206
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 &&
208208
test_must_be_empty output.err &&
209209
test_cmp expect output
210210
'
211211

212212
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
214214
'
215215

216216
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
218218
'
219219

220220
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
222222
'
223223

224224
cat >typo.err <<\EOF
225225
error: did you mean `--boolean` (with two dashes ?)
226226
EOF
227227

228228
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 &&
230230
test_must_be_empty output &&
231231
test_cmp typo.err output.err
232232
'
@@ -236,13 +236,13 @@ error: did you mean `--ambiguous` (with two dashes ?)
236236
EOF
237237

238238
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 &&
240240
test_must_be_empty output &&
241241
test_cmp typo.err output.err
242242
'
243243

244244
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
246246
'
247247

248248
cat >expect <<\EOF
@@ -260,7 +260,7 @@ arg 00: foo
260260
EOF
261261

262262
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" \
264264
foo -q >output 2>output.err &&
265265
test_must_be_empty output.err &&
266266
test_cmp expect output
@@ -281,13 +281,13 @@ file: (not set)
281281
EOF
282282

283283
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 &&
285285
test_must_be_empty output.err &&
286286
test_cmp expect output
287287
'
288288

289289
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 &&
291291
test_must_be_empty output &&
292292
test_must_be_empty output.err
293293
'
@@ -306,31 +306,31 @@ file: (not set)
306306
EOF
307307

308308
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 &&
310310
test_must_be_empty output.err &&
311311
test_cmp expect output
312312
'
313313

314314
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 &&
316316
test_must_be_empty output.err &&
317317
test_cmp expect output
318318
'
319319

320320
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
322322
'
323323

324324
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
326326
'
327327

328328
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" + + + + + +
330330
'
331331

332332
test_expect_success 'OPT_NUMBER_CALLBACK() works' '
333-
test-parse-options --expect="integer: 12345" -12345
333+
test-tool parse-options --expect="integer: 12345" -12345
334334
'
335335

336336
cat >expect <<\EOF
@@ -347,7 +347,7 @@ file: (not set)
347347
EOF
348348

349349
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 &&
351351
test_must_be_empty output.err &&
352352
test_cmp expect output
353353
'
@@ -358,38 +358,38 @@ list: bar
358358
list: baz
359359
EOF
360360
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 &&
362362
test_cmp expect output
363363
'
364364

365365
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 \
367367
--no-list --list=foo --list=bar --list=baz >output &&
368368
test_cmp expect output
369369
'
370370

371371
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
373373
'
374374

375375
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
377377
'
378378

379379
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
381381
'
382382

383383
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
385385
'
386386

387387
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
389389
'
390390

391391
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
393393
'
394394

395395
test_done

0 commit comments

Comments
 (0)