summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-12-05 20:59:03 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-12-05 20:59:04 (GMT)
commit3576f113cb3f36b9e2b36a84573754a922f2998b (patch)
tree6a37475bcceb021ee9b3f2345abac1dd4078c9e6 /t
parentc5a77e8f9293674e9a936f01cc1719a316f87d24 (diff)
parentf8c872127d4c48a6ec02abce34cb059ddeb6402a (diff)
downloadgit-3576f113cb3f36b9e2b36a84573754a922f2998b.zip
git-3576f113cb3f36b9e2b36a84573754a922f2998b.tar.gz
git-3576f113cb3f36b9e2b36a84573754a922f2998b.tar.bz2
Merge branch 'nv/parseopt-opt-arg'
Enhance "rev-parse --parseopt" mode to help parsing options with an optional parameter. * nv/parseopt-opt-arg: rev-parse --parseopt: add the --stuck-long mode Use the word 'stuck' instead of 'sticked'
Diffstat (limited to 't')
-rwxr-xr-xt/t1502-rev-parse-parseopt.sh42
1 files changed, 39 insertions, 3 deletions
diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh
index 13c88c9..83b1300 100755
--- a/t/t1502-rev-parse-parseopt.sh
+++ b/t/t1502-rev-parse-parseopt.sh
@@ -12,9 +12,11 @@ usage: some-command [options] <args>...
-h, --help show the help
--foo some nifty option --foo
--bar ... some cool option --bar with an argument
+ -b, --baz a short and long option
An option group Header
-C[...] option C with an optional argument
+ -d, --data[=...] short and long option with an optional argument
Extras
--extra1 line above used to cause a segfault but no longer does
@@ -31,9 +33,11 @@ h,help show the help
foo some nifty option --foo
bar= some cool option --bar with an argument
+b,baz a short and long option
An option group Header
C? option C with an optional argument
+d,data? short and long option with an optional argument
Extras
extra1 line above used to cause a segfault but no longer does
@@ -45,16 +49,16 @@ test_expect_success 'test --parseopt help output' '
'
cat > expect <<EOF
-set -- --foo --bar 'ham' -- 'arg'
+set -- --foo --bar 'ham' -b -- 'arg'
EOF
test_expect_success 'test --parseopt' '
- git rev-parse --parseopt -- --foo --bar=ham arg < optionspec > output &&
+ git rev-parse --parseopt -- --foo --bar=ham --baz arg < optionspec > output &&
test_cmp expect output
'
test_expect_success 'test --parseopt with mixed options and arguments' '
- git rev-parse --parseopt -- --foo arg --bar=ham < optionspec > output &&
+ git rev-parse --parseopt -- --foo arg --bar=ham --baz < optionspec > output &&
test_cmp expect output
'
@@ -99,4 +103,36 @@ test_expect_success 'test --parseopt --keep-dashdash --stop-at-non-option withou
test_cmp expect output
'
+cat > expect <<EOF
+set -- --foo --bar='z' --baz -C'Z' --data='A' -- 'arg'
+EOF
+
+test_expect_success 'test --parseopt --stuck-long' '
+ git rev-parse --parseopt --stuck-long -- --foo --bar=z -b arg -CZ -dA <optionspec >output &&
+ test_cmp expect output
+'
+
+cat > expect <<EOF
+set -- --data='' -C --baz -- 'arg'
+EOF
+
+test_expect_success 'test --parseopt --stuck-long and empty optional argument' '
+ git rev-parse --parseopt --stuck-long -- --data= arg -C -b <optionspec >output &&
+ test_cmp expect output
+'
+
+cat > expect <<EOF
+set -- --data --baz -- 'arg'
+EOF
+
+test_expect_success 'test --parseopt --stuck-long and long option with unset optional argument' '
+ git rev-parse --parseopt --stuck-long -- --data arg -b <optionspec >output &&
+ test_cmp expect output
+'
+
+test_expect_success 'test --parseopt --stuck-long and short option with unset optional argument' '
+ git rev-parse --parseopt --stuck-long -- -d arg -b <optionspec >output &&
+ test_cmp expect output
+'
+
test_done