diff options
author | philwo <philwo@google.com> | 2017-04-24 15:22:29 +0200 |
---|---|---|
committer | Vladimir Moskva <vladmos@google.com> | 2017-04-24 16:52:22 +0200 |
commit | 29aee67c0c95af2840faa47a071b72adf4b734ce (patch) | |
tree | 5742d1b9d4ef0cce8e9815aede5be2700e8c992d /src/test/shell/integration | |
parent | f3fd3a4ad2e7f2878e7d8f71cfb4cb53fc15e04e (diff) |
Bazel: Fix wrong test count shown for failing tests.
Bazel always miscounted the number of passes that a test was run,
resulting in confusing output like this:
philwo@philwo:~/src/errortest$ bazel test //tests:fail
[...]
//tests:fail FAILED in 1 out of 2 in 0.1s
ERROR .tests/fail
It shows "1 out of 2" even though just one pass happened.
With this fix, the output is correct:
philwo@philwo:~/src/errortest$ bazel test //tests:fail
[...]
//tests:fail FAILED in 0.1s
ERROR .tests/fail
Relevant to #2855.
PiperOrigin-RevId: 154043240
Diffstat (limited to 'src/test/shell/integration')
-rw-r--r-- | src/test/shell/integration/BUILD | 6 | ||||
-rwxr-xr-x | src/test/shell/integration/test_test.sh | 71 |
2 files changed, 77 insertions, 0 deletions
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD index 7d9ecb12e9..ba058210ee 100644 --- a/src/test/shell/integration/BUILD +++ b/src/test/shell/integration/BUILD @@ -265,6 +265,12 @@ sh_test( data = [":test-deps"], ) +sh_test( + name = "test_test", + srcs = ["test_test.sh"], + data = [":test-deps"], +) + test_suite( name = "all_tests", visibility = ["//visibility:public"], diff --git a/src/test/shell/integration/test_test.sh b/src/test/shell/integration/test_test.sh new file mode 100755 index 0000000000..91757c4191 --- /dev/null +++ b/src/test/shell/integration/test_test.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eu + +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + + +function test_passing_test_is_reported_correctly() { + mkdir -p tests + cat >tests/BUILD <<'EOF' +sh_test( + name = "success", + size = "small", + srcs = ["success.sh"], +) +EOF + cat >tests/success.sh <<'EOF' +#!/bin/bash + +echo "success.sh is successful" +exit 0 +EOF + chmod +x tests/success.sh + + bazel test --nocache_test_results //tests:success &>$TEST_log \ + || fail "expected success" + expect_not_log "success.sh is successful" + expect_log "^Executed 1 out of 1 test: 1 test passes." +} + +function test_failing_test_is_reported_correctly() { + mkdir -p tests + cat >tests/BUILD <<'EOF' +sh_test( + name = "fail", + size = "small", + srcs = ["fail.sh"], +) +EOF + cat >tests/fail.sh <<'EOF' +#!/bin/bash + +echo "fail.sh is failing" +exit 42 +EOF + chmod +x tests/fail.sh + + bazel test --nocache_test_results //tests:fail &>$TEST_log \ + && fail "expected failure" || /bin/true + expect_log "^//tests:fail[[:space:]]\+FAILED in [[:digit:]]\+\.[[:digit:]]\+s" + expect_log "^Executed 1 out of 1 test: 1 fails" +} + +run_suite "test tests" |