Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t5750-bundle-uri-parse.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t5750-bundle-uri-parse.sh` 315 lines ยท 7434 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description="Test bundle-uri bundle_uri_parse_line()" 4 5 TEST_NO_CREATE_REPO=1 6 . ./test-lib.sh 7 8 test_expect_success 'bundle_uri_parse_line() just URIs' ' 9 cat >in <<-\EOF && 10 bundle.one.uri=http://example.com/bundle.bdl 11 bundle.two.uri=https://example.com/bundle.bdl 12 bundle.three.uri=file:///usr/share/git/bundle.bdl 13 EOF 14 15 cat >expect <<-\EOF && 16 [bundle] 17 version = 1 18 mode = all 19 [bundle "one"] 20 uri = http://example.com/bundle.bdl 21 [bundle "two"] 22 uri = https://example.com/bundle.bdl 23 [bundle "three"] 24 uri = file:///usr/share/git/bundle.bdl 25 EOF 26 27 test-tool bundle-uri parse-key-values in >actual 2>err && 28 test_must_be_empty err && 29 test_cmp_config_output expect actual 30 ' 31 32 test_expect_success 'bundle_uri_parse_line(): relative URIs' ' 33 cat >in <<-\EOF && 34 bundle.one.uri=bundle.bdl 35 bundle.two.uri=../bundle.bdl 36 bundle.three.uri=sub/dir/bundle.bdl 37 EOF 38 39 cat >expect <<-\EOF && 40 [bundle] 41 version = 1 42 mode = all 43 [bundle "one"] 44 uri = /bundle.bdl 45 [bundle "two"] 46 uri = bundle.bdl 47 [bundle "three"] 48 uri = /sub/dir/bundle.bdl 49 EOF 50 51 test-tool bundle-uri parse-key-values in >actual 2>err && 52 test_must_be_empty err && 53 test_cmp_config_output expect actual 54 ' 55 56 test_expect_success 'bundle_uri_parse_line(): relative URIs and parent paths' ' 57 cat >in <<-\EOF && 58 bundle.one.uri=bundle.bdl 59 bundle.two.uri=../bundle.bdl 60 bundle.three.uri=../../bundle.bdl 61 EOF 62 63 cat >expect <<-\EOF && 64 [bundle] 65 version = 1 66 mode = all 67 [bundle "one"] 68 uri = /bundle.bdl 69 [bundle "two"] 70 uri = bundle.bdl 71 [bundle "three"] 72 uri = /../bundle.bdl 73 EOF 74 75 # TODO: We would prefer if parsing a bundle list would not cause 76 # a die() and instead would give a warning and allow the rest of 77 # a Git command to continue. This test_must_fail is necessary for 78 # now until the interface for relative_url() allows for reporting 79 # an error instead of die()ing. 80 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err && 81 test_grep "fatal: cannot strip one component off url" err 82 ' 83 84 test_expect_success 'bundle_uri_parse_line() parsing edge cases: empty key or value' ' 85 cat >in <<-\EOF && 86 =bogus-value 87 bogus-key= 88 EOF 89 90 cat >err.expect <<-EOF && 91 error: bundle-uri: line has empty key or value 92 error: bad line: '\''=bogus-value'\'' 93 error: bundle-uri: line has empty key or value 94 error: bad line: '\''bogus-key='\'' 95 EOF 96 97 cat >expect <<-\EOF && 98 [bundle] 99 version = 1 100 mode = all 101 EOF 102 103 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err && 104 test_cmp err.expect err && 105 test_cmp_config_output expect actual 106 ' 107 108 test_expect_success 'bundle_uri_parse_line() parsing edge cases: empty lines' ' 109 cat >in <<-\EOF && 110 bundle.one.uri=http://example.com/bundle.bdl 111 112 bundle.two.uri=https://example.com/bundle.bdl 113 114 bundle.three.uri=file:///usr/share/git/bundle.bdl 115 EOF 116 117 cat >err.expect <<-\EOF && 118 error: bundle-uri: got an empty line 119 error: bad line: '\'''\'' 120 error: bundle-uri: got an empty line 121 error: bad line: '\'''\'' 122 EOF 123 124 # We fail, but try to continue parsing regardless 125 cat >expect <<-\EOF && 126 [bundle] 127 version = 1 128 mode = all 129 [bundle "one"] 130 uri = http://example.com/bundle.bdl 131 [bundle "two"] 132 uri = https://example.com/bundle.bdl 133 [bundle "three"] 134 uri = file:///usr/share/git/bundle.bdl 135 EOF 136 137 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err && 138 test_cmp err.expect err && 139 test_cmp_config_output expect actual 140 ' 141 142 test_expect_success 'bundle_uri_parse_line() parsing edge cases: duplicate lines' ' 143 cat >in <<-\EOF && 144 bundle.one.uri=http://example.com/bundle.bdl 145 bundle.two.uri=https://example.com/bundle.bdl 146 bundle.one.uri=https://example.com/bundle-2.bdl 147 bundle.three.uri=file:///usr/share/git/bundle.bdl 148 EOF 149 150 cat >err.expect <<-\EOF && 151 error: bad line: '\''bundle.one.uri=https://example.com/bundle-2.bdl'\'' 152 EOF 153 154 # We fail, but try to continue parsing regardless 155 cat >expect <<-\EOF && 156 [bundle] 157 version = 1 158 mode = all 159 [bundle "one"] 160 uri = http://example.com/bundle.bdl 161 [bundle "two"] 162 uri = https://example.com/bundle.bdl 163 [bundle "three"] 164 uri = file:///usr/share/git/bundle.bdl 165 EOF 166 167 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err && 168 test_cmp err.expect err && 169 test_cmp_config_output expect actual 170 ' 171 172 test_expect_success 'parse config format: just URIs' ' 173 cat >expect <<-\EOF && 174 [bundle] 175 version = 1 176 mode = all 177 [bundle "one"] 178 uri = http://example.com/bundle.bdl 179 [bundle "two"] 180 uri = https://example.com/bundle.bdl 181 [bundle "three"] 182 uri = file:///usr/share/git/bundle.bdl 183 EOF 184 185 test-tool bundle-uri parse-config expect >actual 2>err && 186 test_must_be_empty err && 187 test_cmp_config_output expect actual 188 ' 189 190 test_expect_success 'parse config format: relative URIs' ' 191 cat >in <<-\EOF && 192 [bundle] 193 version = 1 194 mode = all 195 [bundle "one"] 196 uri = bundle.bdl 197 [bundle "two"] 198 uri = ../bundle.bdl 199 [bundle "three"] 200 uri = sub/dir/bundle.bdl 201 EOF 202 203 cat >expect <<-\EOF && 204 [bundle] 205 version = 1 206 mode = all 207 [bundle "one"] 208 uri = /bundle.bdl 209 [bundle "two"] 210 uri = bundle.bdl 211 [bundle "three"] 212 uri = /sub/dir/bundle.bdl 213 EOF 214 215 test-tool bundle-uri parse-config in >actual 2>err && 216 test_must_be_empty err && 217 test_cmp_config_output expect actual 218 ' 219 220 test_expect_success 'parse config format edge cases: empty key or value' ' 221 cat >in1 <<-\EOF && 222 = bogus-value 223 EOF 224 225 cat >err1 <<-EOF && 226 error: bad config line 1 in file in1 227 EOF 228 229 cat >expect <<-\EOF && 230 [bundle] 231 version = 1 232 mode = all 233 EOF 234 235 test_must_fail test-tool bundle-uri parse-config in1 >actual 2>err && 236 test_cmp err1 err && 237 test_cmp_config_output expect actual && 238 239 cat >in2 <<-\EOF && 240 bogus-key = 241 EOF 242 243 cat >err2 <<-EOF && 244 error: bad config line 1 in file in2 245 EOF 246 247 test_must_fail test-tool bundle-uri parse-config in2 >actual 2>err && 248 test_cmp err2 err && 249 test_cmp_config_output expect actual 250 ' 251 252 test_expect_success 'parse config format: creationToken heuristic' ' 253 cat >expect <<-\EOF && 254 [bundle] 255 version = 1 256 mode = all 257 heuristic = creationToken 258 [bundle "one"] 259 uri = http://example.com/bundle.bdl 260 creationToken = 123456 261 [bundle "two"] 262 uri = https://example.com/bundle.bdl 263 creationToken = `12345678901234567890` 264 [bundle "three"] 265 uri = file:///usr/share/git/bundle.bdl 266 creationToken = 1 267 EOF 268 269 test-tool bundle-uri parse-config expect >actual 2>err && 270 test_must_be_empty err && 271 test_cmp_config_output expect actual 272 ' 273 274 test_expect_success 'parse config format edge cases: creationToken heuristic' ' 275 cat >expect <<-\EOF && 276 [bundle] 277 version = 1 278 mode = all 279 heuristic = creationToken 280 [bundle "one"] 281 uri = http://example.com/bundle.bdl 282 creationToken = bogus 283 EOF 284 285 test-tool bundle-uri parse-config expect >actual 2>err && 286 test_grep "could not parse bundle list key creationToken with value '\''bogus'\''" err 287 ' 288 289 test_expect_success 'parse config format: bundle with missing uri' ' 290 cat >input <<-\EOF && 291 [bundle] 292 version = 1 293 mode = all 294 [bundle "missing-uri"] 295 creationToken = 1 296 EOF 297 298 test_must_fail test-tool bundle-uri parse-config input 2>err && 299 test_grep "bundle '\''missing-uri'\'' has no uri" err 300 ' 301 302 test_expect_success 'parse config format: bundle with url instead of uri' ' 303 cat >input <<-\EOF && 304 [bundle] 305 version = 1 306 mode = all 307 [bundle "typo"] 308 url = https://example.com/bundle.bdl 309 EOF 310 311 test_must_fail test-tool bundle-uri parse-config input 2>err && 312 test_grep "bundle '\''typo'\'' has no uri" err 313 ' 314 315 test_done