t1300: style updates

The t1300 test script is quite old, and does not use our modern techniques or styles. This patch updates it in the following ways: 1. Use test_cmp instead of cmp (to make failures easier to debug). 2. Use test_cmp instead of 'test $(command) = expected'. This makes failures much easier to debug, and also makes sure that $(command) exits appropriately. 3. Use test_must_fail (easier to read, and checks more rigorously for signal death). 4. Write tests with the usual style of: test_expect_success 'test name' ' test commands && ... ' rather than one-liners, or using backslash-continuation. This is purely a style fixup. There are still a few command happening outside of test_expect invocations, but they are all innoccuous system commands like "cat" and "cp". In an ideal world, each test would be self sufficient and all commands would happen inside test_expect, but it is not immediately obvious how the grouping should work (some of the commands impact the subsequent tests, and some of them are setting up and modifying state that many tests depend on). This patch just picks the low-hanging style fruit, and we can do more fixes on top later. Signed-off-by: Jeff King <peff@peff.net>

Jeff King committed Oct 23, 2012 at 14:59 UTC ed838e661551958076beda19c9445101da2b70ae
1 file changed +178 -123
t/t1300-repo-config.sh
+178 -123
@@ -55,11 +55,13 @@ test_expect_success 'uppercase section' '
55 test_cmp expect .git/config
56 '
57
58 -test_expect_success 'replace with non-match' \
59 - 'git config core.penguin kingpin !blue'
58 +test_expect_success 'replace with non-match' '
59 + git config core.penguin kingpin !blue
60 +'
61
61 -test_expect_success 'replace with non-match (actually matching)' \
62 - 'git config core.penguin "very blue" !kingpin'
62 +test_expect_success 'replace with non-match (actually matching)' '
63 + git config core.penguin "very blue" !kingpin
64 +'
65
66 cat > expect << EOF
67 [core]
@@ -108,8 +110,9 @@ baz = multiple \
110 lines
111 EOF
112
111 -test_expect_success 'unset with cont. lines' \
112 - 'git config --unset beta.baz'
113 +test_expect_success 'unset with cont. lines' '
114 + git config --unset beta.baz
115 +'
116
117 cat > expect <<\EOF
118 [alpha]
@@ -133,8 +136,9 @@ EOF
136
137 cp .git/config .git/config2
138
136 -test_expect_success 'multiple unset' \
137 - 'git config --unset-all beta.haha'
139 +test_expect_success 'multiple unset' '
140 + git config --unset-all beta.haha
141 +'
142
143 cat > expect << EOF
144 [beta] ; silly comment # another comment
@@ -145,7 +149,9 @@ noIndent= sillyValue ; 'nother silly comment
149 [nextSection] noNewline = ouch
150 EOF
151
148 -test_expect_success 'multiple unset is correct' 'test_cmp expect .git/config'
152 +test_expect_success 'multiple unset is correct' '
153 + test_cmp expect .git/config
154 +'
155
156 cp .git/config2 .git/config
157
@@ -156,8 +162,9 @@ test_expect_success '--replace-all missing value' '
162
163 rm .git/config2
164
159 -test_expect_success '--replace-all' \
160 - 'git config --replace-all beta.haha gamma'
165 +test_expect_success '--replace-all' '
166 + git config --replace-all beta.haha gamma
167 +'
168
169 cat > expect << EOF
170 [beta] ; silly comment # another comment
@@ -169,7 +176,9 @@ noIndent= sillyValue ; 'nother silly comment
176 [nextSection] noNewline = ouch
177 EOF
178
172 -test_expect_success 'all replaced' 'test_cmp expect .git/config'
179 +test_expect_success 'all replaced' '
180 + test_cmp expect .git/config
181 +'
182
183 cat > expect << EOF
184 [beta] ; silly comment # another comment
@@ -200,7 +209,11 @@ test_expect_success 'really really mean test' '
209 test_cmp expect .git/config
210 '
211
203 -test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
212 +test_expect_success 'get value' '
213 + echo alpha >expect &&
214 + git config beta.haha >actual &&
215 + test_cmp expect actual
216 +'
217
218 cat > expect << EOF
219 [beta] ; silly comment # another comment
@@ -231,18 +244,23 @@ test_expect_success 'multivar' '
244 test_cmp expect .git/config
245 '
246
234 -test_expect_success 'non-match' \
235 - 'git config --get nextsection.nonewline !for'
247 +test_expect_success 'non-match' '
248 + git config --get nextsection.nonewline !for
249 +'
250
237 -test_expect_success 'non-match value' \
238 - 'test wow = $(git config --get nextsection.nonewline !for)'
251 +test_expect_success 'non-match value' '
252 + echo wow >expect &&
253 + git config --get nextsection.nonewline !for >actual &&
254 + test_cmp expect actual
255 +'
256
257 test_expect_success 'ambiguous get' '
258 test_must_fail git config --get nextsection.nonewline
259 '
260
244 -test_expect_success 'get multivar' \
245 - 'git config --get-all nextsection.nonewline'
261 +test_expect_success 'get multivar' '
262 + git config --get-all nextsection.nonewline
263 +'
264
265 cat > expect << EOF
266 [beta] ; silly comment # another comment
@@ -290,8 +308,9 @@ test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
308
309 test_expect_success 'correct key' 'git config 123456.a123 987'
310
293 -test_expect_success 'hierarchical section' \
294 - 'git config Version.1.2.3eX.Alpha beta'
311 +test_expect_success 'hierarchical section' '
312 + git config Version.1.2.3eX.Alpha beta
313 +'
314
315 cat > expect << EOF
316 [beta] ; silly comment # another comment
@@ -307,7 +326,9 @@ noIndent= sillyValue ; 'nother silly comment
326 Alpha = beta
327 EOF
328
310 -test_expect_success 'hierarchical section value' 'test_cmp expect .git/config'
329 +test_expect_success 'hierarchical section value' '
330 + test_cmp expect .git/config
331 +'
332
333 cat > expect << EOF
334 beta.noindent=sillyValue
@@ -316,9 +337,10 @@ nextsection.nonewline=wow2 for me
337 version.1.2.3eX.alpha=beta
338 EOF
339
319 -test_expect_success 'working --list' \
320 - 'git config --list > output && cmp output expect'
321 -
340 +test_expect_success 'working --list' '
341 + git config --list > output &&
342 + test_cmp expect output
343 +'
344 cat > expect << EOF
345 EOF
346
@@ -332,8 +354,10 @@ beta.noindent sillyValue
354 nextsection.nonewline wow2 for me
355 EOF
356
335 -test_expect_success '--get-regexp' \
336 - 'git config --get-regexp in > output && cmp output expect'
357 +test_expect_success '--get-regexp' '
358 + git config --get-regexp in >output &&
359 + test_cmp expect output
360 +'
361
362 cat > expect << EOF
363 wow2 for me
@@ -353,41 +377,48 @@ cat > .git/config << EOF
377 variable =
378 EOF
379
356 -test_expect_success 'get variable with no value' \
357 - 'git config --get novalue.variable ^$'
380 +test_expect_success 'get variable with no value' '
381 + git config --get novalue.variable ^$
382 +'
383
359 -test_expect_success 'get variable with empty value' \
360 - 'git config --get emptyvalue.variable ^$'
384 +test_expect_success 'get variable with empty value' '
385 + git config --get emptyvalue.variable ^$
386 +'
387
388 echo novalue.variable > expect
389
364 -test_expect_success 'get-regexp variable with no value' \
365 - 'git config --get-regexp novalue > output &&
366 - cmp output expect'
390 +test_expect_success 'get-regexp variable with no value' '
391 + git config --get-regexp novalue > output &&
392 + test_cmp expect output
393 +'
394
395 echo 'novalue.variable true' > expect
396
370 -test_expect_success 'get-regexp --bool variable with no value' \
371 - 'git config --bool --get-regexp novalue > output &&
372 - cmp output expect'
397 +test_expect_success 'get-regexp --bool variable with no value' '
398 + git config --bool --get-regexp novalue > output &&
399 + test_cmp expect output
400 +'
401
402 echo 'emptyvalue.variable ' > expect
403
376 -test_expect_success 'get-regexp variable with empty value' \
377 - 'git config --get-regexp emptyvalue > output &&
378 - cmp output expect'
404 +test_expect_success 'get-regexp variable with empty value' '
405 + git config --get-regexp emptyvalue > output &&
406 + test_cmp expect output
407 +'
408
409 echo true > expect
410
382 -test_expect_success 'get bool variable with no value' \
383 - 'git config --bool novalue.variable > output &&
384 - cmp output expect'
411 +test_expect_success 'get bool variable with no value' '
412 + git config --bool novalue.variable > output &&
413 + test_cmp expect output
414 +'
415
416 echo false > expect
417
388 -test_expect_success 'get bool variable with empty value' \
389 - 'git config --bool emptyvalue.variable > output &&
390 - cmp output expect'
418 +test_expect_success 'get bool variable with empty value' '
419 + git config --bool emptyvalue.variable > output &&
420 + test_cmp expect output
421 +'
422
423 test_expect_success 'no arguments, but no crash' '
424 test_must_fail git config >output 2>&1 &&
@@ -427,8 +458,9 @@ test_expect_success 'new variable inserts into proper section' '
458 test_cmp expect .git/config
459 '
460
430 -test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
431 - 'test_must_fail git config --file non-existing-config -l'
461 +test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' '
462 + test_must_fail git config --file non-existing-config -l
463 +'
464
465 cat > other-config << EOF
466 [ein]
@@ -444,8 +476,10 @@ test_expect_success 'alternative GIT_CONFIG' '
476 test_cmp expect output
477 '
478
447 -test_expect_success 'alternative GIT_CONFIG (--file)' \
448 - 'git config --file other-config -l > output && cmp output expect'
479 +test_expect_success 'alternative GIT_CONFIG (--file)' '
480 + git config --file other-config -l > output &&
481 + test_cmp expect output
482 +'
483
484 test_expect_success 'refer config from subdirectory' '
485 mkdir x &&
@@ -489,8 +523,9 @@ cat > .git/config << EOF
523 weird
524 EOF
525
492 -test_expect_success "rename section" \
493 - "git config --rename-section branch.eins branch.zwei"
526 +test_expect_success 'rename section' '
527 + git config --rename-section branch.eins branch.zwei
528 +'
529
530 cat > expect << EOF
531 # Hallo
@@ -503,17 +538,22 @@ cat > expect << EOF
538 weird
539 EOF
540
506 -test_expect_success "rename succeeded" "test_cmp expect .git/config"
541 +test_expect_success 'rename succeeded' '
542 + test_cmp expect .git/config
543 +'
544
508 -test_expect_success "rename non-existing section" '
545 +test_expect_success 'rename non-existing section' '
546 test_must_fail git config --rename-section \
547 branch."world domination" branch.drei
548 '
549
513 -test_expect_success "rename succeeded" "test_cmp expect .git/config"
550 +test_expect_success 'rename succeeded' '
551 + test_cmp expect .git/config
552 +'
553
515 -test_expect_success "rename another section" \
516 - 'git config --rename-section branch."1 234 blabl/a" branch.drei'
554 +test_expect_success 'rename another section' '
555 + git config --rename-section branch."1 234 blabl/a" branch.drei
556 +'
557
558 cat > expect << EOF
559 # Hallo
@@ -526,14 +566,17 @@ cat > expect << EOF
566 weird
567 EOF
568
529 -test_expect_success "rename succeeded" "test_cmp expect .git/config"
569 +test_expect_success 'rename succeeded' '
570 + test_cmp expect .git/config
571 +'
572
573 cat >> .git/config << EOF
574 [branch "vier"] z = 1
575 EOF
576
535 -test_expect_success "rename a section with a var on the same line" \
536 - 'git config --rename-section branch.vier branch.zwei'
577 +test_expect_success 'rename a section with a var on the same line' '
578 + git config --rename-section branch.vier branch.zwei
579 +'
580
581 cat > expect << EOF
582 # Hallo
@@ -548,7 +591,9 @@ weird
591 z = 1
592 EOF
593
551 -test_expect_success "rename succeeded" "test_cmp expect .git/config"
594 +test_expect_success 'rename succeeded' '
595 + test_cmp expect .git/config
596 +'
597
598 test_expect_success 'renaming empty section name is rejected' '
599 test_must_fail git config --rename-section branch.zwei ""
@@ -562,7 +607,9 @@ cat >> .git/config << EOF
607 [branch "zwei"] a = 1 [branch "vier"]
608 EOF
609
565 -test_expect_success "remove section" "git config --remove-section branch.zwei"
610 +test_expect_success 'remove section' '
611 + git config --remove-section branch.zwei
612 +'
613
614 cat > expect << EOF
615 # Hallo
@@ -571,8 +618,9 @@ cat > expect << EOF
618 weird
619 EOF
620
574 -test_expect_success "section was removed properly" \
575 - "test_cmp expect .git/config"
621 +test_expect_success 'section was removed properly' '
622 + test_cmp expect .git/config
623 +'
624
625 cat > expect << EOF
626 [gitcvs]
@@ -583,7 +631,6 @@ cat > expect << EOF
631 EOF
632
633 test_expect_success 'section ending' '
586 -
634 rm -f .git/config &&
635 git config gitcvs.enabled true &&
636 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
@@ -593,30 +640,25 @@ test_expect_success 'section ending' '
640 '
641
642 test_expect_success numbers '
596 -
643 git config kilo.gram 1k &&
644 git config mega.ton 1m &&
599 - k=$(git config --int --get kilo.gram) &&
600 - test z1024 = "z$k" &&
601 - m=$(git config --int --get mega.ton) &&
602 - test z1048576 = "z$m"
645 + echo 1024 >expect &&
646 + echo 1048576 >>expect &&
647 + git config --int --get kilo.gram >actual &&
648 + git config --int --get mega.ton >>actual &&
649 + test_cmp expect actual
650 '
651
605 -cat > expect <<EOF
606 -fatal: bad config value for 'aninvalid.unit' in .git/config
607 -EOF
608 -
652 test_expect_success 'invalid unit' '
610 -
653 git config aninvalid.unit "1auto" &&
612 - s=$(git config aninvalid.unit) &&
613 - test "z1auto" = "z$s" &&
614 - if git config --int --get aninvalid.unit 2>actual
615 - then
616 - echo config should have failed
617 - false
618 - fi &&
619 - cmp actual expect
654 + echo 1auto >expect &&
655 + git config aninvalid.unit >actual &&
656 + test_cmp expect actual &&
657 + cat > expect <<-\EOF
658 + fatal: bad config value for '\''aninvalid.unit'\'' in .git/config
659 + EOF
660 + test_must_fail git config --int --get aninvalid.unit 2>actual &&
661 + test_cmp actual expect
662 '
663
664 cat > expect << EOF
@@ -646,7 +688,7 @@ test_expect_success bool '
688 git config --bool --get bool.true$i >>result
689 git config --bool --get bool.false$i >>result
690 done &&
649 - cmp expect result'
691 + test_cmp expect result'
692
693 test_expect_success 'invalid bool (--get)' '
694
@@ -680,7 +722,7 @@ test_expect_success 'set --bool' '
722 git config --bool bool.false2 "" &&
723 git config --bool bool.false3 nO &&
724 git config --bool bool.false4 FALSE &&
683 - cmp expect .git/config'
725 + test_cmp expect .git/config'
726
727 cat > expect <<\EOF
728 [int]
@@ -695,39 +737,37 @@ test_expect_success 'set --int' '
737 git config --int int.val1 01 &&
738 git config --int int.val2 -1 &&
739 git config --int int.val3 5m &&
698 - cmp expect .git/config'
740 + test_cmp expect .git/config
741 +'
742
700 -cat >expect <<\EOF
701 -[bool]
702 - true1 = true
743 +test_expect_success 'get --bool-or-int' '
744 + cat >.git/config <<-\EOF &&
745 + [bool]
746 + true1
747 true2 = true
704 - false1 = false
705 - false2 = false
706 -[int]
748 + false = false
749 + [int]
750 int1 = 0
751 int2 = 1
752 int3 = -1
710 -EOF
711 -
712 -test_expect_success 'get --bool-or-int' '
713 - rm -f .git/config &&
714 - (
715 - echo "[bool]"
716 - echo true1
717 - echo true2 = true
718 - echo false = false
719 - echo "[int]"
720 - echo int1 = 0
721 - echo int2 = 1
722 - echo int3 = -1
723 - ) >>.git/config &&
724 - test $(git config --bool-or-int bool.true1) = true &&
725 - test $(git config --bool-or-int bool.true2) = true &&
726 - test $(git config --bool-or-int bool.false) = false &&
727 - test $(git config --bool-or-int int.int1) = 0 &&
728 - test $(git config --bool-or-int int.int2) = 1 &&
729 - test $(git config --bool-or-int int.int3) = -1
730 -
753 + EOF
754 + cat >expect <<-\EOF &&
755 + true
756 + true
757 + false
758 + 0
759 + 1
760 + -1
761 + EOF
762 + {
763 + git config --bool-or-int bool.true1 &&
764 + git config --bool-or-int bool.true2 &&
765 + git config --bool-or-int bool.false &&
766 + git config --bool-or-int int.int1 &&
767 + git config --bool-or-int int.int2 &&
768 + git config --bool-or-int int.int3
769 + } >actual &&
770 + test_cmp expect actual
771 '
772
773 cat >expect <<\EOF
@@ -844,7 +884,7 @@ EOF
884
885 test_expect_success 'value continued on next line' '
886 git config --list > result &&
847 - cmp result expect
887 + test_cmp result expect
888 '
889
890 cat > .git/config <<\EOF
@@ -880,11 +920,12 @@ test_expect_success '--null --get-regexp' '
920
921 test_expect_success 'inner whitespace kept verbatim' '
922 git config section.val "foo bar" &&
883 - test "z$(git config section.val)" = "zfoo bar"
923 + echo "foo bar" >expect &&
924 + git config section.val >actual &&
925 + test_cmp expect actual
926 '
927
928 test_expect_success SYMLINKS 'symlinked configuration' '
887 -
929 ln -s notyet myconfig &&
930 GIT_CONFIG=myconfig git config test.frotz nitfol &&
931 test -h myconfig &&
@@ -893,9 +934,15 @@ test_expect_success SYMLINKS 'symlinked configuration' '
934 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
935 test -h myconfig &&
936 test -f notyet &&
896 - test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
897 - test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
898 -
937 + cat >expect <<-\EOF &&
938 + nitfol
939 + rezrov
940 + EOF
941 + {
942 + GIT_CONFIG=notyet git config test.frotz &&
943 + GIT_CONFIG=notyet git config test.xyzzy
944 + } >actual &&
945 + test_cmp expect actual
946 '
947
948 test_expect_success 'nonexistent configuration' '
@@ -927,12 +974,20 @@ test_expect_success 'check split_cmdline return' "
974 git commit -m 'initial commit' &&
975 git config branch.master.mergeoptions 'echo \"' &&
976 test_must_fail git merge master
930 - "
977 +"
978
979 test_expect_success 'git -c "key=value" support' '
933 - test "z$(git -c core.name=value config core.name)" = zvalue &&
934 - test "z$(git -c foo.CamelCase=value config foo.camelcase)" = zvalue &&
935 - test "z$(git -c foo.flag config --bool foo.flag)" = ztrue &&
980 + cat >expect <<-\EOF &&
981 + value
982 + value
983 + true
984 + EOF
985 + {
986 + git -c core.name=value config core.name &&
987 + git -c foo.CamelCase=value config foo.camelcase &&
988 + git -c foo.flag config --bool foo.flag
989 + } >actual &&
990 + test_cmp expect actual &&
991 test_must_fail git -c name=value config core.name
992 '
993