Skip to content

Commit

Permalink
Remove cgo from coverage test (#1483)
Browse files Browse the repository at this point in the history
I no longer believe there is a way to consistently collect coverage
data for C libraries with Bazel. This test kept getting stuck in good
or bad states, and its success depended on other tests that were
running with it and tools (lcov) installed on the system.

cgo coverage won't be supported until this is fixed in Bazel.

Also:

Deleted coverage_bin_test since it's expensive to run and provides
very little value.
  • Loading branch information
jayconrod authored and Jay Conrod committed May 2, 2018
1 parent b6413bb commit a4586a1
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 106 deletions.
53 changes: 4 additions & 49 deletions tests/core/coverage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ function check_file_excluded {
included_files=(
'github.com/bazelbuild/rules_go/tests/core/coverage/a/a.go:'
'github.com/bazelbuild/rules_go/tests/core/coverage/c/c.go:'
'github.com/bazelbuild/rules_go/tests/core/coverage/c/c_cgo.go:'
)
excluded_files=(
'github.com/bazelbuild/rules_go/tests/core/coverage/b/b.go:'
'github.com/bazelbuild/rules_go/tests/core/coverage/b/b_cgo.go:'
'\.cgo1\.go:'
)
for i in "${included_files[@]}"; do
check_file_included "$i"
Expand All @@ -55,10 +52,7 @@ done
"--instrumentation_filter=-coverage:b",
"--nocache_test_results",
],
targets = select({
"@io_bazel_rules_go//go/platform:darwin": [],
"//conditions:default": [":coverage_test"],
}),
targets = [":coverage_test"],
)

go_test(
Expand All @@ -68,61 +62,22 @@ go_test(
tags = ["manual"],
)

bazel_test(
name = "coverage_bin_test",
check = """
no_tests_found=4
if [ "$result" -ne "$no_tests_found" ]; then
echo "error: unexpected bazel exit code: want $no_tests_found, got $result" >&2
exit 1
fi
result=0
""",
command = "coverage",
targets = select({
# TODO(bazelbuild/bazel#5128): skip coverage test on Darwin. The target
# includes cgo, which gets instrumented, and Bazel reports link errors
# for instrumented C code on Darwin.
"@io_bazel_rules_go//go/platform:darwin": [],
"//conditions:default": [":coverage_bin"],
}),
)

go_binary(
name = "coverage_bin",
srcs = ["coverage_bin.go"],
deps = [":a"],
tags = ["manual"],
)

go_library(
name = "a",
srcs = [
"a.go",
"a_cgo.go",
],
cgo = True,
srcs = ["a.go"],
deps = [":b"],
importpath = "github.com/bazelbuild/rules_go/tests/core/coverage/a",
)

go_library(
name = "b",
srcs = [
"b.go",
"b_cgo.go",
],
cgo = True,
srcs = ["b.go"],
deps = [":c"],
importpath = "github.com/bazelbuild/rules_go/tests/core/coverage/b",
)

go_library(
name = "c",
srcs = [
"c.go",
"c_cgo.go",
],
cgo = True,
srcs = ["c.go"],
importpath = "github.com/bazelbuild/rules_go/tests/core/coverage/c",
)
6 changes: 0 additions & 6 deletions tests/core/coverage/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,3 @@ 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.

coverage_bin_test
-----------------

Checks that ``bazel coverage`` on a ``go_binary`` causes Bazel to exit with
status 4 (no tests found) instead of some other failure.
14 changes: 0 additions & 14 deletions tests/core/coverage/a_cgo.go

This file was deleted.

14 changes: 0 additions & 14 deletions tests/core/coverage/b_cgo.go

This file was deleted.

15 changes: 0 additions & 15 deletions tests/core/coverage/c_cgo.go

This file was deleted.

7 changes: 0 additions & 7 deletions tests/core/coverage/coverage_bin.go

This file was deleted.

1 change: 0 additions & 1 deletion tests/core/coverage/coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ import "testing"

func TestLive(t *testing.T) {
ALive()
ACgoLive()
}

0 comments on commit a4586a1

Please sign in to comment.