t1300: add more tests for whitespace and inline comments

Add a handful of additional tests, to improve the coverage of the handling of configuration file entries whose values contain internal whitespace, leading and/or trailing whitespace, which may or may not be enclosed within quotation marks, or which contain an additional inline comment. At the same time, rework one already existing whitespace-related test a bit, to ensure its consistency with the newly added tests. This change introduced no functional changes to the already existing test. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Dragan Simic <dsimic@manjaro.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Dragan Simic committed Mar 21, 2024 at 07:06 UTC d71bc1b4a3301b69b83f1363c85c3e07f114c426
1 file changed +111 -3
t/t1300-config.sh
+111 -3
@@ -11,6 +11,98 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
13
14 +test_expect_success 'setup whitespace config' '
15 + sed -e "s/^|//" \
16 + -e "s/[$]$//" \
17 + -e "s/X/ /g" >.git/config <<-\EOF
18 + [section]
19 + | solid = rock
20 + | sparse = big XX blue
21 + | sparseAndTail = big XX blue $
22 + | sparseAndTailQuoted = "big XX blue "
23 + | sparseAndBiggerTail = big XX blue X X
24 + | sparseAndBiggerTailQuoted = "big XX blue X X"
25 + | sparseAndBiggerTailQuotedPlus = "big XX blue X X"X $
26 + | headAndTail = Xbig blue $
27 + | headAndTailQuoted = "Xbig blue "
28 + | headAndTailQuotedPlus = "Xbig blue " $
29 + | annotated = big blueX# to be discarded
30 + | annotatedQuoted = "big blue"X# to be discarded
31 + EOF
32 +'
33 +
34 +test_expect_success 'no internal whitespace' '
35 + echo "rock" >expect &&
36 + git config --get section.solid >actual &&
37 + test_cmp expect actual
38 +'
39 +
40 +test_expect_success 'internal whitespace' '
41 + echo "big QQ blue" | q_to_tab >expect &&
42 + git config --get section.sparse >actual &&
43 + test_cmp expect actual
44 +'
45 +
46 +test_expect_success 'internal and trailing whitespace' '
47 + echo "big QQ blue" | q_to_tab >expect &&
48 + git config --get section.sparseAndTail >actual &&
49 + test_cmp expect actual
50 +'
51 +
52 +test_expect_success 'internal and trailing whitespace, all quoted' '
53 + echo "big QQ blue " | q_to_tab >expect &&
54 + git config --get section.sparseAndTailQuoted >actual &&
55 + test_cmp expect actual
56 +'
57 +
58 +test_expect_success 'internal and more trailing whitespace' '
59 + echo "big QQ blue" | q_to_tab >expect &&
60 + git config --get section.sparseAndBiggerTail >actual &&
61 + test_cmp expect actual
62 +'
63 +
64 +test_expect_success 'internal and more trailing whitespace, all quoted' '
65 + echo "big QQ blue Q Q" | q_to_tab >expect &&
66 + git config --get section.sparseAndBiggerTailQuoted >actual &&
67 + test_cmp expect actual
68 +'
69 +
70 +test_expect_success 'internal and more trailing whitespace, not all quoted' '
71 + echo "big QQ blue Q Q" | q_to_tab >expect &&
72 + git config --get section.sparseAndBiggerTailQuotedPlus >actual &&
73 + test_cmp expect actual
74 +'
75 +
76 +test_expect_success 'leading and trailing whitespace' '
77 + echo "big blue" >expect &&
78 + git config --get section.headAndTail >actual &&
79 + test_cmp expect actual
80 +'
81 +
82 +test_expect_success 'leading and trailing whitespace, all quoted' '
83 + echo "Qbig blue " | q_to_tab >expect &&
84 + git config --get section.headAndTailQuoted >actual &&
85 + test_cmp expect actual
86 +'
87 +
88 +test_expect_success 'leading and trailing whitespace, not all quoted' '
89 + echo "Qbig blue " | q_to_tab >expect &&
90 + git config --get section.headAndTailQuotedPlus >actual &&
91 + test_cmp expect actual
92 +'
93 +
94 +test_expect_success 'inline comment' '
95 + echo "big blue" >expect &&
96 + git config --get section.annotated >actual &&
97 + test_cmp expect actual
98 +'
99 +
100 +test_expect_success 'inline comment, quoted' '
101 + echo "big blue" >expect &&
102 + git config --get section.annotatedQuoted >actual &&
103 + test_cmp expect actual
104 +'
105 +
106 test_expect_success 'clear default config' '
107 rm -f .git/config
108 '
@@ -1066,9 +1158,25 @@ test_expect_success '--null --get-regexp' '
1158 test_cmp expect result
1159 '
1160
1069 -test_expect_success 'inner whitespace kept verbatim' '
1070 - git config section.val "foo bar" &&
1071 - test_cmp_config "foo bar" section.val
1161 +test_expect_success 'inner whitespace kept verbatim, spaces only' '
1162 + echo "foo bar" >expect &&
1163 + git config section.val "foo bar" &&
1164 + git config --get section.val >actual &&
1165 + test_cmp expect actual
1166 +'
1167 +
1168 +test_expect_success 'inner whitespace kept verbatim, horizontal tabs only' '
1169 + echo "fooQQbar" | q_to_tab >expect &&
1170 + git config section.val "$(cat expect)" &&
1171 + git config --get section.val >actual &&
1172 + test_cmp expect actual
1173 +'
1174 +
1175 +test_expect_success 'inner whitespace kept verbatim, horizontal tabs and spaces' '
1176 + echo "foo Q bar" | q_to_tab >expect &&
1177 + git config section.val "$(cat expect)" &&
1178 + git config --get section.val >actual &&
1179 + test_cmp expect actual
1180 '
1181
1182 test_expect_success SYMLINKS 'symlinked configuration' '