Merge branch 'jh/fsmonitor-darwin-modernize'
[git.git] / t / t5750-bundle-uri-parse.sh
blobc2fe3f9c5a5c40543e8c2c0b65949c0dbfc1b594
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() parsing edge cases: empty key or value' '
34 cat >in <<-\EOF &&
35 =bogus-value
36 bogus-key=
37 EOF
39 cat >err.expect <<-EOF &&
40 error: bundle-uri: line has empty key or value
41 error: bad line: '\''=bogus-value'\''
42 error: bundle-uri: line has empty key or value
43 error: bad line: '\''bogus-key='\''
44 EOF
46 cat >expect <<-\EOF &&
47 [bundle]
48 version = 1
49 mode = all
50 EOF
52 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err &&
53 test_cmp err.expect err &&
54 test_cmp_config_output expect actual
57 test_expect_success 'bundle_uri_parse_line() parsing edge cases: empty lines' '
58 cat >in <<-\EOF &&
59 bundle.one.uri=http://example.com/bundle.bdl
61 bundle.two.uri=https://example.com/bundle.bdl
63 bundle.three.uri=file:///usr/share/git/bundle.bdl
64 EOF
66 cat >err.expect <<-\EOF &&
67 error: bundle-uri: got an empty line
68 error: bad line: '\'''\''
69 error: bundle-uri: got an empty line
70 error: bad line: '\'''\''
71 EOF
73 # We fail, but try to continue parsing regardless
74 cat >expect <<-\EOF &&
75 [bundle]
76 version = 1
77 mode = all
78 [bundle "one"]
79 uri = http://example.com/bundle.bdl
80 [bundle "two"]
81 uri = https://example.com/bundle.bdl
82 [bundle "three"]
83 uri = file:///usr/share/git/bundle.bdl
84 EOF
86 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err &&
87 test_cmp err.expect err &&
88 test_cmp_config_output expect actual
91 test_expect_success 'bundle_uri_parse_line() parsing edge cases: duplicate lines' '
92 cat >in <<-\EOF &&
93 bundle.one.uri=http://example.com/bundle.bdl
94 bundle.two.uri=https://example.com/bundle.bdl
95 bundle.one.uri=https://example.com/bundle-2.bdl
96 bundle.three.uri=file:///usr/share/git/bundle.bdl
97 EOF
99 cat >err.expect <<-\EOF &&
100 error: bad line: '\''bundle.one.uri=https://example.com/bundle-2.bdl'\''
103 # We fail, but try to continue parsing regardless
104 cat >expect <<-\EOF &&
105 [bundle]
106 version = 1
107 mode = all
108 [bundle "one"]
109 uri = http://example.com/bundle.bdl
110 [bundle "two"]
111 uri = https://example.com/bundle.bdl
112 [bundle "three"]
113 uri = file:///usr/share/git/bundle.bdl
116 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err &&
117 test_cmp err.expect err &&
118 test_cmp_config_output expect actual
121 test_expect_success 'parse config format: just URIs' '
122 cat >expect <<-\EOF &&
123 [bundle]
124 version = 1
125 mode = all
126 [bundle "one"]
127 uri = http://example.com/bundle.bdl
128 [bundle "two"]
129 uri = https://example.com/bundle.bdl
130 [bundle "three"]
131 uri = file:///usr/share/git/bundle.bdl
134 test-tool bundle-uri parse-config expect >actual 2>err &&
135 test_must_be_empty err &&
136 test_cmp_config_output expect actual
139 test_expect_success 'parse config format edge cases: empty key or value' '
140 cat >in1 <<-\EOF &&
141 = bogus-value
144 cat >err1 <<-EOF &&
145 error: bad config line 1 in file in1
148 cat >expect <<-\EOF &&
149 [bundle]
150 version = 1
151 mode = all
154 test_must_fail test-tool bundle-uri parse-config in1 >actual 2>err &&
155 test_cmp err1 err &&
156 test_cmp_config_output expect actual &&
158 cat >in2 <<-\EOF &&
159 bogus-key =
162 cat >err2 <<-EOF &&
163 error: bad config line 1 in file in2
166 test_must_fail test-tool bundle-uri parse-config in2 >actual 2>err &&
167 test_cmp err2 err &&
168 test_cmp_config_output expect actual
171 test_done