blob: 705a136ed92c99cda688f5e267204e59b0e532a9 [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
Stephan Beyer010a2da2008-06-22 17:04:26 +020026 -L, --length <str> get length of <str>
Michael J Gruber41dbcd42011-02-15 14:09:13 +010027 -F, --file <file> set file to <file>
Johannes Schindelinbeb47432007-10-13 17:34:45 +010028
Stephan Beyer010a2da2008-06-22 17:04:26 +020029String options
Johannes Schindelinbeb47432007-10-13 17:34:45 +010030 -s, --string <string>
31 get a string
32 --string2 <str> get another string
Johannes Schindelin243e0612007-11-05 13:15:21 +000033 --st <st> get another string (pervert ordering)
Pierre Habouzit3a9f0f42008-01-26 12:26:57 +010034 -o <str> get another string
Jeff Kingc8ba1632011-06-09 11:55:23 -040035 --list <str> add str to list
Johannes Schindelinbeb47432007-10-13 17:34:45 +010036
Stephan Beyer010a2da2008-06-22 17:04:26 +020037Magic arguments
Pierre Habouzit580d5bf2008-03-02 11:35:56 +010038 --quux means --quux
René Scharfee0319ff2009-05-07 21:45:08 +020039 -NUM set integer to NUM
René Scharfe51a99492009-05-07 21:45:42 +020040 + same as -b
Andreas Schwab6bbfd1f2009-09-25 20:44:44 +020041 --ambiguous positive ambiguity
42 --no-ambiguous negative ambiguity
Pierre Habouzit580d5bf2008-03-02 11:35:56 +010043
Stephan Beyer010a2da2008-06-22 17:04:26 +020044Standard options
45 --abbrev[=<n>] use <n> digits to display SHA-1s
46 -v, --verbose be verbose
47 -n, --dry-run dry run
48 -q, --quiet be quiet
Junio C Hamanoab6b28b2016-05-05 14:36:55 -070049 --expect <string> expected output in the variable dump
Stephan Beyer010a2da2008-06-22 17:04:26 +020050
Nguyễn Thái Ngọc Duy5c387422019-04-29 17:05:25 +070051Alias
52 -A, --alias-source <string>
53 get a string
54 -Z, --alias-target <string>
55 get a string
56
Johannes Schindelinbeb47432007-10-13 17:34:45 +010057EOF
58
59test_expect_success 'test help' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +020060 test_must_fail test-tool parse-options -h >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -070061 test_must_be_empty output.err &&
Jiang Xin9a001382012-08-27 13:36:55 +080062 test_i18ncmp expect output
Johannes Schindelinbeb47432007-10-13 17:34:45 +010063'
64
Giuseppe Scrivano9c7304e2010-05-17 17:34:41 +020065mv expect expect.err
66
Junio C Hamano8ca65ae2016-05-06 11:17:05 -070067check () {
René Scharfeb9e63dd2012-02-25 20:11:16 +010068 what="$1" &&
69 shift &&
70 expect="$1" &&
71 shift &&
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +020072 test-tool parse-options --expect="$what $expect" "$@"
René Scharfeb9e63dd2012-02-25 20:11:16 +010073}
74
Jiang Xin9a001382012-08-27 13:36:55 +080075check_unknown_i18n() {
76 case "$1" in
77 --*)
78 echo error: unknown option \`${1#--}\' >expect ;;
79 -*)
80 echo error: unknown switch \`${1#-}\' >expect ;;
81 esac &&
82 cat expect.err >>expect &&
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +020083 test_must_fail test-tool parse-options $* >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -070084 test_must_be_empty output &&
Jiang Xin9a001382012-08-27 13:36:55 +080085 test_i18ncmp expect output.err
86}
87
René Scharfeb9e63dd2012-02-25 20:11:16 +010088test_expect_success 'OPT_BOOL() #1' 'check boolean: 1 --yes'
89test_expect_success 'OPT_BOOL() #2' 'check boolean: 1 --no-doubt'
90test_expect_success 'OPT_BOOL() #3' 'check boolean: 1 -D'
91test_expect_success 'OPT_BOOL() #4' 'check boolean: 1 --no-fear'
92test_expect_success 'OPT_BOOL() #5' 'check boolean: 1 -B'
93
94test_expect_success 'OPT_BOOL() is idempotent #1' 'check boolean: 1 --yes --yes'
95test_expect_success 'OPT_BOOL() is idempotent #2' 'check boolean: 1 -DB'
96
97test_expect_success 'OPT_BOOL() negation #1' 'check boolean: 0 -D --no-yes'
98test_expect_success 'OPT_BOOL() negation #2' 'check boolean: 0 -D --no-no-doubt'
99
Brandon Casey1a9bf1e2017-09-24 21:08:04 -0700100test_expect_success 'OPT_BOOL() no negation #1' 'check_unknown_i18n --fear'
101test_expect_success 'OPT_BOOL() no negation #2' 'check_unknown_i18n --no-no-fear'
René Scharfeb9e63dd2012-02-25 20:11:16 +0100102
René Scharfe0f1930c52012-02-25 20:14:54 +0100103test_expect_success 'OPT_BOOL() positivation' 'check boolean: 0 -D --doubt'
René Scharfeb9e63dd2012-02-25 20:11:16 +0100104
Charles Bailey81a48cc2015-06-21 19:25:43 +0100105test_expect_success 'OPT_INT() negative' 'check integer: -2345 -i -2345'
106
Charles Bailey2a514ed2015-06-21 19:25:44 +0100107test_expect_success 'OPT_MAGNITUDE() simple' '
108 check magnitude: 2345678 -m 2345678
109'
110
111test_expect_success 'OPT_MAGNITUDE() kilo' '
112 check magnitude: 239616 -m 234k
113'
114
115test_expect_success 'OPT_MAGNITUDE() mega' '
116 check magnitude: 104857600 -m 100m
117'
118
119test_expect_success 'OPT_MAGNITUDE() giga' '
120 check magnitude: 1073741824 -m 1g
121'
122
123test_expect_success 'OPT_MAGNITUDE() 3giga' '
124 check magnitude: 3221225472 -m 3g
125'
126
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000127cat >expect <<\EOF
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100128boolean: 2
129integer: 1729
Charles Bailey2a514ed2015-06-21 19:25:44 +0100130magnitude: 16384
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700131timestamp: 0
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100132string: 123
Stephan Beyer010a2da2008-06-22 17:04:26 +0200133abbrev: 7
134verbose: 2
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000135quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200136dry run: yes
Stephen Boyddf217ed2009-05-23 11:53:13 -0700137file: prefix/my.file
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100138EOF
139
140test_expect_success 'short options' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200141 test-tool parse-options -s123 -b -i 1729 -m 16k -b -vv -n -F my.file \
Charles Bailey2a514ed2015-06-21 19:25:44 +0100142 >output 2>output.err &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700143 test_cmp expect output &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700144 test_must_be_empty output.err
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100145'
Stephan Beyer010a2da2008-06-22 17:04:26 +0200146
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000147cat >expect <<\EOF
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100148boolean: 2
149integer: 1729
Charles Bailey2a514ed2015-06-21 19:25:44 +0100150magnitude: 16384
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700151timestamp: 0
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100152string: 321
Stephan Beyer010a2da2008-06-22 17:04:26 +0200153abbrev: 10
154verbose: 2
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000155quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200156dry run: no
Stephen Boyddf217ed2009-05-23 11:53:13 -0700157file: prefix/fi.le
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100158EOF
159
160test_expect_success 'long options' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200161 test-tool parse-options --boolean --integer 1729 --magnitude 16k \
Charles Bailey2a514ed2015-06-21 19:25:44 +0100162 --boolean --string2=321 --verbose --verbose --no-dry-run \
163 --abbrev=10 --file fi.le --obsolete \
164 >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700165 test_must_be_empty output.err &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700166 test_cmp expect output
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100167'
168
Olivier Marind5d745f2008-07-21 20:30:36 +0200169test_expect_success 'missing required value' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200170 test_expect_code 129 test-tool parse-options -s &&
171 test_expect_code 129 test-tool parse-options --string &&
172 test_expect_code 129 test-tool parse-options --file
Olivier Marind5d745f2008-07-21 20:30:36 +0200173'
174
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000175cat >expect <<\EOF
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100176boolean: 1
177integer: 13
Charles Bailey2a514ed2015-06-21 19:25:44 +0100178magnitude: 0
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700179timestamp: 0
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100180string: 123
Stephan Beyer010a2da2008-06-22 17:04:26 +0200181abbrev: 7
Pranit Bauvae0070e82016-05-05 15:20:00 +0530182verbose: -1
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000183quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200184dry run: no
Stephen Boyddf217ed2009-05-23 11:53:13 -0700185file: (not set)
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100186arg 00: a1
187arg 01: b1
188arg 02: --boolean
189EOF
190
191test_expect_success 'intermingled arguments' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200192 test-tool parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000193 >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700194 test_must_be_empty output.err &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700195 test_cmp expect output
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100196'
197
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000198cat >expect <<\EOF
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100199boolean: 0
200integer: 2
Charles Bailey2a514ed2015-06-21 19:25:44 +0100201magnitude: 0
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700202timestamp: 0
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100203string: (not set)
Stephan Beyer010a2da2008-06-22 17:04:26 +0200204abbrev: 7
Pranit Bauvae0070e82016-05-05 15:20:00 +0530205verbose: -1
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000206quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200207dry run: no
Stephen Boyddf217ed2009-05-23 11:53:13 -0700208file: (not set)
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100209EOF
210
211test_expect_success 'unambiguously abbreviated option' '
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700212 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200213 test-tool parse-options --int 2 --boolean --no-bo >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700214 test_must_be_empty output.err &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700215 test_cmp expect output
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100216'
217
218test_expect_success 'unambiguously abbreviated option with "="' '
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700219 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200220 test-tool parse-options --expect="integer: 2" --int=2
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100221'
222
Junio C Hamano41ac4142008-02-01 01:50:53 -0800223test_expect_success 'ambiguously abbreviated option' '
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700224 test_expect_code 129 env GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
225 test-tool parse-options --strin 123
Johannes Schindelin7f275b92007-10-14 17:54:06 +0100226'
227
Johannes Schindelin243e0612007-11-05 13:15:21 +0000228test_expect_success 'non ambiguous option (after two options it abbreviates)' '
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700229 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200230 test-tool parse-options --expect="string: 123" --st 123
Johannes Schindelin243e0612007-11-05 13:15:21 +0000231'
232
Nguyễn Thái Ngọc Duy5c387422019-04-29 17:05:25 +0700233test_expect_success 'Alias options do not contribute to abbreviation' '
234 test-tool parse-options --alias-source 123 >output &&
235 grep "^string: 123" output &&
236 test-tool parse-options --alias-target 123 >output &&
237 grep "^string: 123" output &&
238 test_must_fail test-tool parse-options --alias &&
239 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
240 test-tool parse-options --alias 123 >output &&
241 grep "^string: 123" output
242'
243
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000244cat >typo.err <<\EOF
245error: did you mean `--boolean` (with two dashes ?)
Pierre Habouzit3a9f0f42008-01-26 12:26:57 +0100246EOF
247
248test_expect_success 'detect possible typos' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200249 test_must_fail test-tool parse-options -boolean >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700250 test_must_be_empty output &&
Nguyễn Thái Ngọc Duy89003422018-11-10 06:16:13 +0100251 test_i18ncmp typo.err output.err
Pierre Habouzit3a9f0f42008-01-26 12:26:57 +0100252'
253
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000254cat >typo.err <<\EOF
255error: did you mean `--ambiguous` (with two dashes ?)
René Scharfe38916c52012-03-03 12:00:29 +0100256EOF
257
258test_expect_success 'detect possible typos' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200259 test_must_fail test-tool parse-options -ambiguous >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700260 test_must_be_empty output &&
Nguyễn Thái Ngọc Duy89003422018-11-10 06:16:13 +0100261 test_i18ncmp typo.err output.err
René Scharfe38916c52012-03-03 12:00:29 +0100262'
263
Pierre Habouzit580d5bf2008-03-02 11:35:56 +0100264test_expect_success 'keep some options as arguments' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200265 test-tool parse-options --expect="arg 00: --quux" --quux
Pierre Habouzit580d5bf2008-03-02 11:35:56 +0100266'
267
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000268cat >expect <<\EOF
Stephan Beyer010a2da2008-06-22 17:04:26 +0200269Callback: "four", 0
270boolean: 5
271integer: 4
Charles Bailey2a514ed2015-06-21 19:25:44 +0100272magnitude: 0
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700273timestamp: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200274string: (not set)
275abbrev: 7
Pranit Bauvae0070e82016-05-05 15:20:00 +0530276verbose: -1
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000277quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200278dry run: no
Stephen Boyddf217ed2009-05-23 11:53:13 -0700279file: (not set)
Stephan Beyer010a2da2008-06-22 17:04:26 +0200280EOF
281
282test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200283 test-tool parse-options --length=four -b -4 >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700284 test_must_be_empty output.err &&
Stephan Beyer010a2da2008-06-22 17:04:26 +0200285 test_cmp expect output
286'
287
Brandon Casey1a9bf1e2017-09-24 21:08:04 -0700288test_expect_success 'OPT_CALLBACK() and callback errors work' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200289 test_must_fail test-tool parse-options --no-length >output 2>output.err &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200290 test_must_be_empty output &&
Paul-Sebastian Ungureanu3bb09232018-03-22 20:43:51 +0200291 test_must_be_empty output.err
Stephan Beyer010a2da2008-06-22 17:04:26 +0200292'
293
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000294cat >expect <<\EOF
Stephan Beyer010a2da2008-06-22 17:04:26 +0200295boolean: 1
296integer: 23
Charles Bailey2a514ed2015-06-21 19:25:44 +0100297magnitude: 0
Junio C Hamanoc4aca9c2008-07-30 12:53:45 -0700298timestamp: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200299string: (not set)
300abbrev: 7
Pranit Bauvae0070e82016-05-05 15:20:00 +0530301verbose: -1
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000302quiet: 0
Stephan Beyer010a2da2008-06-22 17:04:26 +0200303dry run: no
Stephen Boyddf217ed2009-05-23 11:53:13 -0700304file: (not set)
Stephan Beyer010a2da2008-06-22 17:04:26 +0200305EOF
306
307test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200308 test-tool parse-options --set23 -bbbbb --no-or4 >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700309 test_must_be_empty output.err &&
Stephan Beyer010a2da2008-06-22 17:04:26 +0200310 test_cmp expect output
311'
312
René Scharfe2f4b97f2009-05-07 21:44:17 +0200313test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200314 test-tool parse-options --set23 -bbbbb --neg-or4 >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700315 test_must_be_empty output.err &&
René Scharfe2f4b97f2009-05-07 21:44:17 +0200316 test_cmp expect output
317'
318
René Scharfe2f4b97f2009-05-07 21:44:17 +0200319test_expect_success 'OPT_BIT() works' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200320 test-tool parse-options --expect="boolean: 6" -bb --or4
René Scharfe2f4b97f2009-05-07 21:44:17 +0200321'
322
323test_expect_success 'OPT_NEGBIT() works' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200324 test-tool parse-options --expect="boolean: 6" -bb --no-neg-or4
René Scharfe2f4b97f2009-05-07 21:44:17 +0200325'
Stephan Beyer010a2da2008-06-22 17:04:26 +0200326
René Scharfeb9e63dd2012-02-25 20:11:16 +0100327test_expect_success 'OPT_COUNTUP() with PARSE_OPT_NODASH works' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200328 test-tool parse-options --expect="boolean: 6" + + + + + +
René Scharfe51a99492009-05-07 21:45:42 +0200329'
330
René Scharfee0319ff2009-05-07 21:45:08 +0200331test_expect_success 'OPT_NUMBER_CALLBACK() works' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200332 test-tool parse-options --expect="integer: 12345" -12345
René Scharfee0319ff2009-05-07 21:45:08 +0200333'
334
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000335cat >expect <<\EOF
Andreas Schwab6bbfd1f2009-09-25 20:44:44 +0200336boolean: 0
337integer: 0
Charles Bailey2a514ed2015-06-21 19:25:44 +0100338magnitude: 0
Andreas Schwab6bbfd1f2009-09-25 20:44:44 +0200339timestamp: 0
340string: (not set)
341abbrev: 7
Pranit Bauvae0070e82016-05-05 15:20:00 +0530342verbose: -1
Pranit Bauva36e6a5b2016-04-12 23:02:17 +0000343quiet: 0
Andreas Schwab6bbfd1f2009-09-25 20:44:44 +0200344dry run: no
345file: (not set)
346EOF
347
348test_expect_success 'negation of OPT_NONEG flags is not ambiguous' '
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700349 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200350 test-tool parse-options --no-ambig >output 2>output.err &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700351 test_must_be_empty output.err &&
Andreas Schwab6bbfd1f2009-09-25 20:44:44 +0200352 test_cmp expect output
353'
354
Pranit Bauva8425b7e2016-04-12 23:02:17 +0000355cat >>expect <<\EOF
Jeff Kingc8ba1632011-06-09 11:55:23 -0400356list: foo
357list: bar
358list: baz
359EOF
360test_expect_success '--list keeps list of strings' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200361 test-tool parse-options --list foo --list=bar --list=baz >output &&
Jeff Kingc8ba1632011-06-09 11:55:23 -0400362 test_cmp expect output
363'
364
365test_expect_success '--no-list resets list' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200366 test-tool parse-options --list=other --list=irrelevant --list=options \
Jeff Kingc8ba1632011-06-09 11:55:23 -0400367 --no-list --list=foo --list=bar --list=baz >output &&
368 test_cmp expect output
369'
370
Pranit Bauva7d177152016-05-05 15:19:58 +0530371test_expect_success 'multiple quiet levels' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200372 test-tool parse-options --expect="quiet: 3" -q -q -q
Pranit Bauva7d177152016-05-05 15:19:58 +0530373'
374
Pranit Bauva7d177152016-05-05 15:19:58 +0530375test_expect_success 'multiple verbose levels' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200376 test-tool parse-options --expect="verbose: 3" -v -v -v
Pranit Bauva7d177152016-05-05 15:19:58 +0530377'
378
Pranit Bauva7d177152016-05-05 15:19:58 +0530379test_expect_success '--no-quiet sets --quiet to 0' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200380 test-tool parse-options --expect="quiet: 0" --no-quiet
Pranit Bauva7d177152016-05-05 15:19:58 +0530381'
382
Pranit Bauva7d177152016-05-05 15:19:58 +0530383test_expect_success '--no-quiet resets multiple -q to 0' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200384 test-tool parse-options --expect="quiet: 0" -q -q -q --no-quiet
Pranit Bauva7d177152016-05-05 15:19:58 +0530385'
386
Pranit Bauva7d177152016-05-05 15:19:58 +0530387test_expect_success '--no-verbose sets verbose to 0' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200388 test-tool parse-options --expect="verbose: 0" --no-verbose
Pranit Bauva7d177152016-05-05 15:19:58 +0530389'
390
Pranit Bauva7d177152016-05-05 15:19:58 +0530391test_expect_success '--no-verbose resets multiple verbose to 0' '
Nguyễn Thái Ngọc Duy2f17c782018-09-09 19:36:29 +0200392 test-tool parse-options --expect="verbose: 0" -v -v -v --no-verbose
Pranit Bauva7d177152016-05-05 15:19:58 +0530393'
394
Johannes Schindelinb02e7d52019-04-12 02:37:24 -0700395test_expect_success 'GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS works' '
396 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
397 test-tool parse-options --ye &&
398 test_must_fail env GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=true \
399 test-tool parse-options --ye
400'
401
Jeff King51b45942019-08-06 10:40:16 -0400402test_expect_success '--end-of-options treats remainder as args' '
403 test-tool parse-options \
404 --expect="verbose: -1" \
405 --expect="arg 00: --verbose" \
406 --end-of-options --verbose
407'
408
Johannes Schindelinbeb47432007-10-13 17:34:45 +0100409test_done