Skip to content

Commit

Permalink
Make sure coverage tests work with --enable_workspace=false
Browse files Browse the repository at this point in the history
A part of #23087

Working towards: #23023

PiperOrigin-RevId: 660758318
Change-Id: Icdfdaed35dc9920c628c4f89ac28ff38ef88a6d3
  • Loading branch information
meteorcloudy authored and copybara-github committed Aug 8, 2024
1 parent 1f4aa9e commit ac7a0ff
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
9 changes: 5 additions & 4 deletions src/test/shell/bazel/bazel_coverage_cc_test_gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,8 @@ EOF
}

function setup_external_cc_target() {
cat > WORKSPACE <<'EOF'
cat > MODULE.bazel <<'EOF'
local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
local_repository(
name = "other_repo",
path = "other_repo",
Expand Down Expand Up @@ -956,7 +957,7 @@ int b(bool what) {
EOF

mkdir -p other_repo
touch other_repo/WORKSPACE
touch other_repo/REPO.bazel

cat > other_repo/BUILD <<'EOF'
cc_library(
Expand Down Expand Up @@ -1012,7 +1013,7 @@ function test_external_cc_target_can_collect_coverage() {
&>"$TEST_log" || fail "Coverage for @other_repo//:t failed"

local coverage_file_path="$(get_coverage_file_path_from_test_log)"
local expected_result_a_cc='SF:external/other_repo/a.cc
local expected_result_a_cc='SF:external/+_repo_rules+other_repo/a.cc
FN:4,_Z1ab
FNDA:1,_Z1ab
FNF:1
Expand Down Expand Up @@ -1078,7 +1079,7 @@ LF:4
end_of_record'

assert_cc_coverage_result "$expected_result_b_cc" "$coverage_file_path"
assert_not_contains "SF:external/other_repo/a.cc" "$coverage_file_path"
assert_not_contains "SF:external/+_repo_rules+other_repo/a.cc" "$coverage_file_path"
}

run_suite "test tests"
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bazel_coverage_cc_test_llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ end_of_record"
}

function setup_external_cc_target() {
cat > WORKSPACE <<'EOF'
cat > MODULE.bazel <<'EOF'
local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
local_repository(
name = "other_repo",
path = "other_repo",
Expand Down Expand Up @@ -278,7 +279,7 @@ int b(bool what) {
EOF

mkdir -p other_repo
touch other_repo/WORKSPACE
touch other_repo/REPO.bazel

cat > other_repo/BUILD <<'EOF'
cc_library(
Expand Down Expand Up @@ -345,7 +346,7 @@ DA:7,1
LH:5
LF:7
end_of_record
SF:external/other_repo/a.cc
SF:external/+_repo_rules+other_repo/a.cc
FN:4,_Z1ab
FNDA:1,_Z1ab
FNF:1
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/bazel_coverage_hermetic_py_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function get_coverage_file_path_from_test_log() {
ending_part="$(sed -n -e '/PASSED/,$p' "$TEST_log")"

local coverage_file_path
coverage_file_path=$(grep -Eo "/[/a-zA-Z0-9\.\_\-]+\.dat$" <<< "$ending_part")
coverage_file_path=$(grep -Eo "/[/a-zA-Z0-9+\.\_\-]+\.dat$" <<< "$ending_part")
[[ -e "$coverage_file_path" ]] || fail "Coverage output file does not exist!"
echo "$coverage_file_path"
}
Expand Down
11 changes: 6 additions & 5 deletions src/test/shell/bazel/bazel_coverage_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,8 @@ end_of_record"
}

function setup_external_java_target() {
cat >> WORKSPACE <<'EOF'
cat >> MODULE.bazel <<'EOF'
local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
local_repository(
name = "other_repo",
path = "other_repo",
Expand Down Expand Up @@ -1246,7 +1247,7 @@ public class Math {
EOF

mkdir -p other_repo
touch other_repo/WORKSPACE
touch other_repo/REPO.bazel

cat > other_repo/BUILD <<'EOF'
java_library(
Expand Down Expand Up @@ -1328,7 +1329,7 @@ DA:6,1
LH:1
LF:2
end_of_record'
local expected_result_collatz="SF:external/other_repo/src/main/com/example/Collatz.java
local expected_result_collatz="SF:external/+_repo_rules+other_repo/src/main/com/example/Collatz.java
FN:3,com/example/Collatz::<init> ()V
FN:6,com/example/Collatz::getCollatzFinal (I)I
FNDA:0,com/example/Collatz::<init> ()V
Expand Down Expand Up @@ -1383,10 +1384,10 @@ LF:2
end_of_record'

assert_coverage_result "$expected_result_math" "$coverage_file_path"
assert_not_contains "SF:external/other_repo/" "$coverage_file_path"
assert_not_contains "SF:external/+_repo_rules+other_repo/" "$coverage_file_path"

assert_coverage_result "$expected_result_math" bazel-out/_coverage/_coverage_report.dat
assert_not_contains "SF:external/other_repo/" bazel-out/_coverage/_coverage_report.dat
assert_not_contains "SF:external/+_repo_rules+other_repo/" bazel-out/_coverage/_coverage_report.dat
}

run_suite "test tests"
2 changes: 1 addition & 1 deletion src/test/shell/bazel/bazel_coverage_starlark_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ source "${CURRENT_DIR}/../integration_test_setup.sh" \
function get_coverage_file_path_from_test_log() {
local ending_part="$(sed -n -e '/PASSED/,$p' "$TEST_log")"

local coverage_file_path=$(grep -Eo "/[/a-zA-Z0-9\.\_\-]+\.dat$" <<< "$ending_part")
local coverage_file_path=$(grep -Eo "/[/a-zA-Z0-9+\.\_\-]+\.dat$" <<< "$ending_part")
[[ -e "$coverage_file_path" ]] || fail "Coverage output file does not exist!"
echo "$coverage_file_path"
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/coverage_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function assert_cc_coverage_result() {
function get_coverage_file_path_from_test_log() {
local ending_part="$(sed -n -e '/PASSED/,$p' "$TEST_log")"

local coverage_file_path=$(grep -Eo "/[/a-zA-Z0-9\.\_\-]+\.dat$" <<< "$ending_part")
local coverage_file_path=$(grep -Eo "/[/a-zA-Z0-9+\.\_\-]+\.dat$" <<< "$ending_part")
[[ -e "$coverage_file_path" ]] || fail "Coverage output file does not exist!"
echo "$coverage_file_path"
}
Expand Down

0 comments on commit ac7a0ff

Please sign in to comment.