Skip to content

Commit 5a953fc

Browse files
peffgitster
authored andcommitted
t1300: put git invocations inside test function
This is a very old script, and did a lot of: echo whatever >expect git config foo bar test_expect_success 'cmp .git/config expect' which meant that we didn't actually check that the call to git-config succeeded. Fix this, and while we're at it, modernize the style to use test_cmp. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 703f05a commit 5a953fc

File tree

1 file changed

+93
-83
lines changed

1 file changed

+93
-83
lines changed

t/t1300-repo-config.sh

Lines changed: 93 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ test_description='Test git config in different settings'
77

88
. ./test-lib.sh
99

10-
test -f .git/config && rm .git/config
11-
12-
git config core.penguin "little blue"
10+
test_expect_success 'clear default config' '
11+
rm -f .git/config
12+
'
1313

1414
cat > expect << EOF
1515
[core]
1616
penguin = little blue
1717
EOF
18-
19-
test_expect_success 'initial' 'cmp .git/config expect'
20-
21-
git config Core.Movie BadPhysics
18+
test_expect_success 'initial' '
19+
git config core.penguin "little blue" &&
20+
test_cmp expect .git/config
21+
'
2222

2323
cat > expect << EOF
2424
[core]
2525
penguin = little blue
2626
Movie = BadPhysics
2727
EOF
28-
29-
test_expect_success 'mixed case' 'cmp .git/config expect'
30-
31-
git config Cores.WhatEver Second
28+
test_expect_success 'mixed case' '
29+
git config Core.Movie BadPhysics &&
30+
test_cmp expect .git/config
31+
'
3232

3333
cat > expect << EOF
3434
[core]
@@ -37,10 +37,10 @@ cat > expect << EOF
3737
[Cores]
3838
WhatEver = Second
3939
EOF
40-
41-
test_expect_success 'similar section' 'cmp .git/config expect'
42-
43-
git config CORE.UPPERCASE true
40+
test_expect_success 'similar section' '
41+
git config Cores.WhatEver Second
42+
test_cmp expect .git/config
43+
'
4444

4545
cat > expect << EOF
4646
[core]
@@ -50,8 +50,10 @@ cat > expect << EOF
5050
[Cores]
5151
WhatEver = Second
5252
EOF
53-
54-
test_expect_success 'similar section' 'cmp .git/config expect'
53+
test_expect_success 'uppercase section' '
54+
git config CORE.UPPERCASE true &&
55+
test_cmp expect .git/config
56+
'
5557

5658
test_expect_success 'replace with non-match' \
5759
'git config core.penguin kingpin !blue'
@@ -69,7 +71,7 @@ cat > expect << EOF
6971
WhatEver = Second
7072
EOF
7173

72-
test_expect_success 'non-match result' 'cmp .git/config expect'
74+
test_expect_success 'non-match result' 'test_cmp expect .git/config'
7375

7476
cat > .git/config <<\EOF
7577
[alpha]
@@ -88,7 +90,7 @@ bar = foo
8890
[beta]
8991
EOF
9092

91-
test_expect_success 'unset with cont. lines is correct' 'cmp .git/config expect'
93+
test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
9294

9395
cat > .git/config << EOF
9496
[beta] ; silly comment # another comment
@@ -116,7 +118,7 @@ noIndent= sillyValue ; 'nother silly comment
116118
[nextSection] noNewline = ouch
117119
EOF
118120

119-
test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
121+
test_expect_success 'multiple unset is correct' 'test_cmp expect .git/config'
120122

121123
cp .git/config2 .git/config
122124

@@ -140,9 +142,7 @@ noIndent= sillyValue ; 'nother silly comment
140142
[nextSection] noNewline = ouch
141143
EOF
142144

143-
test_expect_success 'all replaced' 'cmp .git/config expect'
144-
145-
git config beta.haha alpha
145+
test_expect_success 'all replaced' 'test_cmp expect .git/config'
146146

147147
cat > expect << EOF
148148
[beta] ; silly comment # another comment
@@ -153,10 +153,10 @@ noIndent= sillyValue ; 'nother silly comment
153153
haha = alpha
154154
[nextSection] noNewline = ouch
155155
EOF
156-
157-
test_expect_success 'really mean test' 'cmp .git/config expect'
158-
159-
git config nextsection.nonewline wow
156+
test_expect_success 'really mean test' '
157+
git config beta.haha alpha &&
158+
test_cmp expect .git/config
159+
'
160160

