tg.grepStderrNot(`os.Stat .* no such file or directory`, "unexpected stat of archive file")
}
-func TestCoverageWithCgo(t *testing.T) {
- skipIfGccgo(t, "gccgo has no cover tool")
- tooSlow(t)
- if !canCgo {
- t.Skip("skipping because cgo not enabled")
- }
-
- for _, dir := range []string{"cgocover", "cgocover2", "cgocover3", "cgocover4"} {
- t.Run(dir, func(t *testing.T) {
- tg := testgo(t)
- tg.parallel()
- defer tg.cleanup()
- tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
- tg.run("test", "-short", "-cover", dir)
- data := tg.getStdout() + tg.getStderr()
- checkCoverage(tg, data)
- })
- }
-}
-
-func TestCgoAsmError(t *testing.T) {
- if !canCgo {
- t.Skip("skipping because cgo not enabled")
- }
-
- tg := testgo(t)
- tg.parallel()
- defer tg.cleanup()
- tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
- tg.runFail("build", "cgoasm")
- tg.grepBoth("package using cgo has Go assembly file", "did not detect Go assembly file")
-}
-
func TestCgoDependsOnSyscall(t *testing.T) {
if testing.Short() {
t.Skip("skipping test that removes $GOROOT/pkg/*_race in short mode")
--- /dev/null
+[!cgo] skip
+
+# Test that cgo package can't contain a go assembly file.
+
+# Ensure the build fails and reports that the package has a Go assembly file.
+! go build cgoasm
+stderr 'package using cgo has Go assembly file'
+
+-- cgoasm/p.go --
+package p
+
+/*
+// hi
+*/
+import "C"
+
+func F() {}
+-- cgoasm/p.s --
+TEXT asm(SB),$0
+ RET
+
--- /dev/null
+[!cgo] skip
+[gccgo] skip # gccgo has no cover tool
+
+# Test coverage on cgo code.
+
+go test -short -cover cgocover
+stdout 'coverage:.*[1-9][0-9.]+%'
+! stderr '[^0-9]0\.0%'
+
+-- cgocover/p.go --
+package p
+
+/*
+void
+f(void)
+{
+}
+*/
+import "C"
+
+var b bool
+
+func F() {
+ if b {
+ for {
+ }
+ }
+ C.f()
+}
+-- cgocover/p_test.go --
+package p
+
+import "testing"
+
+func TestF(t *testing.T) {
+ F()
+}
--- /dev/null
+[!cgo] skip
+[gccgo] skip # gccgo has no cover tool
+
+# Test coverage on cgo code. This test case includes an
+# extra empty non-cgo file in the package being checked.
+
+go test -short -cover cgocover4
+stdout 'coverage:.*[1-9][0-9.]+%'
+! stderr '[^0-9]0\.0%'
+
+-- cgocover4/notcgo.go --
+package p
+-- cgocover4/p.go --
+package p
+
+/*
+void
+f(void)
+{
+}
+*/
+import "C"
+
+var b bool
+
+func F() {
+ if b {
+ for {
+ }
+ }
+ C.f()
+}
+-- cgocover4/x_test.go --
+package p_test
+
+import (
+ . "cgocover4"
+ "testing"
+)
+
+func TestF(t *testing.T) {
+ F()
+}
\ No newline at end of file
--- /dev/null
+[!cgo] skip
+[gccgo] skip # gccgo has no cover tool
+
+# Test coverage on cgo code. This test case has an external
+# test that tests the code and an in-package test file with
+# no test cases.
+
+go test -short -cover cgocover3
+stdout 'coverage:.*[1-9][0-9.]+%'
+! stderr '[^0-9]0\.0%'
+
+-- cgocover3/p.go --
+package p
+
+/*
+void
+f(void)
+{
+}
+*/
+import "C"
+
+var b bool
+
+func F() {
+ if b {
+ for {
+ }
+ }
+ C.f()
+}
+-- cgocover3/p_test.go --
+package p
+-- cgocover3/x_test.go --
+package p_test
+
+import (
+ . "cgocover3"
+ "testing"
+)
+
+func TestF(t *testing.T) {
+ F()
+}
\ No newline at end of file
--- /dev/null
+[!cgo] skip
+[gccgo] skip # gccgo has no cover tool
+
+# Test cgo coverage with an external test.
+
+go test -short -cover cgocover2
+stdout 'coverage:.*[1-9][0-9.]+%'
+! stderr '[^0-9]0\.0%'
+
+-- cgocover2/p.go --
+package p
+
+/*
+void
+f(void)
+{
+}
+*/
+import "C"
+
+var b bool
+
+func F() {
+ if b {
+ for {
+ }
+ }
+ C.f()
+}
+-- cgocover2/x_test.go --
+package p_test
+
+import (
+ . "cgocover2"
+ "testing"
+)
+
+func TestF(t *testing.T) {
+ F()
+}
\ No newline at end of file
+++ /dev/null
-package p
-
-/*
-// hi
-*/
-import "C"
-
-func F() {}
+++ /dev/null
-TEXT asm(SB),$0
- RET
+++ /dev/null
-package p
-
-/*
-void
-f(void)
-{
-}
-*/
-import "C"
-
-var b bool
-
-func F() {
- if b {
- for {
- }
- }
- C.f()
-}
+++ /dev/null
-package p
-
-import "testing"
-
-func TestF(t *testing.T) {
- F()
-}
+++ /dev/null
-package p
-
-/*
-void
-f(void)
-{
-}
-*/
-import "C"
-
-var b bool
-
-func F() {
- if b {
- for {
- }
- }
- C.f()
-}
+++ /dev/null
-package p_test
-
-import (
- . "cgocover2"
- "testing"
-)
-
-func TestF(t *testing.T) {
- F()
-}
+++ /dev/null
-package p
-
-/*
-void
-f(void)
-{
-}
-*/
-import "C"
-
-var b bool
-
-func F() {
- if b {
- for {
- }
- }
- C.f()
-}
+++ /dev/null
-package p_test
-
-import (
- . "cgocover3"
- "testing"
-)
-
-func TestF(t *testing.T) {
- F()
-}
+++ /dev/null
-package p
-
-/*
-void
-f(void)
-{
-}
-*/
-import "C"
-
-var b bool
-
-func F() {
- if b {
- for {
- }
- }
- C.f()
-}
+++ /dev/null
-package p_test
-
-import (
- . "cgocover4"
- "testing"
-)
-
-func TestF(t *testing.T) {
- F()
-}