33test_description=' test git rev-parse --parseopt'
44. ./test-lib.sh
55
6- sed -e ' s/^|//' > expect << \END_EXPECT
6+ test_expect_success ' setup optionspec' '
7+ sed -e "s/^|//" >optionspec <<\EOF
8+ |some-command [options] <args>...
9+ |
10+ |some-command does foo and bar!
11+ |--
12+ |h,help show the help
13+ |
14+ |foo some nifty option --foo
15+ |bar= some cool option --bar with an argument
16+ |b,baz a short and long option
17+ |
18+ | An option group Header
19+ |C? option C with an optional argument
20+ |d,data? short and long option with an optional argument
21+ |
22+ | Argument hints
23+ |B=arg short option required argument
24+ |bar2=arg long option required argument
25+ |e,fuz=with-space short and long option required argument
26+ |s?some short option optional argument
27+ |long?data long option optional argument
28+ |g,fluf?path short and long option optional argument
29+ |longest=very-long-argument-hint a very long argument hint
30+ |pair=key=value with an equals sign in the hint
31+ |short-hint=a with a one symbol hint
32+ |
33+ |Extras
34+ |extra1 line above used to cause a segfault but no longer does
35+ EOF
36+ '
37+
38+ test_expect_success ' test --parseopt help output' '
39+ sed -e "s/^|//" >expect <<\END_EXPECT &&
740|cat <<\EOF
841|usage: some-command [options] <args>...
942|
@@ -28,49 +61,23 @@ sed -e 's/^|//' >expect <<\END_EXPECT
2861| -g, --fluf[=<path>] short and long option optional argument
2962| --longest <very-long-argument-hint>
3063| a very long argument hint
64+ | --pair <key=value> with an equals sign in the hint
65+ | --short-hint <a> with a one symbol hint
3166|
3267|Extras
3368| --extra1 line above used to cause a segfault but no longer does
3469|
3570|EOF
3671END_EXPECT
37-
38- sed -e ' s/^|//' > optionspec << \EOF
39- |some-command [options] <args>...
40- |
41- |some-command does foo and bar!
42- |--
43- |h,help show the help
44- |
45- |foo some nifty option --foo
46- |bar= some cool option --bar with an argument
47- |b,baz a short and long option
48- |
49- | An option group Header
50- |C? option C with an optional argument
51- |d,data? short and long option with an optional argument
52- |
53- | Argument hints
54- |B=arg short option required argument
55- |bar2=arg long option required argument
56- |e,fuz=with-space short and long option required argument
57- |s?some short option optional argument
58- |long?data long option optional argument
59- |g,fluf?path short and long option optional argument
60- |longest=very-long-argument-hint a very long argument hint
61- |
62- |Extras
63- |extra1 line above used to cause a segfault but no longer does
64- EOF
65-
66- test_expect_success ' test --parseopt help output' '
6772 test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&
6873 test_i18ncmp expect output
6974'
7075
71- cat > expect << EOF
76+ test_expect_success ' setup expect.1' "
77+ cat > expect <<EOF
7278set -- --foo --bar 'ham' -b -- 'arg'
7379EOF
80+ "
7481
7582test_expect_success ' test --parseopt' '
7683 git rev-parse --parseopt -- --foo --bar=ham --baz arg < optionspec > output &&
@@ -82,9 +89,11 @@ test_expect_success 'test --parseopt with mixed options and arguments' '
8289 test_cmp expect output
8390'
8491
85- cat > expect << EOF
92+ test_expect_success ' setup expect.2' "
93+ cat > expect <<EOF
8694set -- --foo -- 'arg' '--bar=ham'
8795EOF
96+ "
8897
8998test_expect_success ' test --parseopt with --' '
9099 git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output &&
@@ -96,54 +105,66 @@ test_expect_success 'test --parseopt --stop-at-non-option' '
96105 test_cmp expect output
97106'
98107
99- cat > expect << EOF
108+ test_expect_success ' setup expect.3' "
109+ cat > expect <<EOF
100110set -- --foo -- '--' 'arg' '--bar=ham'
101111EOF
112+ "
102113
103114test_expect_success ' test --parseopt --keep-dashdash' '
104115 git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output &&
105116 test_cmp expect output
106117'
107118
108- cat > expect << EOF
119+ test_expect_success ' setup expect.4' "
120+ cat >expect <<EOF
109121set -- --foo -- '--' 'arg' '--spam=ham'
110122EOF
123+ "
111124
112125test_expect_success ' test --parseopt --keep-dashdash --stop-at-non-option with --' '
113126 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo -- arg --spam=ham <optionspec >output &&
114127 test_cmp expect output
115128'
116129
117- cat > expect << EOF
130+ test_expect_success ' setup expect.5' "
131+ cat > expect <<EOF
118132set -- --foo -- 'arg' '--spam=ham'
119133EOF
134+ "
120135
121136test_expect_success ' test --parseopt --keep-dashdash --stop-at-non-option without --' '
122137 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo arg --spam=ham <optionspec >output &&
123138 test_cmp expect output
124139'
125140
126- cat > expect << EOF
141+ test_expect_success ' setup expect.6' "
142+ cat > expect <<EOF
127143set -- --foo --bar='z' --baz -C'Z' --data='A' -- 'arg'
128144EOF
145+ "
129146
130147test_expect_success ' test --parseopt --stuck-long' '
131148 git rev-parse --parseopt --stuck-long -- --foo --bar=z -b arg -CZ -dA <optionspec >output &&
132149 test_cmp expect output
133150'
134151
135- cat > expect << EOF
152+ test_expect_success ' setup expect.7' "
153+ cat > expect <<EOF
136154set -- --data='' -C --baz -- 'arg'
137155EOF
156+ "
138157
139158test_expect_success ' test --parseopt --stuck-long and empty optional argument' '
140159 git rev-parse --parseopt --stuck-long -- --data= arg -C -b <optionspec >output &&
141160 test_cmp expect output
142161'
143162
144- cat > expect << EOF
163+ test_expect_success ' setup expect.8' "
164+ cat > expect <<EOF
145165set -- --data --baz -- 'arg'
146166EOF
167+ "
147168
148169test_expect_success ' test --parseopt --stuck-long and long option with unset optional argument' '
149170 git rev-parse --parseopt --stuck-long -- --data arg -b <optionspec >output &&
0 commit comments