]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1502-rev-parse-parseopt.sh
completion tests: consolidate getting path of current working directory
[thirdparty/git.git] / t / t1502-rev-parse-parseopt.sh
CommitLineData
e1033436
JS
1#!/bin/sh
2
3test_description='test git rev-parse --parseopt'
4. ./test-lib.sh
5
2d893dff
IB
6test_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
35EOF
36'
37
38test_expect_success 'test --parseopt help output' '
39 sed -e "s/^|//" >expect <<\END_EXPECT &&
ce7f8745
JH
40|cat <<\EOF
41|usage: some-command [options] <args>...
42|
43| some-command does foo and bar!
44|
45| -h, --help show the help
46| --foo some nifty option --foo
47| --bar ... some cool option --bar with an argument
48| -b, --baz a short and long option
49|
50|An option group Header
51| -C[...] option C with an optional argument
52| -d, --data[=...] short and long option with an optional argument
53|
54|Argument hints
af465af8 55| -B <arg> short option required argument
ce7f8745
JH
56| --bar2 <arg> long option required argument
57| -e, --fuz <with-space>
58| short and long option required argument
59| -s[<some>] short option optional argument
60| --long[=<data>] long option optional argument
61| -g, --fluf[=<path>] short and long option optional argument
62| --longest <very-long-argument-hint>
63| a very long argument hint
2d893dff
IB
64| --pair <key=value> with an equals sign in the hint
65| --short-hint <a> with a one symbol hint
ce7f8745
JH
66|
67|Extras
68| --extra1 line above used to cause a segfault but no longer does
69|
70|EOF
47e9cd28 71END_EXPECT
2b5ec018 72 test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&
9a001381 73 test_i18ncmp expect output
e1033436
JS
74'
75
2d893dff
IB
76test_expect_success 'setup expect.1' "
77 cat > expect <<EOF
f8c87212 78set -- --foo --bar 'ham' -b -- 'arg'
824af25a 79EOF
2d893dff 80"
824af25a
UKK
81
82test_expect_success 'test --parseopt' '
f8c87212 83 git rev-parse --parseopt -- --foo --bar=ham --baz arg < optionspec > output &&
824af25a
UKK
84 test_cmp expect output
85'
86
87test_expect_success 'test --parseopt with mixed options and arguments' '
f8c87212 88 git rev-parse --parseopt -- --foo arg --bar=ham --baz < optionspec > output &&
824af25a
UKK
89 test_cmp expect output
90'
91
2d893dff
IB
92test_expect_success 'setup expect.2' "
93 cat > expect <<EOF
824af25a
UKK
94set -- --foo -- 'arg' '--bar=ham'
95EOF
2d893dff 96"
824af25a
UKK
97
98test_expect_success 'test --parseopt with --' '
99 git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output &&
100 test_cmp expect output
101'
102
6e0800ef
UKK
103test_expect_success 'test --parseopt --stop-at-non-option' '
104 git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output &&
105 test_cmp expect output
106'
107
2d893dff
IB
108test_expect_success 'setup expect.3' "
109 cat > expect <<EOF
824af25a
UKK
110set -- --foo -- '--' 'arg' '--bar=ham'
111EOF
2d893dff 112"
824af25a
UKK
113
114test_expect_success 'test --parseopt --keep-dashdash' '
115 git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output &&
116 test_cmp expect output
117'
118
2d893dff
IB
119test_expect_success 'setup expect.4' "
120 cat >expect <<EOF
29981380
UKK
121set -- --foo -- '--' 'arg' '--spam=ham'
122EOF
2d893dff 123"
29981380
UKK
124
125test_expect_success 'test --parseopt --keep-dashdash --stop-at-non-option with --' '
126 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo -- arg --spam=ham <optionspec >output &&
127 test_cmp expect output
128'
129
2d893dff
IB
130test_expect_success 'setup expect.5' "
131 cat > expect <<EOF
29981380
UKK
132set -- --foo -- 'arg' '--spam=ham'
133EOF
2d893dff 134"
29981380
UKK
135
136test_expect_success 'test --parseopt --keep-dashdash --stop-at-non-option without --' '
137 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo arg --spam=ham <optionspec >output &&
138 test_cmp expect output
139'
140
2d893dff
IB
141test_expect_success 'setup expect.6' "
142 cat > expect <<EOF
f8c87212
NV
143set -- --foo --bar='z' --baz -C'Z' --data='A' -- 'arg'
144EOF
2d893dff 145"
f8c87212
NV
146
147test_expect_success 'test --parseopt --stuck-long' '
148 git rev-parse --parseopt --stuck-long -- --foo --bar=z -b arg -CZ -dA <optionspec >output &&
149 test_cmp expect output
150'
151
2d893dff
IB
152test_expect_success 'setup expect.7' "
153 cat > expect <<EOF
f8c87212
NV
154set -- --data='' -C --baz -- 'arg'
155EOF
2d893dff 156"
f8c87212
NV
157
158test_expect_success 'test --parseopt --stuck-long and empty optional argument' '
159 git rev-parse --parseopt --stuck-long -- --data= arg -C -b <optionspec >output &&
160 test_cmp expect output
161'
162
2d893dff
IB
163test_expect_success 'setup expect.8' "
164 cat > expect <<EOF
f8c87212
NV
165set -- --data --baz -- 'arg'
166EOF
2d893dff 167"
f8c87212
NV
168
169test_expect_success 'test --parseopt --stuck-long and long option with unset optional argument' '
170 git rev-parse --parseopt --stuck-long -- --data arg -b <optionspec >output &&
171 test_cmp expect output
172'
173
174test_expect_success 'test --parseopt --stuck-long and short option with unset optional argument' '
175 git rev-parse --parseopt --stuck-long -- -d arg -b <optionspec >output &&
176 test_cmp expect output
177'
178
e1033436 179test_done