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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Oct 12, 2011 at 14:29 UTC
5a953fc5d1df1fabb5b8ce9f3c884c424ef4f89a
1 file changed
+93
-83
t/t1300-repo-config.sh
+93
-83
@@ -7,28 +7,28 @@ test_description='Test git config in different settings'
7
8
. ./test-lib.sh
9
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
+'
13
14
cat > expect << EOF
15
[core]
16
penguin = little blue
17
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
+'
22
23
cat > expect << EOF
24
[core]
25
penguin = little blue
26
Movie = BadPhysics
27
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
+'
32
33
cat > expect << EOF
34
[core]
@@ -37,10 +37,10 @@ cat > expect << EOF
37
[Cores]
38
WhatEver = Second
39
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
+'
44
45
cat > expect << EOF
46
[core]
@@ -50,8 +50,10 @@ cat > expect << EOF
50
[Cores]
51
WhatEver = Second
52
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
+'
57
58
test_expect_success 'replace with non-match' \
59
'git config core.penguin kingpin !blue'
@@ -69,7 +71,7 @@ cat > expect << EOF
71
WhatEver = Second
72
EOF
73
72
-test_expect_success 'non-match result' 'cmp .git/config expect'
74
+test_expect_success 'non-match result' 'test_cmp expect .git/config'
75
76
cat > .git/config <<\EOF
77
[alpha]
@@ -88,7 +90,7 @@ bar = foo
90
[beta]
91
EOF
92
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'
94
95
cat > .git/config << EOF
96
[beta] ; silly comment # another comment
@@ -116,7 +118,7 @@ noIndent= sillyValue ; 'nother silly comment
118
[nextSection] noNewline = ouch
119
EOF
120
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'
122
123
cp .git/config2 .git/config
124
@@ -140,9 +142,7 @@ noIndent= sillyValue ; 'nother silly comment
142
[nextSection] noNewline = ouch
143
EOF
144
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'
146
147
cat > expect << EOF
148
[beta] ; silly comment # another comment
@@ -153,10 +153,10 @@ noIndent= sillyValue ; 'nother silly comment
153
haha = alpha
154
[nextSection] noNewline = ouch
155
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
+'
160
161
cat > expect << EOF
162
[beta] ; silly comment # another comment
@@ -168,11 +168,12 @@ noIndent= sillyValue ; 'nother silly comment
168
[nextSection]
169
nonewline = wow
170
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
+'
175
176
test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
175
-git config --unset beta.haha
177
178
cat > expect << EOF
179
[beta] ; silly comment # another comment
@@ -183,10 +184,10 @@ noIndent= sillyValue ; 'nother silly comment
184
[nextSection]
185
nonewline = wow
186
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
+'
191
192
cat > expect << EOF
193
[beta] ; silly comment # another comment
@@ -198,8 +199,10 @@ noIndent= sillyValue ; 'nother silly comment
199
nonewline = wow
200
NoNewLine = wow2 for me
201
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
+'
206
207
test_expect_success 'non-match' \
208
'git config --get nextsection.nonewline !for'
@@ -214,8 +217,6 @@ test_expect_success 'ambiguous get' '
217
test_expect_success 'get multivar' \
218
'git config --get-all nextsection.nonewline'
219
217
-git config nextsection.nonewline "wow3" "wow$"
218
-
220
cat > expect << EOF
221
[beta] ; silly comment # another comment
222
noIndent= sillyValue ; 'nother silly comment
@@ -226,8 +227,10 @@ noIndent= sillyValue ; 'nother silly comment
227
nonewline = wow3
228
NoNewLine = wow2 for me
229
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
+'
234
235
test_expect_success 'ambiguous value' '
236
test_must_fail git config nextsection.nonewline
@@ -241,8 +244,6 @@ test_expect_success 'invalid unset' '
244
test_must_fail git config --unset somesection.nonewline
245
'
246
244
-git config --unset nextsection.nonewline "wow3$"
245
-
247
cat > expect << EOF
248
[beta] ; silly comment # another comment
249
noIndent= sillyValue ; 'nother silly comment
@@ -253,7 +254,10 @@ noIndent= sillyValue ; 'nother silly comment
254
NoNewLine = wow2 for me
255
EOF
256
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
+'
261
262
test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
263
@@ -276,7 +280,7 @@ noIndent= sillyValue ; 'nother silly comment
280
Alpha = beta
281
EOF
282
279
-test_expect_success 'hierarchical section value' 'cmp .git/config expect'
283
+test_expect_success 'hierarchical section value' 'test_cmp expect .git/config'
284
285
cat > expect << EOF
286
beta.noindent=sillyValue
@@ -304,15 +308,16 @@ EOF
308
test_expect_success '--get-regexp' \
309
'git config --get-regexp in > output && cmp output expect'
310
307
-git config --add nextsection.nonewline "wow4 for you"
308
-
311
cat > expect << EOF
312
wow2 for me
313
wow4 for you
314
EOF
315
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
+'
321
322
cat > .git/config << EOF
323
[novalue]
@@ -361,8 +366,6 @@ cat > .git/config << EOF
366
c = d
367
EOF
368
364
-git config a.x y
365
-
369
cat > expect << EOF
370
[a.b]
371
c = d
@@ -370,10 +373,10 @@ cat > expect << EOF
373
x = y
374
EOF
375
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
+'
380
381
cat > expect << EOF
382
[a.b]
@@ -385,7 +388,11 @@ cat > expect << EOF
388
x = y
389
EOF
390
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
+'
396
397
test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
398
'test_must_fail git config --file non-existing-config -l'
@@ -399,9 +406,10 @@ cat > expect << EOF
406
ein.bahn=strasse
407
EOF
408
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
+'
413
414
test_expect_success 'alternative GIT_CONFIG (--file)' \
415
'git config --file other-config -l > output && cmp output expect'
@@ -417,8 +425,6 @@ test_expect_success 'refer config from subdirectory' '
425
426
'
427
420
-GIT_CONFIG=other-config git config anwohner.park ausweis
421
-
428
cat > expect << EOF
429
[ein]
430
bahn = strasse
@@ -426,7 +432,10 @@ cat > expect << EOF
432
park = ausweis
433
EOF
434
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
+'
439
440
cat > .git/config << EOF
441
# Hallo
@@ -531,7 +540,7 @@ test_expect_success 'section ending' '
540
git config gitcvs.enabled true &&
541
git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
542
git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
534
- cmp .git/config expect
543
+ test_cmp expect .git/config
544
545
'
546
@@ -750,13 +759,6 @@ test_expect_success NOT_MINGW 'get --path copes with unset $HOME' '
759
test_cmp expect result
760
'
761
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
-
762
cat > expect << EOF
763
[quote]
764
leading = " test"
@@ -764,8 +766,14 @@ cat > expect << EOF
766
semicolon = "test;test"
767
hash = "test#test"
768
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
+'
777
778
test_expect_success 'key with newline' '
779
test_must_fail git config "key.with
@@ -790,9 +798,10 @@ section.noncont=not continued
798
section.quotecont=cont;inued
799
EOF
800
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
+'
805
806
cat > .git/config <<\EOF
807
[section "sub=section"]
@@ -813,16 +822,17 @@ barQsection.sub=section.val3
822
Qsection.sub=section.val4
823
Qsection.sub=section.val5Q
824
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
+'
830
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
+'
836
837
test_expect_success 'inner whitespace kept verbatim' '
838
git config section.val "foo bar" &&