Skip to content

Commit e7587a8

Browse files
avargitster
authored andcommitted
config tests: add "NULL" tests for *_get_value_multi()
A less well known edge case in the config format is that keys can be value-less, a shorthand syntax for "true" boolean keys. I.e. these two are equivalent as far as "--type=bool" is concerned: [a]key [a]key = true But as far as our parser is concerned the values for these two are NULL, and "true". I.e. for a sequence like: [a]key=x [a]key [a]key=y We get a "struct string_list" with "string" members with ".string" values of: { "x", NULL, "y" } This behavior goes back to the initial implementation of git_config_bool() in 1771299 (Add ".git/config" file parser, 2005-10-10). When parts of the config_set API were tested for in [1] they didn't add coverage for 3/4 of the "(NULL)" cases handled in "t/helper/test-config.c". We'd test that case for "get_value", but not "get_value_multi", "configset_get_value" and "configset_get_value_multi". We now cover all of those cases, which in turn expose the details of how this part of the config API works. 1. 4c715eb (test-config: add tests for the config_set API, 2014-07-28) Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 258902c commit e7587a8

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

t/t1308-config-set.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,71 @@ test_expect_success 'find multiple values' '
146146
check_config get_value_multi case.baz sam bat hask
147147
'
148148

149+
test_NULL_in_multi () {
150+
local op="$1" &&
151+
local file="$2" &&
152+
153+
test_expect_success "$op: NULL value in config${file:+ in $file}" '
154+
config="$file" &&
155+
if test -z "$config"
156+
then
157+
config=.git/config &&
158+
test_when_finished "mv $config.old $config" &&
159+
mv "$config" "$config".old
160+
fi &&
161+
162+
# Value-less in the middle of a list
163+
cat >"$config" <<-\EOF &&
164+
[a]key=x
165+
[a]key
166+
[a]key=y
167+
EOF
168+
case "$op" in
169+
*_multi)
170+
cat >expect <<-\EOF
171+
x
172+
(NULL)
173+
y
174+
EOF
175+
;;
176+
*)
177+
cat >expect <<-\EOF
178+
y
179+
EOF
180+
;;
181+
esac &&
182+
test-tool config "$op" a.key $file >actual &&
183+
test_cmp expect actual &&
184+
185+
# Value-less at the end of a least
186+
cat >"$config" <<-\EOF &&
187+
[a]key=x
188+
[a]key=y
189+
[a]key
190+
EOF
191+
case "$op" in
192+
*_multi)
193+
cat >expect <<-\EOF
194+
x
195+
y
196+
(NULL)
197+
EOF
198+
;;
199+
*)
200+
cat >expect <<-\EOF
201+
(NULL)
202+
EOF
203+
;;
204+
esac &&
205+
test-tool config "$op" a.key $file >actual &&
206+
test_cmp expect actual
207+
'
208+
}
209+
210+
test_NULL_in_multi "get_value_multi"
211+
test_NULL_in_multi "configset_get_value" "my.config"
212+
test_NULL_in_multi "configset_get_value_multi" "my.config"
213+
149214
test_expect_success 'find value from a configset' '
150215
cat >config2 <<-\EOF &&
151216
[case]

0 commit comments

Comments
 (0)