mirror of
https://github.com/golang/go
synced 2024-11-17 23:54:51 -07:00
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 <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
d5967a7100
commit
822094f047
@ -2311,39 +2311,6 @@ func main() {
|
||||
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")
|
||||
|
21
src/cmd/go/testdata/script/cgo_asm_error.txt
vendored
Normal file
21
src/cmd/go/testdata/script/cgo_asm_error.txt
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
[!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
|
||||
|
37
src/cmd/go/testdata/script/cover_cgo.txt
vendored
Normal file
37
src/cmd/go/testdata/script/cover_cgo.txt
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
[!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()
|
||||
}
|
43
src/cmd/go/testdata/script/cover_cgo_extra_file.txt
vendored
Normal file
43
src/cmd/go/testdata/script/cover_cgo_extra_file.txt
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
[!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()
|
||||
}
|
44
src/cmd/go/testdata/script/cover_cgo_extra_test.txt
vendored
Normal file
44
src/cmd/go/testdata/script/cover_cgo_extra_test.txt
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
[!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()
|
||||
}
|
40
src/cmd/go/testdata/script/cover_cgo_xtest.txt
vendored
Normal file
40
src/cmd/go/testdata/script/cover_cgo_xtest.txt
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
[!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()
|
||||
}
|
8
src/cmd/go/testdata/src/cgoasm/p.go
vendored
8
src/cmd/go/testdata/src/cgoasm/p.go
vendored
@ -1,8 +0,0 @@
|
||||
package p
|
||||
|
||||
/*
|
||||
// hi
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func F() {}
|
2
src/cmd/go/testdata/src/cgoasm/p.s
vendored
2
src/cmd/go/testdata/src/cgoasm/p.s
vendored
@ -1,2 +0,0 @@
|
||||
TEXT asm(SB),$0
|
||||
RET
|
19
src/cmd/go/testdata/src/cgocover/p.go
vendored
19
src/cmd/go/testdata/src/cgocover/p.go
vendored
@ -1,19 +0,0 @@
|
||||
package p
|
||||
|
||||
/*
|
||||
void
|
||||
f(void)
|
||||
{
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
var b bool
|
||||
|
||||
func F() {
|
||||
if b {
|
||||
for {
|
||||
}
|
||||
}
|
||||
C.f()
|
||||
}
|
7
src/cmd/go/testdata/src/cgocover/p_test.go
vendored
7
src/cmd/go/testdata/src/cgocover/p_test.go
vendored
@ -1,7 +0,0 @@
|
||||
package p
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestF(t *testing.T) {
|
||||
F()
|
||||
}
|
19
src/cmd/go/testdata/src/cgocover2/p.go
vendored
19
src/cmd/go/testdata/src/cgocover2/p.go
vendored
@ -1,19 +0,0 @@
|
||||
package p
|
||||
|
||||
/*
|
||||
void
|
||||
f(void)
|
||||
{
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
var b bool
|
||||
|
||||
func F() {
|
||||
if b {
|
||||
for {
|
||||
}
|
||||
}
|
||||
C.f()
|
||||
}
|
10
src/cmd/go/testdata/src/cgocover2/x_test.go
vendored
10
src/cmd/go/testdata/src/cgocover2/x_test.go
vendored
@ -1,10 +0,0 @@
|
||||
package p_test
|
||||
|
||||
import (
|
||||
. "cgocover2"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestF(t *testing.T) {
|
||||
F()
|
||||
}
|
19
src/cmd/go/testdata/src/cgocover3/p.go
vendored
19
src/cmd/go/testdata/src/cgocover3/p.go
vendored
@ -1,19 +0,0 @@
|
||||
package p
|
||||
|
||||
/*
|
||||
void
|
||||
f(void)
|
||||
{
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
var b bool
|
||||
|
||||
func F() {
|
||||
if b {
|
||||
for {
|
||||
}
|
||||
}
|
||||
C.f()
|
||||
}
|
1
src/cmd/go/testdata/src/cgocover3/p_test.go
vendored
1
src/cmd/go/testdata/src/cgocover3/p_test.go
vendored
@ -1 +0,0 @@
|
||||
package p
|
10
src/cmd/go/testdata/src/cgocover3/x_test.go
vendored
10
src/cmd/go/testdata/src/cgocover3/x_test.go
vendored
@ -1,10 +0,0 @@
|
||||
package p_test
|
||||
|
||||
import (
|
||||
. "cgocover3"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestF(t *testing.T) {
|
||||
F()
|
||||
}
|
1
src/cmd/go/testdata/src/cgocover4/notcgo.go
vendored
1
src/cmd/go/testdata/src/cgocover4/notcgo.go
vendored
@ -1 +0,0 @@
|
||||
package p
|
19
src/cmd/go/testdata/src/cgocover4/p.go
vendored
19
src/cmd/go/testdata/src/cgocover4/p.go
vendored
@ -1,19 +0,0 @@
|
||||
package p
|
||||
|
||||
/*
|
||||
void
|
||||
f(void)
|
||||
{
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
var b bool
|
||||
|
||||
func F() {
|
||||
if b {
|
||||
for {
|
||||
}
|
||||
}
|
||||
C.f()
|
||||
}
|
10
src/cmd/go/testdata/src/cgocover4/x_test.go
vendored
10
src/cmd/go/testdata/src/cgocover4/x_test.go
vendored
@ -1,10 +0,0 @@
|
||||
package p_test
|
||||
|
||||
import (
|
||||
. "cgocover4"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestF(t *testing.T) {
|
||||
F()
|
||||
}
|
Loading…
Reference in New Issue
Block a user