Skip to content

Commit

Permalink
tests/core/coverage: migrate to go_bazel_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Conrod committed Nov 20, 2019
1 parent c6c3124 commit 78605cb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 140 deletions.
98 changes: 0 additions & 98 deletions tests/core/coverage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
10 changes: 2 additions & 8 deletions tests/core/coverage/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------

Expand Down
11 changes: 0 additions & 11 deletions tests/core/coverage/a.go

This file was deleted.

11 changes: 0 additions & 11 deletions tests/core/coverage/b.go

This file was deleted.

9 changes: 0 additions & 9 deletions tests/core/coverage/c.go

This file was deleted.

29 changes: 26 additions & 3 deletions tests/core/coverage/coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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
Expand Down Expand Up @@ -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:",
Expand All @@ -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)
}
}

0 comments on commit 78605cb

Please sign in to comment.