161161
cat > expect << EOF
162162
[beta] ; silly comment # another comment
@@ -168,11 +168,12 @@ noIndent= sillyValue ; 'nother silly comment
168168
[nextSection]
169169
nonewline = wow
170170
EOF
171-
172-
test_expect_success 'really really mean test' 'cmp .git/config expect'
171+
test_expect_success 'really really mean test' '
172+
git config nextsection.nonewline wow &&
173+
test_cmp expect .git/config
174+
'
173175

174176
test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
175-
git config --unset beta.haha
176177

177178
cat > expect << EOF
178179
[beta] ; silly comment # another comment
@@ -183,10 +184,10 @@ noIndent= sillyValue ; 'nother silly comment
183184
[nextSection]
184185
nonewline = wow
185186
EOF
186-
187-
test_expect_success 'unset' 'cmp .git/config expect'
188-
189-
git config nextsection.NoNewLine "wow2 for me" "for me$"
187+
test_expect_success 'unset' '
188+
git config --unset beta.haha &&
189+
test_cmp expect .git/config
190+
'
190191

191192
cat > expect << EOF
192193
[beta] ; silly comment # another comment
@@ -198,8 +199,10 @@ noIndent= sillyValue ; 'nother silly comment
198199
nonewline = wow
199200
NoNewLine = wow2 for me
200201
EOF
201-
202-
test_expect_success 'multivar' 'cmp .git/config expect'
202+
test_expect_success 'multivar' '
203+
git config nextsection.NoNewLine "wow2 for me" "for me$" &&
204+
test_cmp expect .git/config
205+
'
203206

204207
test_expect_success 'non-match' \
205208
'git config --get nextsection.nonewline !for'
@@ -214,8 +217,6 @@ test_expect_success 'ambiguous get' '
214217
test_expect_success 'get multivar' \
215218
'git config --get-all nextsection.nonewline'
216219

217-
git config nextsection.nonewline "wow3" "wow$"
218-
219220
cat > expect << EOF
220221
[beta] ; silly comment # another comment
221222
noIndent= sillyValue ; 'nother silly comment
@@ -226,8 +227,10 @@ noIndent= sillyValue ; 'nother silly comment
226227
nonewline = wow3
227228
NoNewLine = wow2 for me
228229
EOF
229-
230-
test_expect_success 'multivar replace' 'cmp .git/config expect'
230+
test_expect_success 'multivar replace' '
231+
git config nextsection.nonewline "wow3" "wow$" &&
232+
test_cmp expect .git/config
233+
'
231234

232235
test_expect_success 'ambiguous value' '
233236
test_must_fail git config nextsection.nonewline
@@ -241,8 +244,6 @@ test_expect_success 'invalid unset' '
241244
test_must_fail git config --unset somesection.nonewline
242245
'
243246

244-
git config --unset nextsection.nonewline "wow3$"
245-
246247
cat > expect << EOF
247248
[beta] ; silly comment # another comment
248249
noIndent= sillyValue ; 'nother silly comment
@@ -253,7 +254,10 @@ noIndent= sillyValue ; 'nother silly comment
253254
NoNewLine = wow2 for me
254255
EOF
255256

256-
test_expect_success 'multivar unset' 'cmp .git/config expect'
257+
test_expect_success 'multivar unset' '
258+
git config --unset nextsection.nonewline "wow3$" &&
259+
test_cmp expect .git/config
260+
'
257261

258262
test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
259263

@@ -276,7 +280,7 @@ noIndent= sillyValue ; 'nother silly comment
276280
Alpha = beta
277281
EOF
278282

279-
test_expect_success 'hierarchical section value' 'cmp .git/config expect'
283+
test_expect_success 'hierarchical section value' 'test_cmp expect .git/config'
280284

281285
cat > expect << EOF
282286
beta.noindent=sillyValue
@@ -304,15 +308,16 @@ EOF
304308
test_expect_success '--get-regexp' \
305309
'git config --get-regexp in > output && cmp output expect'
306310

307-
git config --add nextsection.nonewline "wow4 for you"
308-
309311
cat > expect << EOF
310312
wow2 for me
311313
wow4 for you
312314
EOF
313315

314-
test_expect_success '--add' \
315-
'git config --get-all nextsection.nonewline > output && cmp output expect'
316+
test_expect_success '--add' '
317+
git config --add nextsection.nonewline "wow4 for you" &&
318+
git config --get-all nextsection.nonewline > output &&
319+
test_cmp expect output
320+
'
316321

317322
cat > .git/config << EOF
318323
[novalue]
@@ -361,19 +366,17 @@ cat > .git/config << EOF
361366
c = d
362367
EOF
363368

