Skip to content

Commit 344e8f8

Browse files
brentleyjoneskeith
andauthored
Fix bazel coverage false negative (#14836)
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: #13978 Closes #14807. RELNOTES: Fixed an issue where Bazel could erroneously report a test passes in coverage mode without actually running the test. PiperOrigin-RevId: 428756211 (cherry picked from commit 16de035) Co-authored-by: Keith Smiley <keithbsmiley@gmail.com>
1 parent 59384dd commit 344e8f8

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/test/shell/bazel/bazel_coverage_starlark_test.sh

Lines changed: 27 additions & 0 deletions
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

Lines changed: 4 additions & 1 deletion
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)