Skip to content

Commit d5dc68f

Browse files
rscharfegitster
authored andcommitted
t1502: test option negation
Add tests for checking the "git rev-parse --parseopt" flag "!" and whether options can be negated with a "no-" prefix. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8dcb490 commit d5dc68f

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

t/t1502-rev-parse-parseopt.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
test_description='test git rev-parse --parseopt'
44
. ./test-lib.sh
55

6+
check_invalid_long_option () {
7+
spec="$1"
8+
opt="$2"
9+
test_expect_success "test --parseopt invalid switch $opt help output for $spec" '
10+
{
11+
cat <<-\EOF &&
12+
error: unknown option `'${opt#--}\''
13+
EOF
14+
sed -e 1d -e \$d <"$TEST_DIRECTORY/t1502/$spec.help"
15+
} >expect &&
16+
test_expect_code 129 git rev-parse --parseopt -- $opt \
17+
2>output <"$TEST_DIRECTORY/t1502/$spec" &&
18+
test_cmp expect output
19+
'
20+
}
21+
622
test_expect_success 'setup optionspec' '
723
sed -e "s/^|//" >optionspec <<\EOF
824
|some-command [options] <args>...
@@ -278,4 +294,32 @@ test_expect_success 'test --parseopt help output: multi-line blurb after empty l
278294
test_cmp expect actual
279295
'
280296

297+
test_expect_success 'test --parseopt help output for optionspec-neg' '
298+
test_expect_code 129 git rev-parse --parseopt -- \
299+
-h >output <"$TEST_DIRECTORY/t1502/optionspec-neg" &&
300+
test_cmp "$TEST_DIRECTORY/t1502/optionspec-neg.help" output
301+
'
302+
303+
test_expect_success 'test --parseopt valid options for optionspec-neg' '
304+
cat >expect <<-\EOF &&
305+
set -- --foo --no-foo --no-bar --positive-only --no-negative --
306+
EOF
307+
git rev-parse --parseopt -- <"$TEST_DIRECTORY/t1502/optionspec-neg" >output \
308+
--foo --no-foo --no-bar --positive-only --no-negative &&
309+
test_cmp expect output
310+
'
311+
312+
test_expect_success 'test --parseopt positivated option for optionspec-neg' '
313+
cat >expect <<-\EOF &&
314+
set -- --no-no-bar --no-no-bar --
315+
EOF
316+
git rev-parse --parseopt -- <"$TEST_DIRECTORY/t1502/optionspec-neg" >output \
317+
--no-no-bar --bar &&
318+
test_cmp expect output
319+
'
320+
321+
check_invalid_long_option optionspec-neg --no-positive-only
322+
check_invalid_long_option optionspec-neg --negative
323+
check_invalid_long_option optionspec-neg --no-no-negative
324+
281325
test_done

t/t1502/optionspec-neg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
some-command [options] <args>...
2+
3+
some-command does foo and bar!
4+
--
5+
foo can be negated
6+
no-bar can be positivated
7+
positive-only! cannot be negated
8+
no-negative! cannot be positivated

t/t1502/optionspec-neg.help

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cat <<\EOF
2+
usage: some-command [options] <args>...
3+
4+
some-command does foo and bar!
5+
6+
--foo can be negated
7+
--no-bar can be positivated
8+
--positive-only cannot be negated
9+
--no-negative cannot be positivated
10+
11+
EOF

0 commit comments

Comments
 (0)