aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar hlopko <hlopko@google.com>2017-04-05 11:55:38 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-04-05 15:22:41 +0200
commitd16f8e063d205743391bcb2a10f615781b0b087e (patch)
tree78b0a0fae084c560cc9dec63a9fc5b63dec79642 /src
parent3cb4ceab9b6ae57b9a105e4fba1aa4509f872430 (diff)
XML-escape test failure message in junit test results file
This cl does poor man's xml attribute escaping to fix http://ci.bazel.io/job/bazel-tests/BAZEL_VERSION=HEAD,PLATFORM_NAME=linux-x86_64/675/testReport/test/xml/_failed_to_read_/ RELNOTES: NONE. PiperOrigin-RevId: 152244340
Diffstat (limited to 'src')
-rw-r--r--src/test/shell/unittest.bash4
-rwxr-xr-xsrc/test/shell/unittest_test.sh5
2 files changed, 6 insertions, 3 deletions
diff --git a/src/test/shell/unittest.bash b/src/test/shell/unittest.bash
index 913389bb81..88e1617700 100644
--- a/src/test/shell/unittest.bash
+++ b/src/test/shell/unittest.bash
@@ -781,7 +781,9 @@ function run_suite() {
# end marker in CDATA cannot be escaped, we need to split the CDATA sections
log=$(cat $TEST_TMPDIR/__log | sed 's/]]>/]]>]]&gt;<![CDATA[/g')
fail_msg=$(cat $TEST_TMPDIR/__fail 2> /dev/null || echo "No failure message")
- testcase_tag="<testcase name=\"$TEST_name\" status=\"run\" time=\"$run_time\" classname=\"\"><error message=\"$fail_msg\"><![CDATA[$log]]></error></testcase>"
+ # Replacing '&' with '&amp;', '<' with '&lt;', '>' with '&gt;', and '"' with '&quot;'
+ escaped_fail_msg=$(echo $fail_msg | sed 's/&/\&amp;/g' | sed 's/</\&lt;/g' | sed 's/>/\&gt;/g' | sed 's/"/\&quot;/g')
+ testcase_tag="<testcase name=\"$TEST_name\" status=\"run\" time=\"$run_time\" classname=\"\"><error message=\"$escaped_fail_msg\"><![CDATA[$log]]></error></testcase>"
fi
if [[ "$TEST_verbose" == "true" ]]; then
diff --git a/src/test/shell/unittest_test.sh b/src/test/shell/unittest_test.sh
index 2799aad1cb..638b664989 100755
--- a/src/test/shell/unittest_test.sh
+++ b/src/test/shell/unittest_test.sh
@@ -54,7 +54,7 @@ XML_OUTPUT_FILE=${TEST_TMPDIR}/dummy.xml
source ${DIR}/unittest.bash
function test_thing() {
- fail "I'm a failure"
+ fail "I'm a failure with <>&\" escaped symbols"
}
run_suite "thing tests"
@@ -62,7 +62,8 @@ EOF
chmod +x thing.sh
./thing.sh &> $TEST_log && fail "thing.sh should fail"
expect_not_log "__fail: No such file or directory"
- assert_contains "I'm a failure." ${TEST_TMPDIR}/dummy.xml
+ assert_contains "message=\"I'm a failure with &lt;&gt;&amp;&quot; escaped symbols\"" ${TEST_TMPDIR}/dummy.xml
+ assert_contains "I'm a failure with <>&\" escaped symbols" ${TEST_TMPDIR}/dummy.xml
assert_contains 'errors="1"' ${TEST_TMPDIR}/dummy.xml
}