blob: f8178ee4e392fa5cfdbef07b0f42710ea68bc67b [file] [log] [blame]
Johannes Schindelinbeb47432007-10-13 17:34:45 +01001#!/bin/sh
2#
3# Copyright (c) 2007 Johannes Schindelin
4#
5
6test_description='our own option parser'
7
8. ./test-lib.sh
9
Pranit Bauva8425b7e2016-04-12 23:02:17 +000010cat >expect <<\EOF
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +020011usage: test-tool parse-options <options>
Johannes Schindelinbeb47432007-10-13 17:34:45 +010012
Brandon Caseyc97ee172017-09-24 21:08:03 -070013 A helper function for the parse-options API.
14
René Scharfeb9e63dd2012-02-25 20:11:16 +010015 --yes get a boolean
16 -D, --no-doubt begins with 'no-'
17 -B, --no-fear be brave
18 -b, --boolean increment by one
Stephan Beyer010a2da2008-06-22 17:04:26 +020019 -4, --or4 bitwise-or boolean with ...0100
René Scharfe2f4b97f2009-05-07 21:44:17 +020020 --neg-or4 same as --no-or4
Stephan Beyer010a2da2008-06-22 17:04:26 +020021
Johannes Schindelinbeb47432007-10-13 17:34:45 +010022 -i, --integer <n> get a integer
23 -j <n> get a integer, too
Charles Bailey2a514ed2015-06-21 19:25:44 +010024 -m, --magnitude <n> get a magnitude
Stephan Beyer010a2da2008-06-22 17:04:26 +020025 --set23 set integer to 23
Paolo Bonzini62e7a6f2020-02-20 15:15:15 +010026 --mode1 set integer to 1 (cmdmode option)
27 --mode2 set integer to 2 (cmdmode option)
Stephan Beyer010a2da2008-06-22 17:04:26 +020028 -L, --length <str> get length of <str>
Michael J Gruber41dbcd42011-02-15 14:09:13 +010029 -F, --file <file> set file to <file>
Johannes Schindelinbeb47432007-10-13 17:34:45 +010030
Stephan Beyer010a2da2008-06-22 17:04:26 +020031String options
Johannes Schindelinbeb47432007-10-13 17:34:45 +010032 -s, --string <string>
33 get a string
34 --string2 <str> get another string
Johannes Schindelin243e0612007-11-05 13:15:21 +000035 --st <st> get another string (pervert ordering)
Pierre Habouzit3a9f0f42008-01-26 12:26:57 +010036 -o <str> get another string
Jeff Kingc8ba1632011-06-09 11:55:23 -040037 --list <str> add str to list
Johannes Schindelinbeb47432007-10-13 17:34:45 +010038
Stephan Beyer010a2da2008-06-22 17:04:26 +020039Magic arguments
Pierre Habouzit580d5bf2008-03-02 11:35:56 +010040 --quux means --quux
René Scharfee0319ff2009-05-07 21:45:08 +020041 -NUM set integer to NUM
René Scharfe51a99492009-05-07 21:45:42 +020042 + same as -b
Andreas Schwab6bbfd1f2009-09-25 20:44:44 +020043 --ambiguous positive ambiguity
44 --no-ambiguous negative ambiguity
Pierre Habouzit580d5bf2008-03-02 11:35:56 +010045
Stephan Beyer010a2da2008-06-22 17:04:26 +020046Standard options
47 --abbrev[=<n>] use <n> digits to display SHA-1s
48 -v, --verbose be verbose
49 -n, --dry-run dry run
50 -q, --quiet be quiet
Junio C Hamanoab6b28b2016-05-05 14:36:55 -070051 --expect <string> expected output in the variable dump
Stephan Beyer010a2da2008-06-22 17:04:26 +020052
Nguyễn Thái Ngọc Duy5c387422019-04-29 17:05:25 +070053Alias
54 -A, --alias-source <string>
55 get a string
56 -Z, --alias-target <string>
Junio C Hamano7c280582020-03-16 13:22:54 -070057 alias of --alias-source
Nguyễn Thái Ngọc Duy5c387422019-04-29 17:05:25 +070058
Johannes Schindelinbeb47432007-10-13 17:34:45 +010059EOF
60
61test_expect_success 'test help' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +020062 test_must_fail test-tool parse-options -h >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -070063 test_must_be_empty output.err &&
Jiang Xin9a001382012-08-27 13:36:55 +080064 test_i18ncmp expect output
Johannes Schindelinbeb47432007-10-13 17:34:45 +010065'
66
Giuseppe Scrivano9c7304e2010-05-17 17:34:41 +020067mv expect expect.err
68
Junio C Hamano8ca65ae2016-05-06 11:17:05 -070069check () {
René Scharfeb9e63dd2012-02-25 20:11:16 +010070 what="$1" &&
71 shift &&
72 expect="$1" &&
73 shift &&
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +020074 test-tool parse-options --expect="$what $expect" "$@"
René Scharfeb9e63dd2012-02-25 20:11:16 +010075}
76
Jiang Xin9a001382012-08-27 13:36:55 +080077check_unknown_i18n() {
78 case "$1" in
79 --*)
80 echo error: unknown option \`${1#--}\' >expect ;;
81 -*)
82 echo error: unknown switch \`${1#-}\' >expect ;;
83 esac &&
84 cat expect.err >>expect &&
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +020085 test_must_fail test-tool parse-options $* >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -070086 test_must_be_empty output &&
Jiang Xin9a001382012-08-27 13:36:55 +080087 test_i18ncmp expect output.err
88}
89
René Scharfeb9e63dd2012-02-25 20:11:16 +010090test_expect_success 'OPT_BOOL() #1' 'check boolean: 1 --yes'
91test_expect_success 'OPT_BOOL() #2' 'check boolean: 1 --no-doubt'
92test_expect_success 'OPT_BOOL() #3' 'check boolean: 1 -D'
93test_expect_success 'OPT_BOOL() #4' 'check boolean: 1 --no-fear'
94test_expect_success 'OPT_BOOL() #5' 'check boolean: 1 -B'
95
96test_expect_success 'OPT_BOOL() is idempotent #1' 'check boolean: 1 --yes --yes'
97test_expect_success 'OPT_BOOL() is idempotent #2' 'check boolean: 1 -DB'
98
99test_expect_success 'OPT_BOOL() negation #1' 'check boolean: 0 -D --no-yes'
100test_expect_success 'OPT_BOOL() negation #2' 'check boolean: 0 -D --no-no-doubt'
101
Brandon Casey1a9bf1e2017-09-24 21:08:04 -0700102test_expect_success 'OPT_BOOL() no negation #1' 'check_unknown_i18n --fear'
103test_expect_success 'OPT_BOOL() no negation #2' 'check_unknown_i18n --no-no-fear'
René Scharfeb9e63dd2012-02-25 20:11:16 +0100104
René Scharfe0f1930c52012-02-25 20:14:54 +0100105test_expect_success 'OPT_BOOL() positivation' 'check boolean: 0 -D --doubt'
René Scharfeb9e63dd2012-02-25 20:11:16 +0100106
Charles Bailey81a48cc2015-06-21 19:25:43 +0100107test_expect_success 'OPT_INT() negative' 'check integer: -2345 -i -2345'
108
Charles Bailey2a514ed2015-06-21 19:25:44 +0100109test_expect_success 'OPT_MAGNITUDE() simple' '
110 check magnitude: 2345678 -m 2345678
111'
112
113test_expect_success 'OPT_MAGNITUDE() kilo' '
114 check magnitude: 239616 -m 234k
115'
116
117test_expect_success 'OPT_MAGNITUDE() mega' '
118 check magnitude: 104857600 -m 100m
119'
120
121test_expect_success 'OPT_MAGNITUDE() giga' '
122 check magnitude: 1073741824 -m 1g
123'
124
125test_expect_success 'OPT_MAGNITUDE() 3giga' '
126 check magnitude: 3221225472 -m 3g
127'
128
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000129cat >expect <<\EOF
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100130boolean: 2
131integer: 1729
Charles Bailey2a514ed2015-06-21 19:25:44 +0100132magnitude: 16384
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700133timestamp: 0
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100134string: 123
Stephan Beyer010a2da2008-06-22 17:04:26 +0200135abbrev: 7
136verbose: 2
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000137quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200138dry run: yes
Stephen Boyddf217ed2009-05-23 11:53:13 -0700139file: prefix/my.file
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100140EOF
141
142test_expect_success 'short options' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200143 test-tool parse-options -s123 -b -i 1729 -m 16k -b -vv -n -F my.file \
Charles Bailey2a514ed2015-06-21 19:25:44 +0100144 >output 2>output.err &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700145 test_cmp expect output &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700146 test_must_be_empty output.err
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100147'
Stephan Beyer010a2da2008-06-22 17:04:26 +0200148
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000149cat >expect <<\EOF
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100150boolean: 2
151integer: 1729
Charles Bailey2a514ed2015-06-21 19:25:44 +0100152magnitude: 16384
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700153timestamp: 0
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100154string: 321
Stephan Beyer010a2da2008-06-22 17:04:26 +0200155abbrev: 10
156verbose: 2
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000157quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200158dry run: no
Stephen Boyddf217ed2009-05-23 11:53:13 -0700159file: prefix/fi.le
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100160EOF
161
162test_expect_success 'long options' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200163 test-tool parse-options --boolean --integer 1729 --magnitude 16k \
Charles Bailey2a514ed2015-06-21 19:25:44 +0100164 --boolean --string2=321 --verbose --verbose --no-dry-run \
165 --abbrev=10 --file fi.le --obsolete \
166 >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700167 test_must_be_empty output.err &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700168 test_cmp expect output
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100169'
170
Olivier Marind5d745f2008-07-21 20:30:36 +0200171test_expect_success 'missing required value' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200172 test_expect_code 129 test-tool parse-options -s &&
173 test_expect_code 129 test-tool parse-options --string &&
174 test_expect_code 129 test-tool parse-options --file
Olivier Marind5d745f2008-07-21 20:30:36 +0200175'
176
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000177cat >expect <<\EOF
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100178boolean: 1
179integer: 13
Charles Bailey2a514ed2015-06-21 19:25:44 +0100180magnitude: 0
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700181timestamp: 0
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100182string: 123
Stephan Beyer010a2da2008-06-22 17:04:26 +0200183abbrev: 7
Pranit Bauvae0070e82016-05-05 15:20:00 +0530184verbose: -1
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000185quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200186dry run: no
Stephen Boyddf217ed2009-05-23 11:53:13 -0700187file: (not set)
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100188arg 00: a1
189arg 01: b1
190arg 02: --boolean
191EOF
192
193test_expect_success 'intermingled arguments' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200194 test-tool parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000195 >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700196 test_must_be_empty output.err &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700197 test_cmp expect output
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100198'
199
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000200cat >expect <<\EOF
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100201boolean: 0
202integer: 2
Charles Bailey2a514ed2015-06-21 19:25:44 +0100203magnitude: 0
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700204timestamp: 0
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100205string: (not set)
Stephan Beyer010a2da2008-06-22 17:04:26 +0200206abbrev: 7
Pranit Bauvae0070e82016-05-05 15:20:00 +0530207verbose: -1
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000208quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200209dry run: no
Stephen Boyddf217ed2009-05-23 11:53:13 -0700210file: (not set)
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100211EOF
212
213test_expect_success 'unambiguously abbreviated option' '
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700214 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200215 test-tool parse-options --int 2 --boolean --no-bo >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700216 test_must_be_empty output.err &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700217 test_cmp expect output
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100218'
219
220test_expect_success 'unambiguously abbreviated option with "="' '
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700221 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200222 test-tool parse-options --expect="integer: 2" --int=2
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100223'
224
Junio C Hamano41ac4142008-02-01 01:50:53 -0800225test_expect_success 'ambiguously abbreviated option' '
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700226 test_expect_code 129 env GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
227 test-tool parse-options --strin 123
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100228'
229
Johannes Schindelin243e0612007-11-05 13:15:21 +0000230test_expect_success 'non ambiguous option (after two options it abbreviates)' '
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700231 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200232 test-tool parse-options --expect="string: 123" --st 123
Johannes Schindelin243e0612007-11-05 13:15:21 +0000233'
234
Nguyễn Thái Ngọc Duy5c387422019-04-29 17:05:25 +0700235test_expect_success 'Alias options do not contribute to abbreviation' '
236 test-tool parse-options --alias-source 123 >output &&
237 grep "^string: 123" output &&
238 test-tool parse-options --alias-target 123 >output &&
239 grep "^string: 123" output &&
240 test_must_fail test-tool parse-options --alias &&
241 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
242 test-tool parse-options --alias 123 >output &&
243 grep "^string: 123" output
244'
245
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000246cat >typo.err <<\EOF
Jacques Bodin-Hullin395518c2020-02-05 13:07:23 +0000247error: did you mean `--boolean` (with two dashes)?
Pierre Habouzit3a9f0f42008-01-26 12:26:57 +0100248EOF
249
250test_expect_success 'detect possible typos' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200251 test_must_fail test-tool parse-options -boolean >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700252 test_must_be_empty output &&
Nguyễn Thái Ngọc Duy89003422018-11-10 06:16:13 +0100253 test_i18ncmp typo.err output.err
Pierre Habouzit3a9f0f42008-01-26 12:26:57 +0100254'
255
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000256cat >typo.err <<\EOF
Jacques Bodin-Hullin395518c2020-02-05 13:07:23 +0000257error: did you mean `--ambiguous` (with two dashes)?
René Scharfe38916c52012-03-03 12:00:29 +0100258EOF
259
260test_expect_success 'detect possible typos' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200261 test_must_fail test-tool parse-options -ambiguous >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700262 test_must_be_empty output &&
Nguyễn Thái Ngọc Duy89003422018-11-10 06:16:13 +0100263 test_i18ncmp typo.err output.err
René Scharfe38916c52012-03-03 12:00:29 +0100264'
265
Pierre Habouzit580d5bf2008-03-02 11:35:56 +0100266test_expect_success 'keep some options as arguments' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200267 test-tool parse-options --expect="arg 00: --quux" --quux
Pierre Habouzit580d5bf2008-03-02 11:35:56 +0100268'
269
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000270cat >expect <<\EOF
Stephan Beyer010a2da2008-06-22 17:04:26 +0200271Callback: "four", 0
272boolean: 5
273integer: 4
Charles Bailey2a514ed2015-06-21 19:25:44 +0100274magnitude: 0
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700275timestamp: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200276string: (not set)
277abbrev: 7
Pranit Bauvae0070e82016-05-05 15:20:00 +0530278verbose: -1
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000279quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200280dry run: no
Stephen Boyddf217ed2009-05-23 11:53:13 -0700281file: (not set)
Stephan Beyer010a2da2008-06-22 17:04:26 +0200282EOF
283
284test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200285 test-tool parse-options --length=four -b -4 >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700286 test_must_be_empty output.err &&
Stephan Beyer010a2da2008-06-22 17:04:26 +0200287 test_cmp expect output
288'
289
Brandon Casey1a9bf1e2017-09-24 21:08:04 -0700290test_expect_success 'OPT_CALLBACK() and callback errors work' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200291 test_must_fail test-tool parse-options --no-length >output 2>output.err &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200292 test_must_be_empty output &&
Paul-Sebastian Ungureanu3bb09232018-03-22 20:43:51 +0200293 test_must_be_empty output.err
Stephan Beyer010a2da2008-06-22 17:04:26 +0200294'
295
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000296cat >expect <<\EOF
Stephan Beyer010a2da2008-06-22 17:04:26 +0200297boolean: 1
298integer: 23
Charles Bailey2a514ed2015-06-21 19:25:44 +0100299magnitude: 0
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700300timestamp: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200301string: (not set)
302abbrev: 7
Pranit Bauvae0070e82016-05-05 15:20:00 +0530303verbose: -1
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000304quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200305dry run: no
Stephen Boyddf217ed2009-05-23 11:53:13 -0700306file: (not set)
Stephan Beyer010a2da2008-06-22 17:04:26 +0200307EOF
308
309test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200310 test-tool parse-options --set23 -bbbbb --no-or4 >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700311 test_must_be_empty output.err &&
Stephan Beyer010a2da2008-06-22 17:04:26 +0200312 test_cmp expect output
313'
314
René Scharfe2f4b97f2009-05-07 21:44:17 +0200315test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200316 test-tool parse-options --set23 -bbbbb --neg-or4 >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700317 test_must_be_empty output.err &&
René Scharfe2f4b97f2009-05-07 21:44:17 +0200318 test_cmp expect output
319'
320
René Scharfe2f4b97f2009-05-07 21:44:17 +0200321test_expect_success 'OPT_BIT() works' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200322 test-tool parse-options --expect="boolean: 6" -bb --or4
René Scharfe2f4b97f2009-05-07 21:44:17 +0200323'
324
325test_expect_success 'OPT_NEGBIT() works' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200326 test-tool parse-options --expect="boolean: 6" -bb --no-neg-or4
René Scharfe2f4b97f2009-05-07 21:44:17 +0200327'
Stephan Beyer010a2da2008-06-22 17:04:26 +0200328
Paolo Bonzini62e7a6f2020-02-20 15:15:15 +0100329test_expect_success 'OPT_CMDMODE() works' '
330 test-tool parse-options --expect="integer: 1" --mode1
331'
332
333test_expect_success 'OPT_CMDMODE() detects incompatibility' '
334 test_must_fail test-tool parse-options --mode1 --mode2 >output 2>output.err &&
335 test_must_be_empty output &&
336 test_i18ngrep "incompatible with --mode" output.err
337'
338
339test_expect_success 'OPT_CMDMODE() detects incompatibility with something else' '
340 test_must_fail test-tool parse-options --set23 --mode2 >output 2>output.err &&
341 test_must_be_empty output &&
342 test_i18ngrep "incompatible with something else" output.err
343'
344
René Scharfeb9e63dd2012-02-25 20:11:16 +0100345test_expect_success 'OPT_COUNTUP() with PARSE_OPT_NODASH works' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200346 test-tool parse-options --expect="boolean: 6" + + + + + +
René Scharfe51a99492009-05-07 21:45:42 +0200347'
348
René Scharfee0319ff2009-05-07 21:45:08 +0200349test_expect_success 'OPT_NUMBER_CALLBACK() works' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200350 test-tool parse-options --expect="integer: 12345" -12345
René Scharfee0319ff2009-05-07 21:45:08 +0200351'
352
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000353cat >expect <<\EOF
Andreas Schwab6bbfd1f2009-09-25 20:44:44 +0200354boolean: 0
355integer: 0
Charles Bailey2a514ed2015-06-21 19:25:44 +0100356magnitude: 0
Andreas Schwab6bbfd1f2009-09-25 20:44:44 +0200357timestamp: 0
358string: (not set)
359abbrev: 7
Pranit Bauvae0070e82016-05-05 15:20:00 +0530360verbose: -1
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000361quiet: 0
Andreas Schwab6bbfd1f2009-09-25 20:44:44 +0200362dry run: no
363file: (not set)
364EOF
365
366test_expect_success 'negation of OPT_NONEG flags is not ambiguous' '
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700367 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200368 test-tool parse-options --no-ambig >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700369 test_must_be_empty output.err &&
Andreas Schwab6bbfd1f2009-09-25 20:44:44 +0200370 test_cmp expect output
371'
372
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000373cat >>expect <<\EOF
Jeff Kingc8ba1632011-06-09 11:55:23 -0400374list: foo
375list: bar
376list: baz
377EOF
378test_expect_success '--list keeps list of strings' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200379 test-tool parse-options --list foo --list=bar --list=baz >output &&
Jeff Kingc8ba1632011-06-09 11:55:23 -0400380 test_cmp expect output
381'
382
383test_expect_success '--no-list resets list' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200384 test-tool parse-options --list=other --list=irrelevant --list=options \
Jeff Kingc8ba1632011-06-09 11:55:23 -0400385 --no-list --list=foo --list=bar --list=baz >output &&
386 test_cmp expect output
387'
388
Pranit Bauva7d177152016-05-05 15:19:58 +0530389test_expect_success 'multiple quiet levels' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200390 test-tool parse-options --expect="quiet: 3" -q -q -q
Pranit Bauva7d177152016-05-05 15:19:58 +0530391'
392
Pranit Bauva7d177152016-05-05 15:19:58 +0530393test_expect_success 'multiple verbose levels' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200394 test-tool parse-options --expect="verbose: 3" -v -v -v
Pranit Bauva7d177152016-05-05 15:19:58 +0530395'
396
Pranit Bauva7d177152016-05-05 15:19:58 +0530397test_expect_success '--no-quiet sets --quiet to 0' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200398 test-tool parse-options --expect="quiet: 0" --no-quiet
Pranit Bauva7d177152016-05-05 15:19:58 +0530399'
400
Pranit Bauva7d177152016-05-05 15:19:58 +0530401test_expect_success '--no-quiet resets multiple -q to 0' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200402 test-tool parse-options --expect="quiet: 0" -q -q -q --no-quiet
Pranit Bauva7d177152016-05-05 15:19:58 +0530403'
404
Pranit Bauva7d177152016-05-05 15:19:58 +0530405test_expect_success '--no-verbose sets verbose to 0' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200406 test-tool parse-options --expect="verbose: 0" --no-verbose
Pranit Bauva7d177152016-05-05 15:19:58 +0530407'
408
Pranit Bauva7d177152016-05-05 15:19:58 +0530409test_expect_success '--no-verbose resets multiple verbose to 0' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200410 test-tool parse-options --expect="verbose: 0" -v -v -v --no-verbose
Pranit Bauva7d177152016-05-05 15:19:58 +0530411'
412
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700413test_expect_success 'GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS works' '
414 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
415 test-tool parse-options --ye &&
416 test_must_fail env GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=true \
417 test-tool parse-options --ye
418'
419
Jeff King51b45942019-08-06 10:40:16 -0400420test_expect_success '--end-of-options treats remainder as args' '
421 test-tool parse-options \
422 --expect="verbose: -1" \
423 --expect="arg 00: --verbose" \
424 --end-of-options --verbose
425'
426
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100427test_done