trailer tests: make test cases self-contained

By using "test_config" instead of "git config", we avoid leaking configuration state across test cases. This in turn helps to make the tests more self-contained, by explicitly capturing the configuration setup. It then makes it easier to add tests anywhere in this 1500+ line file, without worrying about what implicit state was set in some prior test case defined earlier up in the script. This commit was created mechanically as follows: we changed the first occurrence of a particular "git config trailer.*" option, then ran the tests repeatedly to see which ones broke, adding in the extra "test_config" equivalents to make them pass again. In addition, in some test cases we removed "git config --unset ..." lines because they were no longer necessary (as the --unset was being used to clean up leaked configuration state from earlier test cases). The process described above was done repeatedly until there were no more unbridled "git config" invocations. Some "git config" invocations still do exist in the script, but they were already cleaned up properly with test_when_finished "git config --remove-section ..." so they were left alone. Note that these cleanups result in generally longer test case setups because the previously hidden state is now being exposed. Although we could then clean up the test cases' "expected" values to be less verbose (the verbosity arising from the use of implicit state), we choose not to do so here, to make sure that this cleanup does not change any meanings behind the test cases. Signed-off-by: Linus Arver <linusa@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Arver committed Sep 7, 2023 at 22:19 UTC 84e53330f0433b35057ff70dd856494f9970dda9
1 file changed +300 -74
t/t7513-interpret-trailers.sh
+300 -74
@@ -489,7 +489,7 @@ test_expect_success 'multiline field treated as atomic for neighbor check' '
489 '
490
491 test_expect_success 'with config setup' '
492 - git config trailer.ack.key "Acked-by: " &&
492 + test_config trailer.ack.key "Acked-by: " &&
493 cat >expected <<-\EOF &&
494
495 Acked-by: Peff
@@ -503,8 +503,8 @@ test_expect_success 'with config setup' '
503 '
504
505 test_expect_success 'with config setup and ":=" as separators' '
506 - git config trailer.separators ":=" &&
507 - git config trailer.ack.key "Acked-by= " &&
506 + test_config trailer.separators ":=" &&
507 + test_config trailer.ack.key "Acked-by= " &&
508 cat >expected <<-\EOF &&
509
510 Acked-by= Peff
@@ -518,7 +518,7 @@ test_expect_success 'with config setup and ":=" as separators' '
518 '
519
520 test_expect_success 'with config setup and "%" as separators' '
521 - git config trailer.separators "%" &&
521 + test_config trailer.separators "%" &&
522 cat >expected <<-\EOF &&
523
524 bug% 42
@@ -532,6 +532,7 @@ test_expect_success 'with config setup and "%" as separators' '
532 '
533
534 test_expect_success 'with "%" as separators and a message with trailers' '
535 + test_config trailer.separators "%" &&
536 cat >special_message <<-\EOF &&
537 Special Message
538
@@ -553,8 +554,8 @@ test_expect_success 'with "%" as separators and a message with trailers' '
554 '
555
556 test_expect_success 'with config setup and ":=#" as separators' '
556 - git config trailer.separators ":=#" &&
557 - git config trailer.bug.key "Bug #" &&
557 + test_config trailer.separators ":=#" &&
558 + test_config trailer.bug.key "Bug #" &&
559 cat >expected <<-\EOF &&
560
561 Bug #42
@@ -581,6 +582,8 @@ test_expect_success 'with basic patch' '
582 '
583
584 test_expect_success 'with commit complex message as argument' '
585 + test_config trailer.separators ":=" &&
586 + test_config trailer.ack.key "Acked-by= " &&
587 cat complex_message_body complex_message_trailers >complex_message &&
588 cat complex_message_body >expected &&
589 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
@@ -594,6 +597,8 @@ test_expect_success 'with commit complex message as argument' '
597 '
598
599 test_expect_success 'with 2 files arguments' '
600 + test_config trailer.separators ":=" &&
601 + test_config trailer.ack.key "Acked-by= " &&
602 cat basic_message >>expected &&
603 echo >>expected &&
604 cat basic_patch >>expected &&
@@ -677,6 +682,9 @@ test_expect_success 'with message that has an old style conflict block' '
682 '
683
684 test_expect_success 'with commit complex message and trailer args' '
685 + test_config trailer.separators ":=#" &&
686 + test_config trailer.ack.key "Acked-by= " &&
687 + test_config trailer.bug.key "Bug #" &&
688 cat complex_message_body >expected &&
689 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
690 Fixes: Z
@@ -692,6 +700,9 @@ test_expect_success 'with commit complex message and trailer args' '
700 '
701
702 test_expect_success 'with complex patch, args and --trim-empty' '
703 + test_config trailer.separators ":=#" &&
704 + test_config trailer.ack.key "Acked-by= " &&
705 + test_config trailer.bug.key "Bug #" &&
706 cat complex_message >complex_patch &&
707 cat basic_patch >>complex_patch &&
708 cat complex_message_body >expected &&
@@ -746,7 +757,10 @@ test_expect_success POSIXPERM,SANITY "in-place editing doesn't clobber original
757 '
758
759 test_expect_success 'using "where = before"' '
749 - git config trailer.bug.where "before" &&
760 + test_config trailer.separators ":=#" &&
761 + test_config trailer.ack.key "Acked-by= " &&
762 + test_config trailer.bug.key "Bug #" &&
763 + test_config trailer.bug.where "before" &&
764 cat complex_message_body >expected &&
765 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
766 Bug #42
@@ -762,7 +776,9 @@ test_expect_success 'using "where = before"' '
776 '
777
778 test_expect_success 'overriding configuration with "--where after"' '
765 - git config trailer.ack.where "before" &&
779 + test_config trailer.separators ":=" &&
780 + test_config trailer.ack.key "Acked-by= " &&
781 + test_config trailer.ack.where "before" &&
782 cat complex_message_body >expected &&
783 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
784 Fixes: Z
@@ -777,6 +793,11 @@ test_expect_success 'overriding configuration with "--where after"' '
793 '
794
795 test_expect_success 'using "where = before" with "--no-where"' '
796 + test_config trailer.ack.key "Acked-by= " &&
797 + test_config trailer.ack.where "before" &&
798 + test_config trailer.bug.key "Bug #" &&
799 + test_config trailer.bug.where "before" &&
800 + test_config trailer.separators ":=#" &&
801 cat complex_message_body >expected &&
802 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
803 Bug #42
@@ -792,7 +813,11 @@ test_expect_success 'using "where = before" with "--no-where"' '
813 '
814
815 test_expect_success 'using "where = after"' '
795 - git config trailer.ack.where "after" &&
816 + test_config trailer.ack.key "Acked-by= " &&
817 + test_config trailer.ack.where "after" &&
818 + test_config trailer.bug.key "Bug #" &&
819 + test_config trailer.bug.where "before" &&
820 + test_config trailer.separators ":=#" &&
821 cat complex_message_body >expected &&
822 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
823 Bug #42
@@ -808,8 +833,11 @@ test_expect_success 'using "where = after"' '
833 '
834
835 test_expect_success 'using "where = end"' '
811 - git config trailer.review.key "Reviewed-by" &&
812 - git config trailer.review.where "end" &&
836 + test_config trailer.review.key "Reviewed-by" &&
837 + test_config trailer.review.where "end" &&
838 + test_config trailer.ack.key "Acked-by= " &&
839 + test_config trailer.ack.where "after" &&
840 + test_config trailer.separators ":=" &&
841 cat complex_message_body >expected &&
842 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
843 Fixes: Z
@@ -827,8 +855,11 @@ test_expect_success 'using "where = end"' '
855 '
856
857 test_expect_success 'using "where = start"' '
830 - git config trailer.review.key "Reviewed-by" &&
831 - git config trailer.review.where "start" &&
858 + test_config trailer.review.key "Reviewed-by" &&
859 + test_config trailer.review.where "start" &&
860 + test_config trailer.ack.key "Acked-by= " &&
861 + test_config trailer.ack.where "after" &&
862 + test_config trailer.separators ":=" &&
863 cat complex_message_body >expected &&
864 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
865 Reviewed-by: Johannes
@@ -846,8 +877,13 @@ test_expect_success 'using "where = start"' '
877 '
878
879 test_expect_success 'using "where = before" for a token in the middle of the message' '
849 - git config trailer.review.key "Reviewed-by:" &&
850 - git config trailer.review.where "before" &&
880 + test_config trailer.review.key "Reviewed-by:" &&
881 + test_config trailer.review.where "before" &&
882 + test_config trailer.ack.key "Acked-by= " &&
883 + test_config trailer.ack.where "after" &&
884 + test_config trailer.bug.key "Bug #" &&
885 + test_config trailer.bug.where "before" &&
886 + test_config trailer.separators ":=#" &&
887 cat complex_message_body >expected &&
888 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
889 Bug #42
@@ -864,6 +900,12 @@ test_expect_success 'using "where = before" for a token in the middle of the mes
900 '
901
902 test_expect_success 'using "where = before" and --trim-empty' '
903 + test_config trailer.ack.key "Acked-by= " &&
904 + test_config trailer.ack.where "after" &&
905 + test_config trailer.bug.key "Bug #" &&
906 + test_config trailer.bug.where "before" &&
907 + test_config trailer.review.key "Reviewed-by:" &&
908 + test_config trailer.separators ":=#" &&
909 cat complex_message_body >expected &&
910 cat >>expected <<-\EOF &&
911 Bug #46
@@ -878,6 +920,13 @@ test_expect_success 'using "where = before" and --trim-empty' '
920 '
921
922 test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
923 + test_config trailer.ack.key "Acked-by= " &&
924 + test_config trailer.ack.where "after" &&
925 + test_config trailer.bug.key "Bug #" &&
926 + test_config trailer.bug.where "before" &&
927 + test_config trailer.review.key "Reviewed-by:" &&
928 + test_config trailer.review.where "before" &&
929 + test_config trailer.separators ":=#" &&
930 cat complex_message_body >expected &&
931 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
932 Bug #42
@@ -896,7 +945,13 @@ test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
945 '
946
947 test_expect_success 'default "ifExists" is now "addIfDifferent"' '
899 - git config trailer.ifexists "addIfDifferent" &&
948 + test_config trailer.ifexists "addIfDifferent" &&
949 + test_config trailer.ack.key "Acked-by= " &&
950 + test_config trailer.ack.where "after" &&
951 + test_config trailer.bug.key "Bug #" &&
952 + test_config trailer.bug.where "before" &&
953 + test_config trailer.review.key "Reviewed-by:" &&
954 + test_config trailer.separators ":=#" &&
955 cat complex_message_body >expected &&
956 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
957 Bug #42
@@ -914,8 +969,14 @@ test_expect_success 'default "ifExists" is now "addIfDifferent"' '
969 '
970
971 test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
917 - git config trailer.ack.ifExists "addIfDifferent" &&
918 - git config trailer.ack.where "end" &&
972 + test_config trailer.ack.ifExists "addIfDifferent" &&
973 + test_config trailer.ack.key "Acked-by= " &&
974 + test_config trailer.ack.where "end" &&
975 + test_config trailer.bug.key "Bug #" &&
976 + test_config trailer.bug.where "before" &&
977 + test_config trailer.review.key "Reviewed-by:" &&
978 + test_config trailer.ifexists "addIfDifferent" &&
979 + test_config trailer.separators ":=#" &&
980 cat complex_message_body >expected &&
981 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
982 Bug #42
@@ -932,8 +993,14 @@ test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
993 '
994
995 test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
935 - git config trailer.ack.ifExists "addIfDifferent" &&
936 - git config trailer.ack.where "before" &&
996 + test_config trailer.ack.ifExists "addIfDifferent" &&
997 + test_config trailer.ack.key "Acked-by= " &&
998 + test_config trailer.ack.where "before" &&
999 + test_config trailer.bug.key "Bug #" &&
1000 + test_config trailer.bug.where "before" &&
1001 + test_config trailer.review.key "Reviewed-by:" &&
1002 + test_config trailer.ifexists "addIfDifferent" &&
1003 + test_config trailer.separators ":=#" &&
1004 cat complex_message_body >expected &&
1005 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1006 Bug #42
@@ -950,8 +1017,14 @@ test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
1017 '
1018
1019 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
953 - git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
954 - git config trailer.ack.where "end" &&
1020 + test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
1021 + test_config trailer.ack.key "Acked-by= " &&
1022 + test_config trailer.ack.where "end" &&
1023 + test_config trailer.bug.key "Bug #" &&
1024 + test_config trailer.bug.where "before" &&
1025 + test_config trailer.review.key "Reviewed-by:" &&
1026 + test_config trailer.ifexists "addIfDifferent" &&
1027 + test_config trailer.separators ":=#" &&
1028 cat complex_message_body >expected &&
1029 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1030 Bug #42
@@ -973,8 +1046,14 @@ test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end
1046 '
1047
1048 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
976 - git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
977 - git config trailer.ack.where "after" &&
1049 + test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
1050 + test_config trailer.ack.key "Acked-by= " &&
1051 + test_config trailer.ack.where "after" &&
1052 + test_config trailer.bug.key "Bug #" &&
1053 + test_config trailer.bug.where "before" &&
1054 + test_config trailer.review.key "Reviewed-by:" &&
1055 + test_config trailer.ifexists "addIfDifferent" &&
1056 + test_config trailer.separators ":=#" &&
1057 cat complex_message_body >expected &&
1058 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1059 Bug #42
@@ -995,7 +1074,11 @@ test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = af
1074 '
1075
1076 test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
998 - git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
1077 + test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
1078 + test_config trailer.ack.key "Acked-by= " &&
1079 + test_config trailer.bug.key "Bug #" &&
1080 + test_config trailer.bug.where "before" &&
1081 + test_config trailer.separators ":=#" &&
1082 cat complex_message_body >expected &&
1083 cat >>expected <<-\EOF &&
1084 Bug #42
@@ -1011,8 +1094,14 @@ test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty'
1094 '
1095
1096 test_expect_success 'using "ifExists = add" with "where = end"' '
1014 - git config trailer.ack.ifExists "add" &&
1015 - git config trailer.ack.where "end" &&
1097 + test_config trailer.ack.ifExists "add" &&
1098 + test_config trailer.ack.key "Acked-by= " &&
1099 + test_config trailer.ack.where "end" &&
1100 + test_config trailer.bug.key "Bug #" &&
1101 + test_config trailer.bug.where "before" &&
1102 + test_config trailer.review.key "Reviewed-by:" &&
1103 + test_config trailer.ifexists "addIfDifferent" &&
1104 + test_config trailer.separators ":=#" &&
1105 cat complex_message_body >expected &&
1106 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1107 Bug #42
@@ -1036,8 +1125,14 @@ test_expect_success 'using "ifExists = add" with "where = end"' '
1125 '
1126
1127 test_expect_success 'using "ifExists = add" with "where = after"' '
1039 - git config trailer.ack.ifExists "add" &&
1040 - git config trailer.ack.where "after" &&
1128 + test_config trailer.ack.ifExists "add" &&
1129 + test_config trailer.ack.key "Acked-by= " &&
1130 + test_config trailer.ack.where "after" &&
1131 + test_config trailer.bug.key "Bug #" &&
1132 + test_config trailer.bug.where "before" &&
1133 + test_config trailer.review.key "Reviewed-by:" &&
1134 + test_config trailer.ifexists "addIfDifferent" &&
1135 + test_config trailer.separators ":=#" &&
1136 cat complex_message_body >expected &&
1137 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1138 Bug #42
@@ -1058,8 +1153,15 @@ test_expect_success 'using "ifExists = add" with "where = after"' '
1153 '
1154
1155 test_expect_success 'overriding configuration with "--if-exists replace"' '
1061 - git config trailer.fix.key "Fixes: " &&
1062 - git config trailer.fix.ifExists "add" &&
1156 + test_config trailer.fix.key "Fixes: " &&
1157 + test_config trailer.fix.ifExists "add" &&
1158 + test_config trailer.ack.key "Acked-by= " &&
1159 + test_config trailer.ack.where "after" &&
1160 + test_config trailer.bug.key "Bug #" &&
1161 + test_config trailer.bug.where "before" &&
1162 + test_config trailer.review.key "Reviewed-by:" &&
1163 + test_config trailer.review.where "before" &&
1164 + test_config trailer.separators ":=#" &&
1165 cat complex_message_body >expected &&
1166 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1167 Bug #42
@@ -1075,8 +1177,15 @@ test_expect_success 'overriding configuration with "--if-exists replace"' '
1177 '
1178
1179 test_expect_success 'using "ifExists = replace"' '
1078 - git config trailer.fix.key "Fixes: " &&
1079 - git config trailer.fix.ifExists "replace" &&
1180 + test_config trailer.fix.key "Fixes: " &&
1181 + test_config trailer.fix.ifExists "replace" &&
1182 + test_config trailer.ack.key "Acked-by= " &&
1183 + test_config trailer.ack.where "after" &&
1184 + test_config trailer.bug.key "Bug #" &&
1185 + test_config trailer.bug.where "before" &&
1186 + test_config trailer.review.key "Reviewed-by:" &&
1187 + test_config trailer.ifexists "addIfDifferent" &&
1188 + test_config trailer.separators ":=#" &&
1189 cat complex_message_body >expected &&
1190 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1191 Bug #42
@@ -1095,7 +1204,16 @@ test_expect_success 'using "ifExists = replace"' '
1204 '
1205
1206 test_expect_success 'using "ifExists = replace" with "where = after"' '
1098 - git config trailer.fix.where "after" &&
1207 + test_config trailer.ack.key "Acked-by= " &&
1208 + test_config trailer.ack.where "after" &&
1209 + test_config trailer.bug.key "Bug #" &&
1210 + test_config trailer.bug.where "before" &&
1211 + test_config trailer.fix.key "Fixes: " &&
1212 + test_config trailer.fix.ifExists "replace" &&
1213 + test_config trailer.fix.where "after" &&
1214 + test_config trailer.review.key "Reviewed-by:" &&
1215 + test_config trailer.ifexists "addIfDifferent" &&
1216 + test_config trailer.separators ":=#" &&
1217 cat complex_message_body >expected &&
1218 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1219 Bug #42
@@ -1114,7 +1232,15 @@ test_expect_success 'using "ifExists = replace" with "where = after"' '
1232 '
1233
1234 test_expect_success 'using "ifExists = doNothing"' '
1117 - git config trailer.fix.ifExists "doNothing" &&
1235 + test_config trailer.fix.ifExists "doNothing" &&
1236 + test_config trailer.ack.key "Acked-by= " &&
1237 + test_config trailer.ack.where "after" &&
1238 + test_config trailer.bug.key "Bug #" &&
1239 + test_config trailer.bug.where "before" &&
1240 + test_config trailer.fix.key "Fixes: " &&
1241 + test_config trailer.review.key "Reviewed-by:" &&
1242 + test_config trailer.ifexists "addIfDifferent" &&
1243 + test_config trailer.separators ":=#" &&
1244 cat complex_message_body >expected &&
1245 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1246 Bug #42
@@ -1133,8 +1259,17 @@ test_expect_success 'using "ifExists = doNothing"' '
1259 '
1260
1261 test_expect_success 'the default is "ifMissing = add"' '
1136 - git config trailer.cc.key "Cc: " &&
1137 - git config trailer.cc.where "before" &&
1262 + test_config trailer.ack.key "Acked-by= " &&
1263 + test_config trailer.ack.where "after" &&
1264 + test_config trailer.bug.key "Bug #" &&
1265 + test_config trailer.bug.where "before" &&
1266 + test_config trailer.cc.key "Cc: " &&
1267 + test_config trailer.cc.where "before" &&
1268 + test_config trailer.fix.key "Fixes: " &&
1269 + test_config trailer.fix.ifExists "doNothing" &&
1270 + test_config trailer.review.key "Reviewed-by:" &&
1271 + test_config trailer.ifexists "addIfDifferent" &&
1272 + test_config trailer.separators ":=#" &&
1273 cat complex_message_body >expected &&
1274 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1275 Bug #42
@@ -1154,7 +1289,14 @@ test_expect_success 'the default is "ifMissing = add"' '
1289 '
1290
1291 test_expect_success 'overriding configuration with "--if-missing doNothing"' '
1157 - git config trailer.ifmissing "add" &&
1292 + test_config trailer.ack.key "Acked-by= " &&
1293 + test_config trailer.ack.where "after" &&
1294 + test_config trailer.fix.key "Fixes: " &&
1295 + test_config trailer.fix.ifExists "doNothing" &&
1296 + test_config trailer.review.key "Reviewed-by:" &&
1297 + test_config trailer.ifexists "addIfDifferent" &&
1298 + test_config trailer.ifmissing "add" &&
1299 + test_config trailer.separators ":=" &&
1300 cat complex_message_body >expected &&
1301 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1302 Fixes: Z
@@ -1173,7 +1315,13 @@ test_expect_success 'overriding configuration with "--if-missing doNothing"' '
1315 '
1316
1317 test_expect_success 'when default "ifMissing" is "doNothing"' '
1176 - git config trailer.ifmissing "doNothing" &&
1318 + test_config trailer.ack.key "Acked-by= " &&
1319 + test_config trailer.ack.where "after" &&
1320 + test_config trailer.fix.ifExists "doNothing" &&
1321 + test_config trailer.review.key "Reviewed-by:" &&
1322 + test_config trailer.ifexists "addIfDifferent" &&
1323 + test_config trailer.ifmissing "doNothing" &&
1324 + test_config trailer.separators ":=" &&
1325 cat complex_message_body >expected &&
1326 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1327 Fixes: Z
@@ -1187,14 +1335,21 @@ test_expect_success 'when default "ifMissing" is "doNothing"' '
1335 --trailer "cc=Linus" --trailer "ack: Junio" \
1336 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1337 <complex_message >actual &&
1190 - test_cmp expected actual &&
1191 - git config trailer.ifmissing "add"
1338 + test_cmp expected actual
1339 '
1340
1341 test_expect_success 'using "ifMissing = add" with "where = end"' '
1195 - git config trailer.cc.key "Cc: " &&
1196 - git config trailer.cc.where "end" &&
1197 - git config trailer.cc.ifMissing "add" &&
1342 + test_config trailer.ack.key "Acked-by= " &&
1343 + test_config trailer.ack.where "after" &&
1344 + test_config trailer.bug.key "Bug #" &&
1345 + test_config trailer.bug.where "before" &&
1346 + test_config trailer.cc.key "Cc: " &&
1347 + test_config trailer.cc.ifMissing "add" &&
1348 + test_config trailer.cc.where "end" &&
1349 + test_config trailer.fix.ifExists "doNothing" &&
1350 + test_config trailer.review.key "Reviewed-by:" &&
1351 + test_config trailer.ifexists "addIfDifferent" &&
1352 + test_config trailer.separators ":=#" &&
1353 cat complex_message_body >expected &&
1354 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1355 Bug #42
@@ -1214,9 +1369,17 @@ test_expect_success 'using "ifMissing = add" with "where = end"' '
1369 '
1370
1371 test_expect_success 'using "ifMissing = add" with "where = before"' '
1217 - git config trailer.cc.key "Cc: " &&
1218 - git config trailer.cc.where "before" &&
1219 - git config trailer.cc.ifMissing "add" &&
1372 + test_config trailer.ack.key "Acked-by= " &&
1373 + test_config trailer.ack.where "after" &&
1374 + test_config trailer.bug.key "Bug #" &&
1375 + test_config trailer.bug.where "before" &&
1376 + test_config trailer.cc.key "Cc: " &&
1377 + test_config trailer.cc.ifMissing "add" &&
1378 + test_config trailer.cc.where "before" &&
1379 + test_config trailer.fix.ifExists "doNothing" &&
1380 + test_config trailer.review.key "Reviewed-by:" &&
1381 + test_config trailer.ifexists "addIfDifferent" &&
1382 + test_config trailer.separators ":=#" &&
1383 cat complex_message_body >expected &&
1384 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1385 Cc: Linus
@@ -1236,7 +1399,15 @@ test_expect_success 'using "ifMissing = add" with "where = before"' '
1399 '
1400
1401 test_expect_success 'using "ifMissing = doNothing"' '
1239 - git config trailer.cc.ifMissing "doNothing" &&
1402 + test_config trailer.ack.key "Acked-by= " &&
1403 + test_config trailer.ack.where "after" &&
1404 + test_config trailer.bug.key "Bug #" &&
1405 + test_config trailer.bug.where "before" &&
1406 + test_config trailer.cc.ifMissing "doNothing" &&
1407 + test_config trailer.fix.ifExists "doNothing" &&
1408 + test_config trailer.review.key "Reviewed-by:" &&
1409 + test_config trailer.ifexists "addIfDifferent" &&
1410 + test_config trailer.separators ":=#" &&
1411 cat complex_message_body >expected &&
1412 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1413 Bug #42
@@ -1256,7 +1427,15 @@ test_expect_success 'using "ifMissing = doNothing"' '
1427
1428 test_expect_success 'default "where" is now "after"' '
1429 git config trailer.where "after" &&
1259 - git config --unset trailer.ack.where &&
1430 + test_config trailer.ack.ifExists "add" &&
1431 + test_config trailer.ack.key "Acked-by= " &&
1432 + test_config trailer.ack.where "after" &&
1433 + test_config trailer.bug.key "Bug #" &&
1434 + test_config trailer.bug.where "before" &&
1435 + test_config trailer.fix.ifExists "doNothing" &&
1436 + test_config trailer.review.key "Reviewed-by:" &&
1437 + test_config trailer.ifexists "addIfDifferent" &&
1438 + test_config trailer.separators ":=#" &&
1439 cat complex_message_body >expected &&
1440 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1441 Bug #42
@@ -1280,10 +1459,15 @@ test_expect_success 'default "where" is now "after"' '
1459 '
1460
1461 test_expect_success 'with simple command' '
1283 - git config trailer.sign.key "Signed-off-by: " &&
1284 - git config trailer.sign.where "after" &&
1285 - git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1286 - git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
1462 + test_config trailer.ack.key "Acked-by= " &&
1463 + test_config trailer.fix.ifExists "doNothing" &&
1464 + test_config trailer.review.key "Reviewed-by:" &&
1465 + test_config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
1466 + test_config trailer.sign.key "Signed-off-by: " &&
1467 + test_config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1468 + test_config trailer.sign.where "after" &&
1469 + test_config trailer.ifexists "addIfDifferent" &&
1470 + test_config trailer.separators ":=" &&
1471 cat complex_message_body >expected &&
1472 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1473 Fixes: Z
@@ -1298,8 +1482,14 @@ test_expect_success 'with simple command' '
1482 '
1483
1484 test_expect_success 'with command using committer information' '
1301 - git config trailer.sign.ifExists "addIfDifferent" &&
1302 - git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
1485 + test_config trailer.ack.key "Acked-by= " &&
1486 + test_config trailer.fix.ifExists "doNothing" &&
1487 + test_config trailer.review.key "Reviewed-by:" &&
1488 + test_config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
1489 + test_config trailer.sign.key "Signed-off-by: " &&
1490 + test_config trailer.sign.ifExists "addIfDifferent" &&
1491 + test_config trailer.ifexists "addIfDifferent" &&
1492 + test_config trailer.separators ":=" &&
1493 cat complex_message_body >expected &&
1494 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1495 Fixes: Z
@@ -1314,10 +1504,15 @@ test_expect_success 'with command using committer information' '
1504 '
1505
1506 test_expect_success 'with command using author information' '
1317 - git config trailer.sign.key "Signed-off-by: " &&
1318 - git config trailer.sign.where "after" &&
1319 - git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1320 - git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1507 + test_config trailer.ack.key "Acked-by= " &&
1508 + test_config trailer.fix.ifExists "doNothing" &&
1509 + test_config trailer.review.key "Reviewed-by:" &&
1510 + test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1511 + test_config trailer.sign.key "Signed-off-by: " &&
1512 + test_config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1513 + test_config trailer.sign.where "after" &&
1514 + test_config trailer.ifexists "addIfDifferent" &&
1515 + test_config trailer.separators ":=" &&
1516 cat complex_message_body >expected &&
1517 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1518 Fixes: Z
@@ -1338,12 +1533,19 @@ test_expect_success 'setup a commit' '
1533 '
1534
1535 test_expect_success 'cmd takes precedence over command' '
1341 - test_when_finished "git config --unset trailer.fix.cmd" &&
1342 - git config trailer.fix.ifExists "replace" &&
1343 - git config trailer.fix.cmd "test -n \"\$1\" && git log -1 --oneline --format=\"%h (%aN)\" \
1344 - --abbrev-commit --abbrev=14 \"\$1\" || true" &&
1345 - git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" \
1536 + test_config trailer.ack.key "Acked-by= " &&
1537 + test_config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" \
1538 --abbrev-commit --abbrev=14 \$ARG" &&
1539 + test_config trailer.fix.cmd "test -n \"\$1\" && git log -1 --oneline --format=\"%h (%aN)\" \
1540 + --abbrev-commit --abbrev=14 \"\$1\" || true" &&
1541 + test_config trailer.fix.key "Fixes: " &&
1542 + test_config trailer.fix.ifExists "replace" &&
1543 + test_config trailer.fix.where "after" &&
1544 + test_config trailer.review.key "Reviewed-by:" &&
1545 + test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1546 + test_config trailer.sign.key "Signed-off-by: " &&
1547 + test_config trailer.ifexists "addIfDifferent" &&
1548 + test_config trailer.separators ":=" &&
1549 FIXED=$(git log -1 --oneline --format="%h (%aN)" --abbrev-commit --abbrev=14 HEAD) &&
1550 cat complex_message_body >expected2 &&
1551 sed -e "s/ Z\$/ /" >>expected2 <<-EOF &&
@@ -1359,8 +1561,16 @@ test_expect_success 'cmd takes precedence over command' '
1561 '
1562
1563 test_expect_success 'with command using $ARG' '
1362 - git config trailer.fix.ifExists "replace" &&
1363 - git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
1564 + test_config trailer.ack.key "Acked-by= " &&
1565 + test_config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
1566 + test_config trailer.fix.key "Fixes: " &&
1567 + test_config trailer.fix.ifExists "replace" &&
1568 + test_config trailer.fix.where "after" &&
1569 + test_config trailer.review.key "Reviewed-by:" &&
1570 + test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1571 + test_config trailer.sign.key "Signed-off-by: " &&
1572 + test_config trailer.ifexists "addIfDifferent" &&
1573 + test_config trailer.separators ":=" &&
1574 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
1575 cat complex_message_body >expected &&
1576 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
@@ -1376,8 +1586,16 @@ test_expect_success 'with command using $ARG' '
1586 '
1587
1588 test_expect_success 'with failing command using $ARG' '
1379 - git config trailer.fix.ifExists "replace" &&
1380 - git config trailer.fix.command "false \$ARG" &&
1589 + test_config trailer.ack.key "Acked-by= " &&
1590 + test_config trailer.fix.command "false \$ARG" &&
1591 + test_config trailer.fix.key "Fixes: " &&
1592 + test_config trailer.fix.ifExists "replace" &&
1593 + test_config trailer.fix.where "after" &&
1594 + test_config trailer.review.key "Reviewed-by:" &&
1595 + test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1596 + test_config trailer.sign.key "Signed-off-by: " &&
1597 + test_config trailer.ifexists "addIfDifferent" &&
1598 + test_config trailer.separators ":=" &&
1599 cat complex_message_body >expected &&
1600 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1601 Fixes: Z
@@ -1392,7 +1610,9 @@ test_expect_success 'with failing command using $ARG' '
1610 '
1611
1612 test_expect_success 'with empty tokens' '
1395 - git config --unset trailer.fix.command &&
1613 + test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1614 + test_config trailer.sign.key "Signed-off-by: " &&
1615 + test_config trailer.ifexists "addIfDifferent" &&
1616 cat >expected <<-EOF &&
1617
1618 Signed-off-by: A U Thor <author@example.com>
@@ -1403,7 +1623,8 @@ test_expect_success 'with empty tokens' '
1623 '
1624
1625 test_expect_success 'with command but no key' '
1406 - git config --unset trailer.sign.key &&
1626 + test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1627 + test_config trailer.ifexists "addIfDifferent" &&
1628 cat >expected <<-EOF &&
1629
1630 sign: A U Thor <author@example.com>
@@ -1414,7 +1635,9 @@ test_expect_success 'with command but no key' '
1635 '
1636
1637 test_expect_success 'with no command and no key' '
1417 - git config --unset trailer.review.key &&
1638 + test_config trailer.review.where "before" &&
1639 + test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1640 + test_config trailer.ifexists "addIfDifferent" &&
1641 cat >expected <<-EOF &&
1642
1643 review: Junio
@@ -1426,6 +1649,8 @@ test_expect_success 'with no command and no key' '
1649 '
1650
1651 test_expect_success 'with cut line' '
1652 + test_config trailer.review.where "before" &&
1653 + test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1654 cat >expected <<-\EOF &&
1655 my subject
1656
@@ -1443,7 +1668,8 @@ test_expect_success 'with cut line' '
1668 '
1669
1670 test_expect_success 'only trailers' '
1446 - git config trailer.sign.command "echo config-value" &&
1671 + test_config trailer.sign.command "echo config-value" &&
1672 + test_config trailer.ifexists "addIfDifferent" &&
1673 cat >expected <<-\EOF &&
1674 existing: existing-value
1675 sign: config-value
@@ -1462,7 +1688,7 @@ test_expect_success 'only trailers' '
1688 '
1689
1690 test_expect_success 'only-trailers omits non-trailer in middle of block' '
1465 - git config trailer.sign.command "echo config-value" &&
1691 + test_config trailer.sign.command "echo config-value" &&
1692 cat >expected <<-\EOF &&
1693 Signed-off-by: nobody <nobody@nowhere>
1694 Signed-off-by: somebody <somebody@somewhere>
@@ -1482,7 +1708,7 @@ test_expect_success 'only-trailers omits non-trailer in middle of block' '
1708 '
1709
1710 test_expect_success 'only input' '
1485 - git config trailer.sign.command "echo config-value" &&
1711 + test_config trailer.sign.command "echo config-value" &&
1712 cat >expected <<-\EOF &&
1713 existing: existing-value
1714 EOF