Skip to content

Commit 822094f

Browse files
committed
cmd/go: convert some cgo-related testcases to script framework
This change converts TestCoverageWithCgo and TestCgoConsistentResults to the script framework. Change-Id: Ic5a13f6dd6099d3d73a5cda8cbc724a79a3d2c58 Reviewed-on: https://go-review.googlesource.com/c/go/+/212621 Run-TryBot: Michael Matloob <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent d5967a7 commit 822094f

File tree

18 files changed

+185
-158
lines changed

18 files changed

+185
-158
lines changed

src/cmd/go/go_test.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,39 +2311,6 @@ func main() {
23112311
tg.grepStderrNot(`os.Stat .* no such file or directory`, "unexpected stat of archive file")
23122312
}
23132313

2314-
func TestCoverageWithCgo(t *testing.T) {
2315-
skipIfGccgo(t, "gccgo has no cover tool")
2316-
tooSlow(t)
2317-
if !canCgo {
2318-
t.Skip("skipping because cgo not enabled")
2319-
}
2320-
2321-
for _, dir := range []string{"cgocover", "cgocover2", "cgocover3", "cgocover4"} {
2322-
t.Run(dir, func(t *testing.T) {
2323-
tg := testgo(t)
2324-
tg.parallel()
2325-
defer tg.cleanup()
2326-
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
2327-
tg.run("test", "-short", "-cover", dir)
2328-
data := tg.getStdout() + tg.getStderr()
2329-
checkCoverage(tg, data)
2330-
})
2331-
}
2332-
}
2333-
2334-
func TestCgoAsmError(t *testing.T) {
2335-
if !canCgo {
2336-
t.Skip("skipping because cgo not enabled")
2337-
}
2338-
2339-
tg := testgo(t)
2340-
tg.parallel()
2341-
defer tg.cleanup()
2342-
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
2343-
tg.runFail("build", "cgoasm")
2344-
tg.grepBoth("package using cgo has Go assembly file", "did not detect Go assembly file")
2345-
}
2346-
23472314
func TestCgoDependsOnSyscall(t *testing.T) {
23482315
if testing.Short() {
23492316
t.Skip("skipping test that removes $GOROOT/pkg/*_race in short mode")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[!cgo] skip
2+
3+
# Test that cgo package can't contain a go assembly file.
4+
5+
# Ensure the build fails and reports that the package has a Go assembly file.
6+
! go build cgoasm
7+
stderr 'package using cgo has Go assembly file'
8+
9+
-- cgoasm/p.go --
10+
package p
11+
12+
/*
13+
// hi
14+
*/
15+
import "C"
16+
17+
func F() {}
18+
-- cgoasm/p.s --
19+
TEXT asm(SB),$0
20+
RET
21+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[!cgo] skip
2+
[gccgo] skip # gccgo has no cover tool
3+
4+
# Test coverage on cgo code.
5+
6+
go test -short -cover cgocover
7+
stdout 'coverage:.*[1-9][0-9.]+%'
8+
! stderr '[^0-9]0\.0%'
9+
10+
-- cgocover/p.go --
11+
package p
12+
13+
/*
14+
void
15+
f(void)
16+
{
17+
}
18+
*/
19+
import "C"
20+
21+
var b bool
22+
23+
func F() {
24+
if b {
25+
for {
26+
}
27+
}
28+
C.f()
29+
}
30+
-- cgocover/p_test.go --
31+
package p
32+
33+
import "testing"
34+
35+
func TestF(t *testing.T) {
36+
F()
37+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[!cgo] skip
2+
[gccgo] skip # gccgo has no cover tool
3+
4+
# Test coverage on cgo code. This test case includes an
5+
# extra empty non-cgo file in the package being checked.
6+
7+
go test -short -cover cgocover4
8+
stdout 'coverage:.*[1-9][0-9.]+%'
9+
! stderr '[^0-9]0\.0%'
10+
11+
-- cgocover4/notcgo.go --
12+
package p
13+
-- cgocover4/p.go --
14+
package p
15+
16+
/*
17+
void
18+
f(void)
19+
{
20+
}
21+
*/
22+
import "C"
23+
24+
var b bool
25+
26+
func F() {
27+
if b {
28+
for {
29+
}
30+
}
31+
C.f()
32+
}
33+
-- cgocover4/x_test.go --
34+
package p_test
35+
36+
import (
37+
. "cgocover4"
38+
"testing"
39+
)
40+
41+
func TestF(t *testing.T) {
42+
F()
43+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[!cgo] skip
2+
[gccgo] skip # gccgo has no cover tool
3+
4+
# Test coverage on cgo code. This test case has an external
5+
# test that tests the code and an in-package test file with
6+
# no test cases.
7+
8+
go test -short -cover cgocover3
9+
stdout 'coverage:.*[1-9][0-9.]+%'
10+
! stderr '[^0-9]0\.0%'
11+
12+
-- cgocover3/p.go --
13+
package p
14+
15+
/*
16+
void
17+
f(void)
18+
{
19+
}
20+
*/
21+
import "C"
22+
23+
var b bool
24+
25+
func F() {
26+
if b {
27+
for {
28+
}
29+
}
30+
C.f()
31+
}
32+
-- cgocover3/p_test.go --
33+
package p
34+
-- cgocover3/x_test.go --
35+
package p_test
36+
37+
import (
38+
. "cgocover3"
39+
"testing"
40+
)
41+
42+
func TestF(t *testing.T) {
43+
F()
44+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[!cgo] skip
2+
[gccgo] skip # gccgo has no cover tool
3+
4+
# Test cgo coverage with an external test.
5+
6+
go test -short -cover cgocover2
7+
stdout 'coverage:.*[1-9][0-9.]+%'
8+
! stderr '[^0-9]0\.0%'
9+
10+
-- cgocover2/p.go --
11+
package p
12+
13+
/*
14+
void
15+
f(void)
16+
{
17+
}
18+
*/
19+
import "C"
20+
21+
var b bool
22+
23+
func F() {
24+
if b {
25+
for {
26+
}
27+
}
28+
C.f()
29+
}
30+
-- cgocover2/x_test.go --
31+
package p_test
32+
33+
import (
34+
. "cgocover2"
35+
"testing"
36+
)
37+
38+
func TestF(t *testing.T) {
39+
F()
40+
}

src/cmd/go/testdata/src/cgoasm/p.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/cmd/go/testdata/src/cgoasm/p.s

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/cmd/go/testdata/src/cgocover/p.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/cmd/go/testdata/src/cgocover/p_test.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/cmd/go/testdata/src/cgocover2/p.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/cmd/go/testdata/src/cgocover2/x_test.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/cmd/go/testdata/src/cgocover3/p.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/cmd/go/testdata/src/cgocover3/p_test.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/cmd/go/testdata/src/cgocover3/x_test.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/cmd/go/testdata/src/cgocover4/notcgo.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/cmd/go/testdata/src/cgocover4/p.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/cmd/go/testdata/src/cgocover4/x_test.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)