Skip to content

Commit 16de035

Browse files
keithcopybara-github
authored andcommitted
Fix bazel coverage false negative
Previously this short circuit meant the tests weren't actually run, and they would always exit 0, in the case the test rule didn't set the lcov related attributes. More context: bazelbuild#13978 Closes bazelbuild#14807. RELNOTES: Fixed an issue where Bazel could erroneously report a test passes in coverage mode without actually running the test. PiperOrigin-RevId: 428756211
1 parent 464f5d5 commit 16de035

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/test/shell/bazel/bazel_coverage_starlark_test.sh

+27
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ EOF
5858
|| fail "Coverage run failed but should have succeeded."
5959
}
6060

61+
function test_starlark_rule_without_lcov_merger_failing_test() {
62+
cat <<EOF > rules.bzl
63+
def _impl(ctx):
64+
executable = ctx.actions.declare_file(ctx.attr.name)
65+
ctx.actions.write(executable, "exit 1", is_executable = True)
66+
return [
67+
DefaultInfo(
68+
executable = executable,
69+
)
70+
]
71+
custom_test = rule(
72+
implementation = _impl,
73+
test = True,
74+
)
75+
EOF
76+
77+
cat <<EOF > BUILD
78+
load(":rules.bzl", "custom_test")
79+
80+
custom_test(name = "foo_test")
81+
EOF
82+
if bazel coverage //:foo_test > $TEST_log; then
83+
fail "Coverage run succeeded but should have failed."
84+
fi
85+
}
86+
87+
6188
function test_starlark_rule_with_custom_lcov_merger() {
6289

6390
cat <<EOF > lcov_merger.sh

tools/test/collect_coverage.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ if [[ -z "$LCOV_MERGER" ]]; then
3939
# it.
4040
# TODO(cmita): Improve this situation so this early-exit isn't required.
4141
touch $COVERAGE_OUTPUT_FILE
42-
exit 0
42+
# Execute the test.
43+
"$@"
44+
TEST_STATUS=$?
45+
exit "$TEST_STATUS"
4346
fi
4447

4548
function resolve_links() {

0 commit comments

Comments
 (0)