diff options
author | 2017-09-25 22:56:01 +0200 | |
---|---|---|
committer | 2017-09-26 12:30:55 +0200 | |
commit | 494910bc64fee68ce981619225e45b05a8adef14 (patch) | |
tree | 5cc1147d0a18af51d9fb096e58a9df20b4249352 /src/test/shell | |
parent | 65a5119a9c8a9cc2aa2f056ed6f37b41ecf5deb4 (diff) |
BEP: Add coverage data to test_result
Include the coverage data file into the list of files repeorted in the
test_result event in the BEP.
Change-Id: Ia7b653addd5589268ce919b3e0349371dbc18bf2
PiperOrigin-RevId: 169956864
Diffstat (limited to 'src/test/shell')
-rwxr-xr-x | src/test/shell/bazel/bazel_coverage_test.sh | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/src/test/shell/bazel/bazel_coverage_test.sh b/src/test/shell/bazel/bazel_coverage_test.sh index c651f50580..25e20dc6c2 100755 --- a/src/test/shell/bazel/bazel_coverage_test.sh +++ b/src/test/shell/bazel/bazel_coverage_test.sh @@ -66,7 +66,8 @@ int main(void) { } EOF - bazel coverage --test_output=all //:t &>$TEST_log || fail "Coverage for //:t failed" + bazel coverage --test_output=all --build_event_text_file=bep.txt //:t \ + &>$TEST_log || fail "Coverage for //:t failed" ending_part=$(sed -n -e '/PASSED/,$p' $TEST_log) @@ -78,6 +79,63 @@ EOF # Check if the only branch in a() has correct coverage: assert_contains "^DA:5,1$" "$coverage_file_path" # true branch should be taken assert_contains "^DA:7,0$" "$coverage_file_path" # false branch should not be + + # Verify the files are reported correctly in the build event protocol. + assert_contains 'name: "test.lcov"' bep.txt + + # Verify that this is also true for cached coverage actions. + bazel coverage --test_output=all --build_event_text_file=bep.txt //:t \ + &>$TEST_log || fail "Coverage for //:t failed" + expect_log '//:t.*cached' + assert_contains 'name: "test.lcov"' bep.txt +} + +function test_failed_coverage() { + if [[ ! -x /usr/bin/lcov ]]; then + echo "lcov not installed. Skipping test." + return + fi + + cat << EOF > BUILD +cc_library( + name = "a", + srcs = ["a.cc"], + hdrs = ["a.h"], +) + +cc_test( + name = "t", + srcs = ["t.cc"], + deps = [":a"], +) +EOF + + cat << EOF > a.h +int a(); +EOF + + cat << EOF > a.cc +#include "a.h" + +int a() { + return 1; +} +EOF + + cat << EOF > t.cc +#include <stdio.h> +#include "a.h" + +int main(void) { + return a(); +} +EOF + + bazel coverage --test_output=all --build_event_text_file=bep.txt //:t \ + &>$TEST_log && fail "Expected test failure" || : + + # Verify that coverage data is still reported. + assert_contains 'name: "test.lcov"' bep.txt } function test_java_test_coverage() { |