diff --git a/tests/core/coverage/BUILD.bazel b/tests/core/coverage/BUILD.bazel index 9529321dd5..35711c7f70 100644 --- a/tests/core/coverage/BUILD.bazel +++ b/tests/core/coverage/BUILD.bazel @@ -8,104 +8,6 @@ go_bazel_test( srcs = ["coverage_test.go"], ) -# bazel_test( -# name = "coverage_test_test", -# args = ["--instrumentation_filter=-coverage:b"], -# check = """ -# if ! grep -q '^coverage: 50.0% of statements' "bazel-testlogs/$RULES_GO_OUTPUT/coverage_test/test.log"; then -# echo "error: no coverage output found in test log file" >&2 -# exit 1 -# fi - -# data_file=bazel-testlogs/$RULES_GO_OUTPUT/coverage_test/coverage.dat -# if [ ! -e "$data_file" ]; then -# echo "error: $data_file: does not exist" >&2 -# exit 1 -# fi -# if [ ! -s "$data_file" ]; then -# echo "warning: $data_file: has size zero. Bazel may have trashed it with lcov." >&2 -# echo "skipping rest of test" >&2 -# exit 0 -# fi - -# function check_file_included { -# if ! grep -q "$1" "$data_file"; then -# echo "error: coverage data not found for $1" >&2 -# exit 1 -# fi -# } -# function check_file_excluded { -# if grep -q "$1" "$data_file"; then -# echo "error: coverage data found for $1, but it should be excluded" >&2 -# exit 1 -# fi -# } - -# included_files=( -# 'github.com/bazelbuild/rules_go/tests/core/coverage/a/a.go:' -# 'github.com/bazelbuild/rules_go/tests/core/coverage/c/c.go:' -# ) -# excluded_files=( -# 'github.com/bazelbuild/rules_go/tests/core/coverage/b/b.go:' -# ) -# for i in "${included_files[@]}"; do -# check_file_included "$i" -# done -# for i in "${excluded_files[@]}"; do -# check_file_excluded "$i" -# done -# """, -# command = "coverage", -# targets = [":coverage_test"], -# ) - -# go_test( -# name = "coverage_test", -# srcs = ["coverage_test.go"], -# embed = [":a"], -# tags = ["manual"], -# ) - -# go_library( -# name = "a", -# srcs = ["a.go"], -# importpath = "github.com/bazelbuild/rules_go/tests/core/coverage/a", -# deps = [":b"], -# ) - -# go_library( -# name = "b", -# srcs = ["b.go"], -# importpath = "github.com/bazelbuild/rules_go/tests/core/coverage/b", -# deps = [":c"], -# ) - -# go_library( -# name = "c", -# srcs = ["c.go"], -# importpath = "github.com/bazelbuild/rules_go/tests/core/coverage/c", -# ) - -# bazel_test( -# name = "cross_cover_test_test", -# args = [ -# "--collect_code_coverage", -# "--instrumentation_filter=-coverage:b", -# ], -# command = "build", -# targets = [":cross_cover_test"], -# ) - -# go_test( -# name = "cross_cover_test", -# srcs = ["coverage_test.go"], -# embed = [":a"], -# goarch = "386", -# goos = "linux", -# pure = "on", -# tags = ["manual"], -# ) - go_bazel_test( name = "binary_coverage_test", srcs = ["binary_coverage_test.go"], diff --git a/tests/core/coverage/README.rst b/tests/core/coverage/README.rst index 4abf7305cc..aadc5fa9ae 100644 --- a/tests/core/coverage/README.rst +++ b/tests/core/coverage/README.rst @@ -3,20 +3,14 @@ coverage functionality ====================== -coverage_test_test ------------------- +coverage_test +------------- Checks that ``bazel coverage`` on a ``go_test`` produces reasonable output. Libraries referenced by the test that pass ``--instrumentation_filter`` should have coverage data. Library excluded with ``--instrumentatiuon_filter`` should not have coverage data. -coverdata_aspect_test_test --------------------------- - -Checks that the ``coverdata`` library is compiled in the same mode as the -test that depends on it. - binary_coverage_test -------------------- diff --git a/tests/core/coverage/a.go b/tests/core/coverage/a.go deleted file mode 100644 index 5df70972c4..0000000000 --- a/tests/core/coverage/a.go +++ /dev/null @@ -1,11 +0,0 @@ -package a - -import "github.com/bazelbuild/rules_go/tests/core/coverage/b" - -func ALive() int { - return b.BLive() -} - -func ADead() int { - return b.BDead() -} diff --git a/tests/core/coverage/b.go b/tests/core/coverage/b.go deleted file mode 100644 index 1ec411eec5..0000000000 --- a/tests/core/coverage/b.go +++ /dev/null @@ -1,11 +0,0 @@ -package b - -import "github.com/bazelbuild/rules_go/tests/core/coverage/c" - -func BLive() int { - return c.CLive() -} - -func BDead() int { - return c.CDead() -} diff --git a/tests/core/coverage/c.go b/tests/core/coverage/c.go deleted file mode 100644 index fc9570ea8b..0000000000 --- a/tests/core/coverage/c.go +++ /dev/null @@ -1,9 +0,0 @@ -package c - -func CLive() int { - return 12 -} - -func CDead() int { - return 34 -} diff --git a/tests/core/coverage/coverage_test.go b/tests/core/coverage/coverage_test.go index aff1c5c076..6b53f78a18 100644 --- a/tests/core/coverage/coverage_test.go +++ b/tests/core/coverage/coverage_test.go @@ -31,9 +31,20 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_test( name = "a_test", + srcs = ["a_test.go"], embed = [":a"], ) +go_test( + name = "a_test_cross", + srcs = ["a_test.go"], + embed = [":a"], + goarch = "386", + goos = "linux", + pure = "on", + tags = ["manual"], +) + go_library( name = "a", srcs = ["a.go"], @@ -54,6 +65,15 @@ go_library( importpath = "example.com/coverage/c", ) +-- a_test.go -- +package a + +import "testing" + +func TestA(t *testing.T) { + ALive() +} + -- a.go -- package a @@ -105,9 +125,6 @@ func TestCoverage(t *testing.T) { if err != nil { t.Fatal(err) } - if len(coverageData) == 0 { - t.Skipf("%s is empty. Bazel may have trashed it with lcov.", coveragePath) - } for _, include := range []string{ "example.com/coverage/a/a.go:", "example.com/coverage/c/c.go:", @@ -124,3 +141,9 @@ func TestCoverage(t *testing.T) { } } } + +func TestCrossBuild(t *testing.T) { + if err := bazel_testing.RunBazel("build", "--collect_code_coverage", "--instrumentation_filter=-//:b", "//:a_test_cross"); err != nil { + t.Fatal(err) + } +}