1#!/bin/sh
23
test_description='test git rev-parse --parseopt'
4. ./test-lib.sh
56
cat > expect.err <<EOF
7usage: some-command [options] <args>...
89
some-command does foo and bar!
1011
-h, --help show the help
12--foo some nifty option --foo
13--bar ... some cool option --bar with an argument
1415
An option group Header
16-C[...] option C with an optional argument
1718
Extras
19--extra1 line above used to cause a segfault but no longer does
2021
EOF
2223
cat > optionspec << EOF
24some-command [options] <args>...
2526
some-command does foo and bar!
27--
28h,help show the help
2930
foo some nifty option --foo
31bar= some cool option --bar with an argument
3233
An option group Header
34C? option C with an optional argument
3536
Extras
37extra1 line above used to cause a segfault but no longer does
38EOF
3940
test_expect_success 'test --parseopt help output' '
41git rev-parse --parseopt -- -h 2> output.err < optionspec
42test_cmp expect.err output.err
43'
4445
cat > expect <<EOF
46set -- --foo --bar 'ham' -- 'arg'
47EOF
4849
test_expect_success 'test --parseopt' '
50git rev-parse --parseopt -- --foo --bar=ham arg < optionspec > output &&
51test_cmp expect output
52'
5354
test_expect_success 'test --parseopt with mixed options and arguments' '
55git rev-parse --parseopt -- --foo arg --bar=ham < optionspec > output &&
56test_cmp expect output
57'
5859
cat > expect <<EOF
60set -- --foo -- 'arg' '--bar=ham'
61EOF
6263
test_expect_success 'test --parseopt with --' '
64git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output &&
65test_cmp expect output
66'
6768
test_expect_success 'test --parseopt --stop-at-non-option' '
69git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output &&
70test_cmp expect output
71'
7273
cat > expect <<EOF
74set -- --foo -- '--' 'arg' '--bar=ham'
75EOF
7677
test_expect_success 'test --parseopt --keep-dashdash' '
78git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output &&
79test_cmp expect output
80'
8182
test_done