aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar Benjamin Peterson <bp@benjamin.pe>2017-06-28 14:24:03 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-06-28 15:27:29 +0200
commit218c36341b2911002164c6ccac9decf4fed9e380 (patch)
treeefa93bb1a2788e3884f0be821084828636bcb311 /src/test/shell
parent224a0da597ddae822a0a9b2ae314a25fa6481bfe (diff)
Ensure shards of the same test have unique names in the fallback xml
test-setup.sh currently uses the test target name as the "name" attribute in the xml output's "testcase" element. This ensures names in the xml are unique across the workspace for unsharded tests. However, sharded tests all end up with the same "name" attribute. This angers some junitxml processing tools, which can be quite persnickity about uniqueness. Let's generate unique test names of the form "mytest_shard_N/M" for sharded tests. Change-Id: I6ea82f56846b88449da977dc6629a73b695a485e PiperOrigin-RevId: 160397341
Diffstat (limited to 'src/test/shell')
-rwxr-xr-xsrc/test/shell/bazel/bazel_test_test.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/shell/bazel/bazel_test_test.sh b/src/test/shell/bazel/bazel_test_test.sh
index 9f0c4614ef..8608147764 100755
--- a/src/test/shell/bazel/bazel_test_test.sh
+++ b/src/test/shell/bazel/bazel_test_test.sh
@@ -300,6 +300,37 @@ EOF
[ -s $xml_log ] || fail "$xml_log was not present after test"
}
+# Check that fallback xml output is correctly generated for sharded tests.
+function test_xml_fallback_for_sharded_test() {
+ mkdir -p dir
+
+ cat <<EOF > dir/test.sh
+#!/bin/sh
+exit \$((TEST_SHARD_INDEX == 1))
+EOF
+
+ chmod +x dir/test.sh
+
+ cat <<EOF > dir/BUILD
+sh_test(
+ name = "test",
+ srcs = [ "test.sh" ],
+ shard_count = 2,
+)
+EOF
+
+ bazel test //dir:test && fail "should have failed" || true
+
+ cp bazel-testlogs/dir/test/shard_1_of_2/test.xml $TEST_log
+ expect_log "errors=\"0\""
+ expect_log_once "testcase"
+ expect_log "name=\"dir/test_shard_1/2\""
+ cp bazel-testlogs/dir/test/shard_2_of_2/test.xml $TEST_log
+ expect_log "errors=\"1\""
+ expect_log_once "testcase"
+ expect_log "name=\"dir/test_shard_2/2\""
+}
+
# Simple test that we actually enforce testonly, see #1923.
function test_testonly_is_enforced() {
mkdir -p testonly