Skip to content

Commit 5dd7e60

Browse files
committed
Make CC_CODE_COVERAGE_SCRIPT failures fail tests
If you're editing, or overriding, this script and you introduce and introduce an error, previously this wouldn't fail the test invocation.
1 parent 43cadae commit 5dd7e60

9 files changed

+27
-2
lines changed

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ build --java_language_version=21
5757
build --tool_java_language_version=21
5858
build --tool_java_runtime_version=21
5959

60+
# TODO: Fix tests that fail without this flag
61+
coverage --test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1
62+
6063
# User-specific .bazelrc
6164
try-import %workspace%/user.bazelrc
6265

src/test/shell/bazel/bazel_coverage_hermetic_py_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2121
source "${CURRENT_DIR}/../integration_test_setup.sh" \
2222
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }
2323

24+
# TODO: Fix tests that fail without this flag
25+
add_to_bazelrc "coverage --test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1"
26+
2427
# Fetch hermetic python and register toolchain.
2528
function set_up() {
2629
cat >>MODULE.bazel <<EOF

src/test/shell/bazel/bazel_coverage_java_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ JAVA_TOOLS_PREBUILT_ZIP="$1"; shift
3030

3131
override_java_tools "${RULES_JAVA_REPO_NAME}" "${JAVA_TOOLS_ZIP}" "${JAVA_TOOLS_PREBUILT_ZIP}"
3232

33+
# TODO: Fix tests that fail without this flag
34+
add_to_bazelrc "coverage --test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1"
3335
COVERAGE_GENERATOR_WORKSPACE_FILE="$1"; shift
3436
if [[ "${COVERAGE_GENERATOR_WORKSPACE_FILE}" != "released" ]]; then
3537
COVERAGE_GENERATOR_DIR="$(dirname "$(rlocation $COVERAGE_GENERATOR_WORKSPACE_FILE)")"

src/test/shell/bazel/bazel_coverage_py_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ source "${CURRENT_DIR}/../integration_test_setup.sh" \
2323
source "${CURRENT_DIR}/coverage_helpers.sh" \
2424
|| { echo "coverage_helpers.sh not found!" >&2; exit 1; }
2525

26+
# TODO: Fix tests that fail without this flag
27+
add_to_bazelrc "coverage --test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1"
28+
2629
# Returns 0 if gcov is not installed or if a version before 7.0 was found.
2730
# Returns 1 otherwise.
2831
function is_gcov_missing_or_wrong_version() {

src/test/shell/bazel/bazel_coverage_sh_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ source "${CURRENT_DIR}/../integration_test_setup.sh" \
2323
source "${CURRENT_DIR}/coverage_helpers.sh" \
2424
|| { echo "coverage_helpers.sh not found!" >&2; exit 1; }
2525

26+
# TODO: Fix tests that fail without this flag
27+
add_to_bazelrc "coverage --test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1"
2628

2729
function set_up_sh_test_coverage() {
2830
add_rules_shell "MODULE.bazel"

src/test/shell/bazel/bazel_execlog_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2020
source "${CURRENT_DIR}/../integration_test_setup.sh" \
2121
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }
2222

23+
# TODO: Fix tests that fail without this flag
24+
add_to_bazelrc "coverage --test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1"
25+
2326
function test_dir_depends() {
2427
create_new_workspace
2528
cat > starlark.bzl <<'EOF'

src/test/shell/bazel/remote/build_without_the_bytes_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
4444
source "$(rlocation "io_bazel/src/test/shell/bazel/remote/remote_utils.sh")" \
4545
|| { echo "remote_utils.sh not found!" >&2; exit 1; }
4646

47+
# TODO: Fix tests that fail without this flag
48+
add_to_bazelrc "coverage --test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1"
49+
4750
function set_up() {
4851
start_worker
4952
}

src/test/shell/bazel/remote/remote_execution_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ source "$(rlocation "io_bazel/src/test/shell/bazel/remote_helpers.sh")" \
4646
source "$(rlocation "io_bazel/src/test/shell/bazel/remote/remote_utils.sh")" \
4747
|| { echo "remote_utils.sh not found!" >&2; exit 1; }
4848

49+
# TODO: Fix tests that fail without this flag
50+
add_to_bazelrc "coverage --test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1"
51+
4952
function set_up() {
5053
start_worker
5154
}

tools/test/collect_coverage.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,11 @@ fi
179179
# TODO(bazel-team): cd should be avoided.
180180
cd $ROOT
181181
# Call the C++ code coverage collection script.
182-
if [[ "$CC_CODE_COVERAGE_SCRIPT" ]]; then
183-
eval "${CC_CODE_COVERAGE_SCRIPT}"
182+
if [[ -n "$GENERATE_LLVM_LCOV" && "$CC_CODE_COVERAGE_SCRIPT" ]]; then
183+
if ! eval "${CC_CODE_COVERAGE_SCRIPT}" && test -z "${IGNORE_COVERAGE_COLLECTION_FAILURES:-}"; then
184+
echo "error: coverage collection script failed" >&2
185+
exit 1
186+
fi
184187
fi
185188

186189
if [[ -z "$LCOV_MERGER" ]]; then

0 commit comments

Comments
 (0)