Merge branch 'maint'
[git/mingw/4msysgit/kblees.git] / t / t1502-rev-parse-parseopt.sh
blobb3195c47070b35d555f8cfae90497a2d00d10ca7
1 #!/bin/sh
3 test_description='test git rev-parse --parseopt'
4 . ./test-lib.sh
6 cat > expect <<\END_EXPECT
7 cat <<\EOF
8 usage: some-command [options] <args>...
10 some-command does foo and bar!
12 -h, --help show the help
13 --foo some nifty option --foo
14 --bar ... some cool option --bar with an argument
16 An option group Header
17 -C[...] option C with an optional argument
19 Extras
20 --extra1 line above used to cause a segfault but no longer does
22 EOF
23 END_EXPECT
25 cat > optionspec << EOF
26 some-command [options] <args>...
28 some-command does foo and bar!
30 h,help show the help
32 foo some nifty option --foo
33 bar= some cool option --bar with an argument
35 An option group Header
36 C? option C with an optional argument
38 Extras
39 extra1 line above used to cause a segfault but no longer does
40 EOF
42 test_expect_success 'test --parseopt help output' '
43 git rev-parse --parseopt -- -h > output < optionspec
44 test_cmp expect output
47 cat > expect <<EOF
48 set -- --foo --bar 'ham' -- 'arg'
49 EOF
51 test_expect_success 'test --parseopt' '
52 git rev-parse --parseopt -- --foo --bar=ham arg < optionspec > output &&
53 test_cmp expect output
56 test_expect_success 'test --parseopt with mixed options and arguments' '
57 git rev-parse --parseopt -- --foo arg --bar=ham < optionspec > output &&
58 test_cmp expect output
61 cat > expect <<EOF
62 set -- --foo -- 'arg' '--bar=ham'
63 EOF
65 test_expect_success 'test --parseopt with --' '
66 git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output &&
67 test_cmp expect output
70 test_expect_success 'test --parseopt --stop-at-non-option' '
71 git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output &&
72 test_cmp expect output
75 cat > expect <<EOF
76 set -- --foo -- '--' 'arg' '--bar=ham'
77 EOF
79 test_expect_success 'test --parseopt --keep-dashdash' '
80 git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output &&
81 test_cmp expect output
84 cat >expect <<EOF
85 set -- --foo -- '--' 'arg' '--spam=ham'
86 EOF
88 test_expect_success 'test --parseopt --keep-dashdash --stop-at-non-option with --' '
89 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo -- arg --spam=ham <optionspec >output &&
90 test_cmp expect output
93 cat > expect <<EOF
94 set -- --foo -- 'arg' '--spam=ham'
95 EOF
97 test_expect_success 'test --parseopt --keep-dashdash --stop-at-non-option without --' '
98 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo arg --spam=ham <optionspec >output &&
99 test_cmp expect output
102 test_done