Ævar Arnfjörð Bjarmason | d796ced | 2022-10-12 12:52:32 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description="Test bundle-uri bundle_uri_parse_line()" |
| 4 | |
| 5 | TEST_NO_CREATE_REPO=1 |
| 6 | TEST_PASSES_SANITIZE_LEAK=true |
| 7 | . ./test-lib.sh |
| 8 | |
| 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 |
| 15 | |
| 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 |
| 27 | |
| 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 |
| 31 | ' |
| 32 | |
| 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 |
| 38 | |
| 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 |
| 45 | |
| 46 | cat >expect <<-\EOF && |
| 47 | [bundle] |
| 48 | version = 1 |
| 49 | mode = all |
| 50 | EOF |
| 51 | |
| 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 |
| 55 | ' |
| 56 | |
| 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 |
| 60 | |
| 61 | bundle.two.uri=https://example.com/bundle.bdl |
| 62 | |
| 63 | bundle.three.uri=file:///usr/share/git/bundle.bdl |
| 64 | EOF |
| 65 | |
| 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 |
| 72 | |
| 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 |
| 85 | |
| 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 |
| 89 | ' |
| 90 | |
| 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 |
| 98 | |
| 99 | cat >err.expect <<-\EOF && |
| 100 | error: bad line: '\''bundle.one.uri=https://example.com/bundle-2.bdl'\'' |
| 101 | EOF |
| 102 | |
| 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 |
| 114 | EOF |
| 115 | |
| 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 |
| 119 | ' |
| 120 | |
Derrick Stolee | 738e524 | 2022-10-12 12:52:33 +0000 | [diff] [blame] | 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 |
| 132 | EOF |
| 133 | |
| 134 | test-tool bundle-uri parse-config expect >actual 2>err && |
| 135 | test_must_be_empty err && |
| 136 | test_cmp_config_output expect actual |
| 137 | ' |
| 138 | |
| 139 | test_expect_success 'parse config format edge cases: empty key or value' ' |
| 140 | cat >in1 <<-\EOF && |
| 141 | = bogus-value |
| 142 | EOF |
| 143 | |
| 144 | cat >err1 <<-EOF && |
| 145 | error: bad config line 1 in file in1 |
| 146 | EOF |
| 147 | |
| 148 | cat >expect <<-\EOF && |
| 149 | [bundle] |
| 150 | version = 1 |
| 151 | mode = all |
| 152 | EOF |
| 153 | |
| 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 && |
| 157 | |
| 158 | cat >in2 <<-\EOF && |
| 159 | bogus-key = |
| 160 | EOF |
| 161 | |
| 162 | cat >err2 <<-EOF && |
| 163 | error: bad config line 1 in file in2 |
| 164 | EOF |
| 165 | |
| 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 |
| 169 | ' |
| 170 | |
Ævar Arnfjörð Bjarmason | d796ced | 2022-10-12 12:52:32 +0000 | [diff] [blame] | 171 | test_done |