364-
git config a.x y
365-
366369
cat > expect << EOF
367370
[a.b]
368371
c = d
369372
[a]
370373
x = y
371374
EOF
372375

373-
test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
374-
375-
git config b.x y
376-
git config a.b c
376+
test_expect_success 'new section is partial match of another' '
377+
git config a.x y &&
378+
test_cmp expect .git/config
379+
'
377380

378381
cat > expect << EOF
379382
[a.b]
@@ -385,7 +388,11 @@ cat > expect << EOF
385388
x = y
386389
EOF
387390

388-
test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
391+
test_expect_success 'new variable inserts into proper section' '
392+
git config b.x y &&
393+
git config a.b c &&
394+
test_cmp expect .git/config
395+
'
389396

390397
test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
391398
'test_must_fail git config --file non-existing-config -l'
@@ -399,9 +406,10 @@ cat > expect << EOF
399406
ein.bahn=strasse
400407
EOF
401408

402-
GIT_CONFIG=other-config git config -l > output
403-
404-
test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
409+
test_expect_success 'alternative GIT_CONFIG' '
410+
GIT_CONFIG=other-config git config -l >output &&
411+
test_cmp expect output
412+
'
405413

406414
test_expect_success 'alternative GIT_CONFIG (--file)' \
407415
'git config --file other-config -l > output && cmp output expect'
@@ -417,16 +425,17 @@ test_expect_success 'refer config from subdirectory' '
417425
418426
'
419427

420-
GIT_CONFIG=other-config git config anwohner.park ausweis
421-
422428
cat > expect << EOF
423429
[ein]
424430
bahn = strasse
425431
[anwohner]
426432
park = ausweis
427433
EOF
428434

429-
test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
435+
test_expect_success '--set in alternative GIT_CONFIG' '
436+
GIT_CONFIG=other-config git config anwohner.park ausweis &&
437+
test_cmp expect other-config
438+
'
430439

431440
cat > .git/config << EOF
432441
# Hallo
@@ -531,7 +540,7 @@ test_expect_success 'section ending' '
531540
git config gitcvs.enabled true &&
532541
git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
533542
git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
534-
cmp .git/config expect
543+
test_cmp expect .git/config
535544
536545
'
537546

@@ -750,22 +759,21 @@ test_expect_success NOT_MINGW 'get --path copes with unset $HOME' '
750759
test_cmp expect result
751760
'
752761

753-
rm .git/config
754-
755-
git config quote.leading " test"
756-
git config quote.ending "test "
757-
git config quote.semicolon "test;test"
758-
git config quote.hash "test#test"
759-
760762
cat > expect << EOF
761763
[quote]
762764
leading = " test"
763765
ending = "test "
764766
semicolon = "test;test"
765767
hash = "test#test"
766768
EOF
767-
768-
test_expect_success 'quoting' 'cmp .git/config expect'
769+
test_expect_success 'quoting' '
770+
rm .git/config &&
771+
git config quote.leading " test" &&
772+
git config quote.ending "test " &&
773+
git config quote.semicolon "test;test" &&
774+
git config quote.hash "test#test" &&
775+
test_cmp expect .git/config
776+
'
769777

770778
test_expect_success 'key with newline' '
771779
test_must_fail git config "key.with
@@ -790,9 +798,10 @@ section.noncont=not continued
790798
section.quotecont=cont;inued
791799
EOF
792800

793-
git config --list > result
794-
795-
test_expect_success 'value continued on next line' 'cmp result expect'
801+
test_expect_success 'value continued on next line' '
802+
git config --list > result &&
803+
cmp result expect
804+
'
796805

797806
cat > .git/config <<\EOF
798807
[section "sub=section"]
@@ -813,16 +822,17 @@ barQsection.sub=section.val3
813822
Qsection.sub=section.val4
814823
Qsection.sub=section.val5Q
815824
EOF
825+
test_expect_success '--null --list' '
826+
git config --null --list | nul_to_q >result &&
827+
echo >>result &&
828+
test_cmp expect result
829+
'
816830

817-
git config --null --list | perl -pe 'y/\000/Q/' > result
818-
echo >>result
819-
820-
test_expect_success '--null --list' 'cmp result expect'
821-
822-
git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result
823-
echo >>result
824-
825-
test_expect_success '--null --get-regexp' 'cmp result expect'
831+
test_expect_success '--null --get-regexp' '
832+
git config --null --get-regexp "val[0-9]" | nul_to_q >result &&
833+
echo >>result &&
834+
test_cmp expect result
835+
'
826836

827837
test_expect_success 'inner whitespace kept verbatim' '
828838
git config section.val "foo bar" &&

0 commit comments

Comments
 (0)