@@ -137,6 +137,12 @@ mark_option_requires_arg () {
137
137
store_arg_to=$2
138
138
}
139
139
140
+ # These functions can be overridden e.g. to output JUnit XML
141
+ start_test_output () { : ; }
142
+ start_test_case_output () { : ; }
143
+ finalize_test_case_output () { : ; }
144
+ finalize_test_output () { : ; }
145
+
140
146
parse_option () {
141
147
local opt=" $1 "
142
148
@@ -196,7 +202,7 @@ parse_option () {
196
202
tee=t
197
203
;;
198
204
--write-junit-xml)
199
- write_junit_xml=t
205
+ . " $TEST_DIRECTORY /test-lib-junit.sh "
200
206
;;
201
207
--stress)
202
208
stress=t ;;
@@ -664,7 +670,7 @@ exec 6<&0
664
670
exec 7>&2
665
671
666
672
_error_exit () {
667
- finalize_junit_xml
673
+ finalize_test_output
668
674
GIT_EXIT_OK=t
669
675
exit 1
670
676
}
@@ -774,35 +780,13 @@ trap '{ code=$?; set +x; } 2>/dev/null; exit $code' INT TERM HUP
774
780
# the test_expect_* functions instead.
775
781
776
782
test_ok_ () {
777
- if test -n " $write_junit_xml "
778
- then
779
- write_junit_xml_testcase " $* "
780
- fi
783
+ finalize_test_case_output ok " $@ "
781
784
test_success=$(( $test_success + 1 ))
782
785
say_color " " " ok $test_count - $@ "
783
786
}
784
787
785
788
test_failure_ () {
786
- if test -n " $write_junit_xml "
787
- then
788
- junit_insert=" <failure message=\" not ok $test_count -"
789
- junit_insert=" $junit_insert $( xml_attr_encode " $1 " ) \" >"
790
- junit_insert=" $junit_insert $( xml_attr_encode \
791
- " $( if test -n " $GIT_TEST_TEE_OUTPUT_FILE "
792
- then
793
- test-tool path-utils skip-n-bytes \
794
- " $GIT_TEST_TEE_OUTPUT_FILE " $GIT_TEST_TEE_OFFSET
795
- else
796
- printf ' %s\n' " $@ " | sed 1d
797
- fi) " ) "
798
- junit_insert=" $junit_insert </failure>"
799
- if test -n " $GIT_TEST_TEE_OUTPUT_FILE "
800
- then
801
- junit_insert=" $junit_insert <system-err>$( xml_attr_encode \
802
- " $( cat " $GIT_TEST_TEE_OUTPUT_FILE " ) " ) </system-err>"
803
- fi
804
- write_junit_xml_testcase " $1 " " $junit_insert "
805
- fi
789
+ finalize_test_case_output failure " $@ "
806
790
test_failure=$(( $test_failure + 1 ))
807
791
say_color error " not ok $test_count - $1 "
808
792
shift
@@ -815,19 +799,13 @@ test_failure_ () {
815
799
}
816
800
817
801
test_known_broken_ok_ () {
818
- if test -n " $write_junit_xml "
819
- then
820
- write_junit_xml_testcase " $* (breakage fixed)"
821
- fi
802
+ finalize_test_case_output fixed " $@ "
822
803
test_fixed=$(( $test_fixed + 1 ))
823
804
say_color error " ok $test_count - $@ # TODO known breakage vanished"
824
805
}
825
806
826
807
test_known_broken_failure_ () {
827
- if test -n " $write_junit_xml "
828
- then
829
- write_junit_xml_testcase " $* (known breakage)"
830
- fi
808
+ finalize_test_case_output broken " $@ "
831
809
test_broken=$(( $test_broken + 1 ))
832
810
say_color warn " not ok $test_count - $@ # TODO known breakage"
833
811
}
@@ -1104,10 +1082,7 @@ test_start_ () {
1104
1082
test_count=$(( $test_count + 1 ))
1105
1083
maybe_setup_verbose
1106
1084
maybe_setup_valgrind
1107
- if test -n " $write_junit_xml "
1108
- then
1109
- junit_start=$( test-tool date getnanos)
1110
- fi
1085
+ start_test_case_output
1111
1086
}
1112
1087
1113
1088
test_finish_ () {
@@ -1158,12 +1133,7 @@ test_skip () {
1158
1133
1159
1134
case " $to_skip " in
1160
1135
t)
1161
- if test -n " $write_junit_xml "
1162
- then
1163
- message=" $( xml_attr_encode " $skipped_reason " ) "
1164
- write_junit_xml_testcase " $1 " \
1165
- " <skipped message=\" $message \" />"
1166
- fi
1136
+ finalize_test_case_output skip " $@ "
1167
1137
1168
1138
say_color skip " ok $test_count # skip $1 ($skipped_reason )"
1169
1139
: true
@@ -1179,53 +1149,6 @@ test_at_end_hook_ () {
1179
1149
:
1180
1150
}
1181
1151
1182
- write_junit_xml () {
1183
- case " $1 " in
1184
- --truncate)
1185
- > " $junit_xml_path "
1186
- junit_have_testcase=
1187
- shift
1188
- ;;
1189
- esac
1190
- printf ' %s\n' " $@ " >> " $junit_xml_path "
1191
- }
1192
-
1193
- xml_attr_encode () {
1194
- printf ' %s\n' " $@ " | test-tool xml-encode
1195
- }
1196
-
1197
- write_junit_xml_testcase () {
1198
- junit_attrs=" name=\" $( xml_attr_encode " $this_test .$test_count $1 " ) \" "
1199
- shift
1200
- junit_attrs=" $junit_attrs classname=\" $this_test \" "
1201
- junit_attrs=" $junit_attrs time=\" $( test-tool \
1202
- date getnanos $junit_start ) \" "
1203
- write_junit_xml " $( printf ' %s\n' \
1204
- " <testcase $junit_attrs >" " $@ " " </testcase>" ) "
1205
- junit_have_testcase=t
1206
- }
1207
-
1208
- finalize_junit_xml () {
1209
- if test -n " $write_junit_xml " && test -n " $junit_xml_path "
1210
- then
1211
- test -n " $junit_have_testcase " || {
1212
- junit_start=$( test-tool date getnanos)
1213
- write_junit_xml_testcase " all tests skipped"
1214
- }
1215
-
1216
- # adjust the overall time
1217
- junit_time=$( test-tool date getnanos $junit_suite_start )
1218
- sed -e " s/\(<testsuite.*\) time=\" [^\" ]*\" /\1/" \
1219
- -e " s/<testsuite [^>]*/& time=\" $junit_time \" /" \
1220
- -e ' /^ *<\/testsuite/d' \
1221
- < " $junit_xml_path " > " $junit_xml_path .new"
1222
- mv " $junit_xml_path .new" " $junit_xml_path "
1223
-
1224
- write_junit_xml " </testsuite>" " </testsuites>"
1225
- write_junit_xml=
1226
- fi
1227
- }
1228
-
1229
1152
test_atexit_cleanup=:
1230
1153
test_atexit_handler () {
1231
1154
# In a succeeding test script 'test_atexit_handler' is invoked
@@ -1248,7 +1171,7 @@ test_done () {
1248
1171
# removed, so the commands can access pidfiles and socket files.
1249
1172
test_atexit_handler
1250
1173
1251
- finalize_junit_xml
1174
+ finalize_test_output
1252
1175
1253
1176
if test -z " $HARNESS_ACTIVE "
1254
1177
then
@@ -1539,22 +1462,7 @@ fi
1539
1462
# in subprocesses like git equals our $PWD (for pathname comparisons).
1540
1463
cd -P " $TRASH_DIRECTORY " || exit 1
1541
1464
1542
- if test -n " $write_junit_xml "
1543
- then
1544
- junit_xml_dir=" $TEST_OUTPUT_DIRECTORY /out"
1545
- mkdir -p " $junit_xml_dir "
1546
- junit_xml_base=${0##*/ }
1547
- junit_xml_path=" $junit_xml_dir /TEST-${junit_xml_base% .sh} .xml"
1548
- junit_attrs=" name=\" ${junit_xml_base% .sh} \" "
1549
- junit_attrs=" $junit_attrs timestamp=\" $( TZ=UTC \
1550
- date +%Y-%m-%dT%H:%M:%S) \" "
1551
- write_junit_xml --truncate " <testsuites>" " <testsuite $junit_attrs >"
1552
- junit_suite_start=$( test-tool date getnanos)
1553
- if test -n " $GIT_TEST_TEE_OUTPUT_FILE "
1554
- then
1555
- GIT_TEST_TEE_OFFSET=0
1556
- fi
1557
- fi
1465
+ start_test_output " $0 "
1558
1466
1559
1467
# Convenience
1560
1468
# A regexp to match 5 and 35 hexdigits
0 commit comments