From eb067ea88749a5635cc8ee8954cde2b767f1eb61 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 22 Feb 2018 02:47:42 -0800 Subject: [PATCH] Fix test name in fallback xml when --run_under is used. When --run_under is used, the run-under wrapper will be injected in front of the normal test command line. So, it's incorrect to use the beginning of the command line to infer the test name. However, we can always get the underlying test executable with the TEST_BINARY environmental variable. Rename TEST_NAME to EXE to avoid future confusion. Fixes https://github.com/bazelbuild/bazel/issues/4588. Change-Id: I6fd05cca5e5441c13ee16290c4028ec84adec983 PiperOrigin-RevId: 186590311 --- src/test/shell/bazel/bazel_test_test.sh | 12 ++++++++++++ tools/test/test-setup.sh | 19 ++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/test/shell/bazel/bazel_test_test.sh b/src/test/shell/bazel/bazel_test_test.sh index 389bc91b143fa7..edc67744589cec 100755 --- a/src/test/shell/bazel/bazel_test_test.sh +++ b/src/test/shell/bazel/bazel_test_test.sh @@ -469,6 +469,18 @@ EOF expect_log_once "testcase" expect_log_once "duration=\"[0-9]\+\"" expect_log "name=\"dir/fail\"" + + bazel test //dir:all --run_under=exec &> $TEST_log && fail "should have failed" || true + cp bazel-testlogs/dir/success/test.xml $TEST_log + expect_log "errors=\"0\"" + expect_log_once "testcase" + expect_log_once "duration=\"[0-9]\+\"" + expect_log "name=\"dir/success\"" + cp bazel-testlogs/dir/fail/test.xml $TEST_log + expect_log "errors=\"1\"" + expect_log_once "testcase" + expect_log_once "duration=\"[0-9]\+\"" + expect_log "name=\"dir/fail\"" } function test_detailed_test_summary() { diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh index 002edb8bdfdcc5..bb411c92683d80 100755 --- a/tools/test/test-setup.sh +++ b/tools/test/test-setup.sh @@ -160,6 +160,7 @@ function write_xml_output_file { local errors=0 local error_msg= local signal="${1-}" + local test_name= if [ -n "${XML_OUTPUT_FILE-}" -a ! -f "${XML_OUTPUT_FILE-}" ]; then # Create a default XML output file if the test runner hasn't generated it if [ -n "${signal}" ]; then @@ -173,16 +174,17 @@ function write_xml_output_file { errors=1 error_msg="" fi + test_name="${TEST_BINARY#./}" # Ensure that test shards have unique names in the xml output. if [[ -n "${TEST_TOTAL_SHARDS+x}" ]] && ((TEST_TOTAL_SHARDS != 0)); then ((shard_num=TEST_SHARD_INDEX+1)) - TEST_NAME="$TEST_NAME"_shard_"$shard_num"/"$TEST_TOTAL_SHARDS" + test_name="${test_name}"_shard_"$shard_num"/"$TEST_TOTAL_SHARDS" fi cat <${XML_OUTPUT_FILE} - - ${error_msg} + + ${error_msg} @@ -198,18 +200,17 @@ EOF PATH=".:$PATH" if [ -z "$COVERAGE_DIR" ]; then - TEST_NAME=${1#./} + EXE="$1" shift else - TEST_NAME=${2#./} + EXE="$2" fi -if is_absolute "$TEST_NAME" ; then - TEST_PATH="${TEST_NAME}" +if is_absolute "$EXE"; then + TEST_PATH="$EXE" else - TEST_PATH="$(rlocation $TEST_WORKSPACE/$TEST_NAME)" + TEST_PATH="$(rlocation $TEST_WORKSPACE/$EXE)" fi -[[ -n "$RUNTEST_PRESERVE_CWD" ]] && EXE="${TEST_NAME}" exitCode=0 signals="$(trap -l | sed -E 's/[0-9]+\)//g')"