t1300: write test expectations in the test's body

There are a bunch of tests in t1300 where we write the test expectation handed over to `test_cmp ()` outside of the test body. This does not match our modern test style, and there isn't really a reason why this would need to happen outside of the test bodies. Convert those to instead do so as part of the test itself. While at it, normalize these tests to use `<<\EOF` for those that don't use variable expansion and `<<-EOF` for those that aren't sensitive to indentation. Note that there are two exceptions that we leave as-is for now since they are reused across tests. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Sep 22, 2025 at 15:06 UTC f1371a3c9511361d3aedf37f833981113a3b19d8
1 file changed +128 -163
t/t1300-config.sh
+128 -163
@@ -134,38 +134,39 @@ test_expect_success 'clear default config' '
134 rm -f .git/config
135 '
136
137 -cat > expect << EOF
137 +test_expect_success 'initial' '
138 + cat >expect <<\EOF &&
139 [section]
140 penguin = little blue
141 EOF
141 -test_expect_success 'initial' '
142 git config ${mode_set} section.penguin "little blue" &&
143 test_cmp expect .git/config
144 '
145
146 -cat > expect << EOF
146 +test_expect_success 'mixed case' '
147 + cat >expect <<\EOF &&
148 [section]
149 penguin = little blue
150 Movie = BadPhysics
151 EOF
151 -test_expect_success 'mixed case' '
152 git config ${mode_set} Section.Movie BadPhysics &&
153 test_cmp expect .git/config
154 '
155
156 -cat > expect << EOF
156 +test_expect_success 'similar section' '
157 + cat >expect <<\EOF &&
158 [section]
159 penguin = little blue
160 Movie = BadPhysics
161 [Sections]
162 WhatEver = Second
163 EOF
163 -test_expect_success 'similar section' '
164 git config ${mode_set} Sections.WhatEver Second &&
165 test_cmp expect .git/config
166 '
167
168 -cat > expect << EOF
168 +test_expect_success 'uppercase section' '
169 + cat >expect <<\EOF &&
170 [section]
171 penguin = little blue
172 Movie = BadPhysics
@@ -173,7 +174,6 @@ cat > expect << EOF
174 [Sections]
175 WhatEver = Second
176 EOF
176 -test_expect_success 'uppercase section' '
177 git config ${mode_set} SECTION.UPPERCASE true &&
178 test_cmp expect .git/config
179 '
@@ -186,7 +186,8 @@ test_expect_success 'replace with non-match (actually matching)' '
186 git config section.penguin "very blue" !kingpin
187 '
188
189 -cat > expect << EOF
189 +test_expect_success 'append comments' '
190 + cat >expect <<\EOF &&
191 [section]
192 Movie = BadPhysics
193 UPPERCASE = true
@@ -198,8 +199,6 @@ cat > expect << EOF
199 [Sections]
200 WhatEver = Second
201 EOF
201 -
202 -test_expect_success 'append comments' '
202 git config --replace-all --comment="Pygoscelis papua" section.penguin gentoo &&
203 git config ${mode_set} --comment="find fish" section.disposition peckish &&
204 git config ${mode_set} --comment="#abc" section.foo bar &&
@@ -265,14 +264,15 @@ test_expect_success 'unset with cont. lines' '
264 git config ${mode_unset} beta.baz
265 '
266
268 -cat > expect <<\EOF
269 -[alpha]
270 -bar = foo
271 -[beta]
272 -foo = bar
273 -EOF
274 -
275 -test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
267 +test_expect_success 'unset with cont. lines is correct' '
268 + cat >expect <<-\EOF &&
269 + [alpha]
270 + bar = foo
271 + [beta]
272 + foo = bar
273 + EOF
274 + test_cmp expect .git/config
275 +'
276
277 cat > .git/config << EOF
278 [beta] ; silly comment # another comment
@@ -292,16 +292,15 @@ test_expect_success 'multiple unset' '
292 git config ${mode_unset_all} beta.haha
293 '
294
295 -cat > expect << EOF
295 +test_expect_success 'multiple unset is correct' '
296 + cat >expect <<EOF &&
297 [beta] ; silly comment # another comment
297 -noIndent= sillyValue ; 'nother silly comment
298 +noIndent= sillyValue ; ${SQ}nother silly comment
299
300 # empty line
301 ; comment
302 [nextSection] noNewline = ouch
303 EOF
303 -
304 -test_expect_success 'multiple unset is correct' '
304 test_cmp expect .git/config
305 '
306
@@ -318,37 +317,37 @@ test_expect_success '--replace-all' '
317 git config ${mode_replace_all} beta.haha gamma
318 '
319
321 -cat > expect << EOF
320 +test_expect_success 'all replaced' '
321 + cat >expect <<EOF &&
322 [beta] ; silly comment # another comment
323 -noIndent= sillyValue ; 'nother silly comment
323 +noIndent= sillyValue ; ${SQ}nother silly comment
324
325 # empty line
326 ; comment
327 haha = gamma
328 [nextSection] noNewline = ouch
329 EOF
330 -
331 -test_expect_success 'all replaced' '
330 test_cmp expect .git/config
331 '
332
335 -cat > expect << EOF
333 +test_expect_success 'really mean test' '
334 + cat >expect <<EOF &&
335 [beta] ; silly comment # another comment
337 -noIndent= sillyValue ; 'nother silly comment
336 +noIndent= sillyValue ; ${SQ}nother silly comment
337
338 # empty line
339 ; comment
340 haha = alpha
341 [nextSection] noNewline = ouch
342 EOF
344 -test_expect_success 'really mean test' '
343 git config ${mode_set} beta.haha alpha &&
344 test_cmp expect .git/config
345 '
346
349 -cat > expect << EOF
347 +test_expect_success 'really really mean test' '
348 + cat >expect <<EOF &&
349 [beta] ; silly comment # another comment
351 -noIndent= sillyValue ; 'nother silly comment
350 +noIndent= sillyValue ; ${SQ}nother silly comment
351
352 # empty line
353 ; comment
@@ -356,7 +355,6 @@ noIndent= sillyValue ; 'nother silly comment
355 [nextSection]
356 nonewline = wow
357 EOF
359 -test_expect_success 'really really mean test' '
358 git config ${mode_set} nextsection.nonewline wow &&
359 test_cmp expect .git/config
360 '
@@ -365,23 +363,24 @@ test_expect_success 'get value' '
363 test_cmp_config alpha beta.haha
364 '
365
368 -cat > expect << EOF
366 +test_expect_success 'unset' '
367 + cat >expect <<EOF &&
368 [beta] ; silly comment # another comment
370 -noIndent= sillyValue ; 'nother silly comment
369 +noIndent= sillyValue ; ${SQ}nother silly comment
370
371 # empty line
372 ; comment
373 [nextSection]
374 nonewline = wow
375 EOF
377 -test_expect_success 'unset' '
376 git config ${mode_unset} beta.haha &&
377 test_cmp expect .git/config
378 '
379
382 -cat > expect << EOF
380 +test_expect_success 'multivar' '
381 + cat >expect <<EOF &&
382 [beta] ; silly comment # another comment
384 -noIndent= sillyValue ; 'nother silly comment
383 +noIndent= sillyValue ; ${SQ}nother silly comment
384
385 # empty line
386 ; comment
@@ -389,7 +388,6 @@ noIndent= sillyValue ; 'nother silly comment
388 nonewline = wow
389 NoNewLine = wow2 for me
390 EOF
392 -test_expect_success 'multivar' '
391 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
392 test_cmp expect .git/config
393 '
@@ -415,9 +413,10 @@ test_expect_success 'multi-valued get-all returns all' '
413 test_cmp expect actual
414 '
415
418 -cat > expect << EOF
416 +test_expect_success 'multivar replace' '
417 + cat >expect <<EOF &&
418 [beta] ; silly comment # another comment
420 -noIndent= sillyValue ; 'nother silly comment
419 +noIndent= sillyValue ; ${SQ}nother silly comment
420
421 # empty line
422 ; comment
@@ -425,7 +424,6 @@ noIndent= sillyValue ; 'nother silly comment
424 nonewline = wow3
425 NoNewLine = wow2 for me
426 EOF
428 -test_expect_success 'multivar replace' '
427 git config nextsection.nonewline "wow3" "wow$" &&
428 test_cmp expect .git/config
429 '
@@ -438,17 +436,16 @@ test_expect_success 'invalid unset' '
436 test_must_fail git config ${mode_unset} somesection.nonewline
437 '
438
441 -cat > expect << EOF
439 +test_expect_success 'multivar unset' '
440 + cat >expect <<EOF &&
441 [beta] ; silly comment # another comment
443 -noIndent= sillyValue ; 'nother silly comment
442 +noIndent= sillyValue ; ${SQ}nother silly comment
443
444 # empty line
445 ; comment
446 [nextSection]
447 NoNewLine = wow2 for me
448 EOF
450 -
451 -test_expect_success 'multivar unset' '
449 case "$mode" in
450 legacy)
451 git config --unset nextsection.nonewline "wow3$";;
@@ -466,9 +463,10 @@ test_expect_success 'hierarchical section' '
463 git config Version.1.2.3eX.Alpha beta
464 '
465
469 -cat > expect << EOF
466 +test_expect_success 'hierarchical section value' '
467 + cat >expect <<EOF &&
468 [beta] ; silly comment # another comment
471 -noIndent= sillyValue ; 'nother silly comment
469 +noIndent= sillyValue ; ${SQ}nother silly comment
470
471 # empty line
472 ; comment
@@ -479,19 +477,16 @@ noIndent= sillyValue ; 'nother silly comment
477 [Version "1.2.3eX"]
478 Alpha = beta
479 EOF
482 -
483 -test_expect_success 'hierarchical section value' '
480 test_cmp expect .git/config
481 '
482
487 -cat > expect << EOF
488 -beta.noindent=sillyValue
489 -nextsection.nonewline=wow2 for me
490 -123456.a123=987
491 -version.1.2.3eX.alpha=beta
492 -EOF
493 -
483 test_expect_success 'working --list' '
484 + cat >expect <<-\EOF &&
485 + beta.noindent=sillyValue
486 + nextsection.nonewline=wow2 for me
487 + 123456.a123=987
488 + version.1.2.3eX.alpha=beta
489 + EOF
490 git config ${mode_prefix}list > output &&
491 test_cmp expect output
492 '
@@ -500,44 +495,40 @@ test_expect_success '--list without repo produces empty output' '
495 test_must_be_empty output
496 '
497
503 -cat > expect << EOF
504 -beta.noindent
505 -nextsection.nonewline
506 -123456.a123
507 -version.1.2.3eX.alpha
508 -EOF
509 -
498 test_expect_success '--name-only --list' '
499 + cat >expect <<-\EOF &&
500 + beta.noindent
501 + nextsection.nonewline
502 + 123456.a123
503 + version.1.2.3eX.alpha
504 + EOF
505 git config ${mode_prefix}list --name-only >output &&
506 test_cmp expect output
507 '
508
515 -cat > expect << EOF
516 -beta.noindent sillyValue
517 -nextsection.nonewline wow2 for me
518 -EOF
519 -
509 test_expect_success '--get-regexp' '
510 + cat >expect <<-\EOF &&
511 + beta.noindent sillyValue
512 + nextsection.nonewline wow2 for me
513 + EOF
514 git config ${mode_get_regexp} in >output &&
515 test_cmp expect output
516 '
517
525 -cat > expect << EOF
526 -beta.noindent
527 -nextsection.nonewline
528 -EOF
529 -
518 test_expect_success '--name-only --get-regexp' '
519 + cat >expect <<-\EOF &&
520 + beta.noindent
521 + nextsection.nonewline
522 + EOF
523 git config ${mode_get_regexp} --name-only in >output &&
524 test_cmp expect output
525 '
526
535 -cat > expect << EOF
536 -wow2 for me
537 -wow4 for you
538 -EOF
539 -
527 test_expect_success '--add' '
528 + cat >expect <<-\EOF &&
529 + wow2 for me
530 + wow4 for you
531 + EOF
532 git config --add nextsection.nonewline "wow4 for you" &&
533 git config ${mode_get_all} nextsection.nonewline > output &&
534 test_cmp expect output
@@ -558,37 +549,32 @@ test_expect_success 'get variable with empty value' '
549 git config --get emptyvalue.variable ^$
550 '
551
561 -echo novalue.variable > expect
562 -
552 test_expect_success 'get-regexp variable with no value' '
553 + echo novalue.variable >expect &&
554 git config ${mode_get_regexp} novalue > output &&
555 test_cmp expect output
556 '
557
568 -echo 'novalue.variable true' > expect
569 -
558 test_expect_success 'get-regexp --bool variable with no value' '
559 + echo "novalue.variable true" >expect &&
560 git config ${mode_get_regexp} --bool novalue > output &&
561 test_cmp expect output
562 '
563
575 -echo 'emptyvalue.variable ' > expect
576 -
564 test_expect_success 'get-regexp variable with empty value' '
565 + echo "emptyvalue.variable " >expect &&
566 git config ${mode_get_regexp} emptyvalue > output &&
567 test_cmp expect output
568 '
569
582 -echo true > expect
583 -
570 test_expect_success 'get bool variable with no value' '
571 + echo true >expect &&
572 git config --bool novalue.variable > output &&
573 test_cmp expect output
574 '
575
589 -echo false > expect
590 -
576 test_expect_success 'get bool variable with empty value' '
577 + echo false >expect &&
578 git config --bool emptyvalue.variable > output &&
579 test_cmp expect output
580 '
@@ -604,19 +590,19 @@ cat > .git/config << EOF
590 c = d
591 EOF
592
607 -cat > expect << EOF
593 +test_expect_success 'new section is partial match of another' '
594 + cat >expect <<\EOF &&
595 [a.b]
596 c = d
597 [a]
598 x = y
599 EOF
613 -
614 -test_expect_success 'new section is partial match of another' '
600 git config a.x y &&
601 test_cmp expect .git/config
602 '
603
619 -cat > expect << EOF
604 +test_expect_success 'new variable inserts into proper section' '
605 + cat >expect <<\EOF &&
606 [a.b]
607 c = d
608 [a]
@@ -625,8 +611,6 @@ cat > expect << EOF
611 [b]
612 x = y
613 EOF
628 -
629 -test_expect_success 'new variable inserts into proper section' '
614 git config b.x y &&
615 git config a.b c &&
616 test_cmp expect .git/config
@@ -642,11 +626,10 @@ cat > other-config << EOF
626 bahn = strasse
627 EOF
628
645 -cat > expect << EOF
646 -ein.bahn=strasse
647 -EOF
648 -
629 test_expect_success 'alternative GIT_CONFIG' '
630 + cat >expect <<-\EOF &&
631 + ein.bahn=strasse
632 + EOF
633 GIT_CONFIG=other-config git config ${mode_prefix}list >output &&
634 test_cmp expect output
635 '
@@ -675,14 +658,13 @@ test_expect_success 'refer config from subdirectory' '
658 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
659 '
660
678 -cat > expect << EOF
661 +test_expect_success '--set in alternative file' '
662 + cat >expect <<\EOF &&
663 [ein]
664 bahn = strasse
665 [anwohner]
666 park = ausweis
667 EOF
684 -
685 -test_expect_success '--set in alternative file' '
668 git config --file=other-config anwohner.park ausweis &&
669 test_cmp expect other-config
670 '
@@ -730,7 +712,8 @@ test_expect_success 'rename another section' '
712 git config ${mode_prefix}rename-section branch."1 234 blabl/a" branch.drei
713 '
714
733 -cat > expect << EOF
715 +test_expect_success 'rename succeeded' '
716 + cat >expect <<\EOF &&
717 # Hallo
718 #Bello
719 [branch "zwei"]
@@ -740,8 +723,6 @@ cat > expect << EOF
723 [branch "drei"]
724 weird
725 EOF
743 -
744 -test_expect_success 'rename succeeded' '
726 test_cmp expect .git/config
727 '
728
@@ -753,7 +734,8 @@ test_expect_success 'rename a section with a var on the same line' '
734 git config ${mode_prefix}rename-section branch.vier branch.zwei
735 '
736
756 -cat > expect << EOF
737 +test_expect_success 'rename succeeded' '
738 + cat >expect <<\EOF &&
739 # Hallo
740 #Bello
741 [branch "zwei"]
@@ -765,8 +747,6 @@ weird
747 [branch "zwei"]
748 z = 1
749 EOF
768 -
769 -test_expect_success 'rename succeeded' '
750 test_cmp expect .git/config
751 '
752
@@ -816,32 +796,29 @@ test_expect_success 'remove section' '
796 git config ${mode_prefix}remove-section branch.zwei
797 '
798
819 -cat > expect << EOF
799 +test_expect_success 'section was removed properly' '
800 + cat >expect <<\EOF &&
801 # Hallo
802 #Bello
803 [branch "drei"]
804 weird
805 EOF
825 -
826 -test_expect_success 'section was removed properly' '
806 test_cmp expect .git/config
807 '
808
830 -cat > expect << EOF
809 +test_expect_success 'section ending' '
810 + cat >expect <<\EOF &&
811 [gitcvs]
812 enabled = true
813 dbname = %Ggitcvs2.%a.%m.sqlite
814 [gitcvs "ext"]
815 dbname = %Ggitcvs1.%a.%m.sqlite
816 EOF
837 -
838 -test_expect_success 'section ending' '
817 rm -f .git/config &&
818 git config ${mode_set} gitcvs.enabled true &&
819 git config ${mode_set} gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
820 git config ${mode_set} gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
821 test_cmp expect .git/config
844 -
822 '
823
824 test_expect_success numbers '
@@ -885,19 +862,17 @@ test_expect_success 'invalid stdin config' '
862 test_grep "bad config line 1 in standard input" output
863 '
864
888 -cat > expect << EOF
889 -true
890 -false
891 -true
892 -false
893 -true
894 -false
895 -true
896 -false
897 -EOF
898 -
865 test_expect_success bool '
900 -
866 + cat >expect <<-\EOF &&
867 + true
868 + false
869 + true
870 + false
871 + true
872 + false
873 + true
874 + false
875 + EOF
876 git config ${mode_set} bool.true1 01 &&
877 git config ${mode_set} bool.true2 -1 &&
878 git config ${mode_set} bool.true3 YeS &&
@@ -923,7 +898,8 @@ test_expect_success 'invalid bool (set)' '
898
899 test_must_fail git config --bool bool.nobool foobar'
900
926 -cat > expect <<\EOF
901 +test_expect_success 'set --bool' '
902 + cat >expect <<\EOF &&
903 [bool]
904 true1 = true
905 true2 = true
@@ -934,9 +910,6 @@ cat > expect <<\EOF
910 false3 = false
911 false4 = false
912 EOF
937 -
938 -test_expect_success 'set --bool' '
939 -
913 rm -f .git/config &&
914 git config --bool bool.true1 01 &&
915 git config --bool bool.true2 -1 &&
@@ -948,15 +921,13 @@ test_expect_success 'set --bool' '
921 git config --bool bool.false4 FALSE &&
922 test_cmp expect .git/config'
923
951 -cat > expect <<\EOF
924 +test_expect_success 'set --int' '
925 + cat >expect <<\EOF &&
926 [int]
927 val1 = 1
928 val2 = -1
929 val3 = 5242880
930 EOF
957 -
958 -test_expect_success 'set --int' '
959 -
931 rm -f .git/config &&
932 git config --int int.val1 01 &&
933 git config --int int.val2 -1 &&
@@ -994,7 +965,8 @@ test_expect_success 'get --bool-or-int' '
965 test_cmp expect actual
966 '
967
997 -cat >expect <<\EOF
968 +test_expect_success 'set --bool-or-int' '
969 + cat >expect <<\EOF &&
970 [bool]
971 true1 = true
972 false1 = false
@@ -1005,8 +977,6 @@ cat >expect <<\EOF
977 int2 = 1
978 int3 = -1
979 EOF
1008 -
1009 -test_expect_success 'set --bool-or-int' '
980 rm -f .git/config &&
981 git config --bool-or-int bool.true1 true &&
982 git config --bool-or-int bool.false1 false &&
@@ -1018,14 +988,13 @@ test_expect_success 'set --bool-or-int' '
988 test_cmp expect .git/config
989 '
990
1021 -cat >expect <<\EOF
991 +test_expect_success !MINGW 'set --path' '
992 + cat >expect <<\EOF &&
993 [path]
994 home = ~/
995 normal = /dev/null
996 trailingtilde = foo~
997 EOF
1027 -
1028 -test_expect_success !MINGW 'set --path' '
998 rm -f .git/config &&
999 git config --path path.home "~/" &&
1000 git config --path path.normal "/dev/null" &&
@@ -1037,25 +1006,23 @@ then
1006 test_set_prereq HOMEVAR
1007 fi
1008
1040 -cat >expect <<EOF
1041 -$HOME/
1042 -/dev/null
1043 -foo~
1044 -EOF
1045 -
1009 test_expect_success HOMEVAR 'get --path' '
1010 + cat >expect <<-EOF &&
1011 + $HOME/
1012 + /dev/null
1013 + foo~
1014 + EOF
1015 git config --get --path path.home > result &&
1016 git config --get --path path.normal >> result &&
1017 git config --get --path path.trailingtilde >> result &&
1018 test_cmp expect result
1019 '
1020
1053 -cat >expect <<\EOF
1054 -/dev/null
1055 -foo~
1056 -EOF
1057 -
1021 test_expect_success !MINGW 'get --path copes with unset $HOME' '
1022 + cat >expect <<-\EOF &&
1023 + /dev/null
1024 + foo~
1025 + EOF
1026 (
1027 sane_unset HOME &&
1028 test_must_fail git config --get --path path.home \
@@ -1112,12 +1079,11 @@ test_expect_success 'get --type=color' '
1079 test_cmp expect actual
1080 '
1081
1115 -cat >expect << EOF
1082 +test_expect_success 'set --type=color' '
1083 + cat >expect <<\EOF &&
1084 [foo]
1085 color = red
1086 EOF
1119 -
1120 -test_expect_success 'set --type=color' '
1087 rm .git/config &&
1088 git config --type=color foo.color "red" &&
1089 test_cmp expect .git/config
@@ -1133,14 +1099,14 @@ test_expect_success 'set --type=color barfs on non-color' '
1099 test_grep "cannot parse color" error
1100 '
1101
1136 -cat > expect << EOF
1102 +test_expect_success 'quoting' '
1103 + cat >expect <<\EOF &&
1104 [quote]
1105 leading = " test"
1106 ending = "test "
1107 semicolon = "test;test"
1108 hash = "test#test"
1109 EOF
1143 -test_expect_success 'quoting' '
1110 rm -f .git/config &&
1111 git config ${mode_set} quote.leading " test" &&
1112 git config ${mode_set} quote.ending "test " &&
@@ -1166,13 +1132,12 @@ inued
1132 inued"
1133 EOF
1134
1169 -cat > expect <<\EOF
1170 -section.continued=continued
1171 -section.noncont=not continued
1172 -section.quotecont=cont;inued
1173 -EOF
1174 -
1135 test_expect_success 'value continued on next line' '
1136 + cat >expect <<-\EOF &&
1137 + section.continued=continued
1138 + section.noncont=not continued
1139 + section.quotecont=cont;inued
1140 + EOF
1141 git config ${mode_prefix}list > result &&
1142 test_cmp expect result
1143 '