3 test_description
='test git rev-parse --parseopt'
7 usage: some-command [options] <args>...
9 some-command does foo and bar!
11 -h, --help show the help
12 --foo some nifty option --foo
13 --bar ... some cool option --bar with an argument
15 An option group Header
16 -C[...] option C with an optional argument
19 --extra1 line above used to cause a segfault but no longer does
23 cat > optionspec
<< EOF
24 some-command [options] <args>...
26 some-command does foo and bar!
30 foo some nifty option --foo
31 bar= some cool option --bar with an argument
33 An option group Header
34 C? option C with an optional argument
37 extra1 line above used to cause a segfault but no longer does
40 test_expect_success
'test --parseopt help output' '
41 git rev-parse --parseopt -- -h 2> output.err < optionspec
42 test_cmp expect.err output.err
46 set -- --foo --bar 'ham' -- 'arg'
49 test_expect_success
'test --parseopt' '
50 git rev-parse --parseopt -- --foo --bar=ham arg < optionspec > output &&
51 test_cmp expect output
54 test_expect_success
'test --parseopt with mixed options and arguments' '
55 git rev-parse --parseopt -- --foo arg --bar=ham < optionspec > output &&
56 test_cmp expect output
60 set -- --foo -- 'arg' '--bar=ham'
63 test_expect_success
'test --parseopt with --' '
64 git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output &&
65 test_cmp expect output
68 test_expect_success
'test --parseopt --stop-at-non-option' '
69 git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output &&
70 test_cmp expect output
74 set -- --foo -- '--' 'arg' '--bar=ham'
77 test_expect_success
'test --parseopt --keep-dashdash' '
78 git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output &&
79 test_cmp expect output
83 set -- --foo -- '--' 'arg' '--spam=ham'
86 test_expect_success
'test --parseopt --keep-dashdash --stop-at-non-option with --' '
87 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo -- arg --spam=ham <optionspec >output &&
88 test_cmp expect output
92 set -- --foo -- 'arg' '--spam=ham'
95 test_expect_success
'test --parseopt --keep-dashdash --stop-at-non-option without --' '
96 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo arg --spam=ham <optionspec >output &&
97 test_cmp expect output