]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add test case for cgo coverage
authorRuss Cox <rsc@golang.org>
Thu, 6 Mar 2014 23:36:32 +0000 (18:36 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 6 Mar 2014 23:36:32 +0000 (18:36 -0500)
This is a test case for CL 34680044.

Fixes #6333.

LGTM=bradfitz
R=golang-codereviews, bradfitz, minux.ma
CC=golang-codereviews
https://golang.org/cl/71230049

src/cmd/go/test.bash
src/cmd/go/testdata/cgocover/p.go [new file with mode: 0644]
src/cmd/go/testdata/cgocover/p_test.go [new file with mode: 0644]

index 0e4af62754ed7c3feb77a75e5452fa6982cad724..507f2885ddcfe86e219309f8ca40ec64b9ee5dfd 100755 (executable)
@@ -568,6 +568,16 @@ TEST coverage runs
 ./testgo test -short -coverpkg=strings strings regexp || ok=false
 ./testgo test -short -cover strings math regexp || ok=false
 
+TEST coverage with cgo
+d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
+./testgo test -short -cover ./testdata/cgocover >$d/cgo.out 2>&1 || ok=false
+cat $d/cgo.out
+if grep 'coverage: 0.0%' $d/cgo.out >/dev/null; then 
+       ok=false
+       echo no coverage for cgo package
+       ok=false
+fi
+
 TEST cgo depends on syscall
 rm -rf $GOROOT/pkg/*_race
 d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
diff --git a/src/cmd/go/testdata/cgocover/p.go b/src/cmd/go/testdata/cgocover/p.go
new file mode 100644 (file)
index 0000000..a6a3891
--- /dev/null
@@ -0,0 +1,19 @@
+package p
+
+/*
+void
+f(void)
+{
+}
+*/
+import "C"
+
+var b bool
+
+func F() {
+       if b {
+               for {
+               }
+       }
+       C.f()
+}
diff --git a/src/cmd/go/testdata/cgocover/p_test.go b/src/cmd/go/testdata/cgocover/p_test.go
new file mode 100644 (file)
index 0000000..a8f057e
--- /dev/null
@@ -0,0 +1,7 @@
+package p
+
+import "testing"
+
+func TestF(t *testing.T) {
+       F()
+}