]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1502-rev-parse-parseopt.sh
daemon: look up client-supplied hostname lazily
[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
ce7f8745
JH
6sed -e 's/^|//' >expect <<\END_EXPECT
7|cat <<\EOF
8|usage: some-command [options] <args>...
9|
10| some-command does foo and bar!
11|
12| -h, --help show the help
13| --foo some nifty option --foo
14| --bar ... some cool option --bar with an argument
15| -b, --baz a short and long option
16|
17|An option group Header
18| -C[...] option C with an optional argument
19| -d, --data[=...] short and long option with an optional argument
20|
21|Argument hints
22| -b <arg> short option required argument
23| --bar2 <arg> long option required argument
24| -e, --fuz <with-space>
25| 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>
30| a very long argument hint
31|
32|Extras
33| --extra1 line above used to cause a segfault but no longer does
34|
35|EOF
47e9cd28 36END_EXPECT
e1033436 37
ce7f8745
JH
38sed -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
e1033436 64EOF
824af25a
UKK
65
66test_expect_success 'test --parseopt help output' '
2b5ec018 67 test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&
9a001381 68 test_i18ncmp expect output
e1033436
JS
69'
70
824af25a 71cat > expect <<EOF
f8c87212 72set -- --foo --bar 'ham' -b -- 'arg'
824af25a
UKK
73EOF
74
75test_expect_success 'test --parseopt' '
f8c87212 76 git rev-parse --parseopt -- --foo --bar=ham --baz arg < optionspec > output &&
824af25a
UKK
77 test_cmp expect output
78'
79
80test_expect_success 'test --parseopt with mixed options and arguments' '
f8c87212 81 git rev-parse --parseopt -- --foo arg --bar=ham --baz < optionspec > output &&
824af25a
UKK
82 test_cmp expect output
83'
84
85cat > expect <<EOF
86set -- --foo -- 'arg' '--bar=ham'
87EOF
88
89test_expect_success 'test --parseopt with --' '
90 git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output &&
91 test_cmp expect output
92'
93
6e0800ef
UKK
94test_expect_success 'test --parseopt --stop-at-non-option' '
95 git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output &&
96 test_cmp expect output
97'
98
824af25a
UKK
99cat > expect <<EOF
100set -- --foo -- '--' 'arg' '--bar=ham'
101EOF
102
103test_expect_success 'test --parseopt --keep-dashdash' '
104 git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output &&
105 test_cmp expect output
106'
107
29981380
UKK
108cat >expect <<EOF
109set -- --foo -- '--' 'arg' '--spam=ham'
110EOF
111
112test_expect_success 'test --parseopt --keep-dashdash --stop-at-non-option with --' '
113 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo -- arg --spam=ham <optionspec >output &&
114 test_cmp expect output
115'
116
117cat > expect <<EOF
118set -- --foo -- 'arg' '--spam=ham'
119EOF
120
121test_expect_success 'test --parseopt --keep-dashdash --stop-at-non-option without --' '
122 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo arg --spam=ham <optionspec >output &&
123 test_cmp expect output
124'
125
f8c87212
NV
126cat > expect <<EOF
127set -- --foo --bar='z' --baz -C'Z' --data='A' -- 'arg'
128EOF
129
130test_expect_success 'test --parseopt --stuck-long' '
131 git rev-parse --parseopt --stuck-long -- --foo --bar=z -b arg -CZ -dA <optionspec >output &&
132 test_cmp expect output
133'
134
135cat > expect <<EOF
136set -- --data='' -C --baz -- 'arg'
137EOF
138
139test_expect_success 'test --parseopt --stuck-long and empty optional argument' '
140 git rev-parse --parseopt --stuck-long -- --data= arg -C -b <optionspec >output &&
141 test_cmp expect output
142'
143
144cat > expect <<EOF
145set -- --data --baz -- 'arg'
146EOF
147
148test_expect_success 'test --parseopt --stuck-long and long option with unset optional argument' '
149 git rev-parse --parseopt --stuck-long -- --data arg -b <optionspec >output &&
150 test_cmp expect output
151'
152
153test_expect_success 'test --parseopt --stuck-long and short option with unset optional argument' '
154 git rev-parse --parseopt --stuck-long -- -d arg -b <optionspec >output &&
155 test_cmp expect output
156'
157
e1033436 158test_done