|
3 | 3 | test_description='test git rev-parse --parseopt'
|
4 | 4 | . ./test-lib.sh
|
5 | 5 |
|
| 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 | + |
6 | 22 | test_expect_success 'setup optionspec' '
|
7 | 23 | sed -e "s/^|//" >optionspec <<\EOF
|
8 | 24 | |some-command [options] <args>...
|
@@ -278,4 +294,32 @@ test_expect_success 'test --parseopt help output: multi-line blurb after empty l
|
278 | 294 | test_cmp expect actual
|
279 | 295 | '
|
280 | 296 |
|
| 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 | + |
281 | 325 | test_done
|
0 commit comments