diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 85b7fece71..90e285a69e 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -293,6 +293,7 @@ tasks: - "-//tests/core/go_proto_library_importmap:importmap_test" - "-//tests/core/go_test:data_test" - "-//tests/core/go_test:pwd_test" + - "-//tests/core/nogo/coverage:coverage_cgo_test" - "-//tests/core/nogo/coverage:coverage_test" - "-//tests/core/nogo/coverage:gen_code_test" - "-//tests/core/race:race_test" # fails on Windows due to upstream bug, see issue #2911 diff --git a/go/tools/builders/compilepkg.go b/go/tools/builders/compilepkg.go index 4a7c98b48b..bcbdb64224 100644 --- a/go/tools/builders/compilepkg.go +++ b/go/tools/builders/compilepkg.go @@ -342,7 +342,7 @@ func compileArchive( if err != nil { return err } - if coverMode != "" { + if coverMode != "" && nogoPath != "" { // Compile original source files, not coverage instrumented, for nogo _, goSrcsNogo, _, err = cgo2(goenv, goSrcsNogo, cgoSrcsNogo, cSrcs, cxxSrcs, objcSrcs, objcxxSrcs, sSrcs, hSrcs, packagePath, packageName, cc, cppFlags, cFlags, cxxFlags, objcFlags, objcxxFlags, ldFlags, cgoExportHPath) if err != nil { diff --git a/tests/core/nogo/coverage/BUILD.bazel b/tests/core/nogo/coverage/BUILD.bazel index a296e07d83..4999efeeea 100644 --- a/tests/core/nogo/coverage/BUILD.bazel +++ b/tests/core/nogo/coverage/BUILD.bazel @@ -1,5 +1,10 @@ load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") +go_bazel_test( + name = "coverage_cgo_test", + srcs = ["coverage_cgo_test.go"], +) + go_bazel_test( name = "coverage_test", srcs = ["coverage_test.go"], @@ -9,8 +14,3 @@ go_bazel_test( name = "gen_code_test", srcs = ["gen_code_test.go"], ) - -go_bazel_test( - name = "coverage_cgo_test", - srcs = ["coverage_cgo_test.go"], -) diff --git a/tests/core/nogo/coverage/coverage_cgo_test.go b/tests/core/nogo/coverage/coverage_cgo_test.go index 2fdf44044c..3458b2ea63 100644 --- a/tests/core/nogo/coverage/coverage_cgo_test.go +++ b/tests/core/nogo/coverage/coverage_cgo_test.go @@ -27,16 +27,16 @@ func TestMain(m *testing.M) { load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test", "nogo") go_library( - name = "foo", + name = "foo_cgo", cgo = True, - srcs = ["foo.go"], - importpath = "foo" + srcs = ["foo_cgo.go"], + importpath = "foo_cgo" ) go_test( - name = "foo_test", - srcs = ["foo_test.go"], - embed = [":foo"] + name = "foo_cgo_test", + srcs = ["foo_cgo_test.go"], + embed = [":foo_cgo"] ) nogo( @@ -44,22 +44,22 @@ nogo( deps = ["//noinit"], visibility = ["//visibility:public"], ) --- foo.go -- -package foo +-- foo_cgo.go -- +package foo_cgo import "C" -func Foo() string { - return "foo" +func FooCgo() string { + return "foo_cgo" } --- foo_test.go -- -package foo +-- foo_cgo_test.go -- +package foo_cgo import "testing" -func TestFoo(t *testing.T) { - if actual, expected := Foo(), "foo"; actual != expected { - t.Errorf("Foo() should return foo") +func TestFooCgo(t *testing.T) { + if actual, expected := FooCgo(), "foo_cgo"; actual != expected { + t.Errorf("FooCgo() should return foo_cgo") } } -- noinit/BUILD.bazel -- @@ -117,7 +117,7 @@ func run(pass *analysis.Pass) (interface{}, error) { } func TestNogoWithCoverageAndCgo(t *testing.T) { - if out, err := bazel_testing.BazelOutput("coverage", "//:foo_test"); err != nil { + if out, err := bazel_testing.BazelOutput("coverage", "//:foo_cgo_test"); err != nil { println(string(out)) t.Fatal(err) }