t7501: add tests for --include and --only
[git/gitster.git] / t / t5750-bundle-uri-parse.sh
blob81bdf58b94443415083cd1dca427e08564f9af53
1 #!/bin/sh
3 test_description="Test bundle-uri bundle_uri_parse_line()"
5 TEST_NO_CREATE_REPO=1
6 TEST_PASSES_SANITIZE_LEAK=true
7 . ./test-lib.sh
9 test_expect_success 'bundle_uri_parse_line() just URIs' '
10 cat >in <<-\EOF &&
11 bundle.one.uri=http://example.com/bundle.bdl
12 bundle.two.uri=https://example.com/bundle.bdl
13 bundle.three.uri=file:///usr/share/git/bundle.bdl
14 EOF
16 cat >expect <<-\EOF &&
17 [bundle]
18 version = 1
19 mode = all
20 [bundle "one"]
21 uri = http://example.com/bundle.bdl
22 [bundle "two"]
23 uri = https://example.com/bundle.bdl
24 [bundle "three"]
25 uri = file:///usr/share/git/bundle.bdl
26 EOF
28 test-tool bundle-uri parse-key-values in >actual 2>err &&
29 test_must_be_empty err &&
30 test_cmp_config_output expect actual
33 test_expect_success 'bundle_uri_parse_line(): relative URIs' '
34 cat >in <<-\EOF &&
35 bundle.one.uri=bundle.bdl
36 bundle.two.uri=../bundle.bdl
37 bundle.three.uri=sub/dir/bundle.bdl
38 EOF
40 cat >expect <<-\EOF &&
41 [bundle]
42 version = 1
43 mode = all
44 [bundle "one"]
45 uri = <uri>/bundle.bdl
46 [bundle "two"]
47 uri = bundle.bdl
48 [bundle "three"]
49 uri = <uri>/sub/dir/bundle.bdl
50 EOF
52 test-tool bundle-uri parse-key-values in >actual 2>err &&
53 test_must_be_empty err &&
54 test_cmp_config_output expect actual
57 test_expect_success 'bundle_uri_parse_line(): relative URIs and parent paths' '
58 cat >in <<-\EOF &&
59 bundle.one.uri=bundle.bdl
60 bundle.two.uri=../bundle.bdl
61 bundle.three.uri=../../bundle.bdl
62 EOF
64 cat >expect <<-\EOF &&
65 [bundle]
66 version = 1
67 mode = all
68 [bundle "one"]
69 uri = <uri>/bundle.bdl
70 [bundle "two"]
71 uri = bundle.bdl
72 [bundle "three"]
73 uri = <uri>/../bundle.bdl
74 EOF
76 # TODO: We would prefer if parsing a bundle list would not cause
77 # a die() and instead would give a warning and allow the rest of
78 # a Git command to continue. This test_must_fail is necessary for
79 # now until the interface for relative_url() allows for reporting
80 # an error instead of die()ing.
81 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err &&
82 grep "fatal: cannot strip one component off url" err
85 test_expect_success 'bundle_uri_parse_line() parsing edge cases: empty key or value' '
86 cat >in <<-\EOF &&
87 =bogus-value
88 bogus-key=
89 EOF
91 cat >err.expect <<-EOF &&
92 error: bundle-uri: line has empty key or value
93 error: bad line: '\''=bogus-value'\''
94 error: bundle-uri: line has empty key or value
95 error: bad line: '\''bogus-key='\''
96 EOF
98 cat >expect <<-\EOF &&
99 [bundle]
100 version = 1
101 mode = all
104 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err &&
105 test_cmp err.expect err &&
106 test_cmp_config_output expect actual
109 test_expect_success 'bundle_uri_parse_line() parsing edge cases: empty lines' '
110 cat >in <<-\EOF &&
111 bundle.one.uri=http://example.com/bundle.bdl
113 bundle.two.uri=https://example.com/bundle.bdl
115 bundle.three.uri=file:///usr/share/git/bundle.bdl
118 cat >err.expect <<-\EOF &&
119 error: bundle-uri: got an empty line
120 error: bad line: '\'''\''
121 error: bundle-uri: got an empty line
122 error: bad line: '\'''\''
125 # We fail, but try to continue parsing regardless
126 cat >expect <<-\EOF &&
127 [bundle]
128 version = 1
129 mode = all
130 [bundle "one"]
131 uri = http://example.com/bundle.bdl
132 [bundle "two"]
133 uri = https://example.com/bundle.bdl
134 [bundle "three"]
135 uri = file:///usr/share/git/bundle.bdl
138 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err &&
139 test_cmp err.expect err &&
140 test_cmp_config_output expect actual
143 test_expect_success 'bundle_uri_parse_line() parsing edge cases: duplicate lines' '
144 cat >in <<-\EOF &&
145 bundle.one.uri=http://example.com/bundle.bdl
146 bundle.two.uri=https://example.com/bundle.bdl
147 bundle.one.uri=https://example.com/bundle-2.bdl
148 bundle.three.uri=file:///usr/share/git/bundle.bdl
151 cat >err.expect <<-\EOF &&
152 error: bad line: '\''bundle.one.uri=https://example.com/bundle-2.bdl'\''
155 # We fail, but try to continue parsing regardless
156 cat >expect <<-\EOF &&
157 [bundle]
158 version = 1
159 mode = all
160 [bundle "one"]
161 uri = http://example.com/bundle.bdl
162 [bundle "two"]
163 uri = https://example.com/bundle.bdl
164 [bundle "three"]
165 uri = file:///usr/share/git/bundle.bdl
168 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err &&
169 test_cmp err.expect err &&
170 test_cmp_config_output expect actual
173 test_expect_success 'parse config format: just URIs' '
174 cat >expect <<-\EOF &&
175 [bundle]
176 version = 1
177 mode = all
178 [bundle "one"]
179 uri = http://example.com/bundle.bdl
180 [bundle "two"]
181 uri = https://example.com/bundle.bdl
182 [bundle "three"]
183 uri = file:///usr/share/git/bundle.bdl
186 test-tool bundle-uri parse-config expect >actual 2>err &&
187 test_must_be_empty err &&
188 test_cmp_config_output expect actual
191 test_expect_success 'parse config format: relative URIs' '
192 cat >in <<-\EOF &&
193 [bundle]
194 version = 1
195 mode = all
196 [bundle "one"]
197 uri = bundle.bdl
198 [bundle "two"]
199 uri = ../bundle.bdl
200 [bundle "three"]
201 uri = sub/dir/bundle.bdl
204 cat >expect <<-\EOF &&
205 [bundle]
206 version = 1
207 mode = all
208 [bundle "one"]
209 uri = <uri>/bundle.bdl
210 [bundle "two"]
211 uri = bundle.bdl
212 [bundle "three"]
213 uri = <uri>/sub/dir/bundle.bdl
216 test-tool bundle-uri parse-config in >actual 2>err &&
217 test_must_be_empty err &&
218 test_cmp_config_output expect actual
221 test_expect_success 'parse config format edge cases: empty key or value' '
222 cat >in1 <<-\EOF &&
223 = bogus-value
226 cat >err1 <<-EOF &&
227 error: bad config line 1 in file in1
230 cat >expect <<-\EOF &&
231 [bundle]
232 version = 1
233 mode = all
236 test_must_fail test-tool bundle-uri parse-config in1 >actual 2>err &&
237 test_cmp err1 err &&
238 test_cmp_config_output expect actual &&
240 cat >in2 <<-\EOF &&
241 bogus-key =
244 cat >err2 <<-EOF &&
245 error: bad config line 1 in file in2
248 test_must_fail test-tool bundle-uri parse-config in2 >actual 2>err &&
249 test_cmp err2 err &&
250 test_cmp_config_output expect actual
253 test_expect_success 'parse config format: creationToken heuristic' '
254 cat >expect <<-\EOF &&
255 [bundle]
256 version = 1
257 mode = all
258 heuristic = creationToken
259 [bundle "one"]
260 uri = http://example.com/bundle.bdl
261 creationToken = 123456
262 [bundle "two"]
263 uri = https://example.com/bundle.bdl
264 creationToken = 12345678901234567890
265 [bundle "three"]
266 uri = file:///usr/share/git/bundle.bdl
267 creationToken = 1
270 test-tool bundle-uri parse-config expect >actual 2>err &&
271 test_must_be_empty err &&
272 test_cmp_config_output expect actual
275 test_expect_success 'parse config format edge cases: creationToken heuristic' '
276 cat >expect <<-\EOF &&
277 [bundle]
278 version = 1
279 mode = all
280 heuristic = creationToken
281 [bundle "one"]
282 uri = http://example.com/bundle.bdl
283 creationToken = bogus
286 test-tool bundle-uri parse-config expect >actual 2>err &&
287 grep "could not parse bundle list key creationToken with value '\''bogus'\''" err
290 test_done