1
0
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:
Michael Matloob 2019-12-26 17:47:26 -05:00
parent d5967a7100
commit 822094f047
18 changed files with 185 additions and 158 deletions

View File

@ -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")

View 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

View 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()
}

View 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()
}

View 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()
}

View 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()
}

View File

@ -1,8 +0,0 @@
package p
/*
// hi
*/
import "C"
func F() {}

View File

@ -1,2 +0,0 @@
TEXT asm(SB),$0
RET

View File

@ -1,19 +0,0 @@
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}

View File

@ -1,7 +0,0 @@
package p
import "testing"
func TestF(t *testing.T) {
F()
}

View File

@ -1,19 +0,0 @@
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}

View File

@ -1,10 +0,0 @@
package p_test
import (
. "cgocover2"
"testing"
)
func TestF(t *testing.T) {
F()
}

View File

@ -1,19 +0,0 @@
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}

View File

@ -1 +0,0 @@
package p

View File

@ -1,10 +0,0 @@
package p_test
import (
. "cgocover3"
"testing"
)
func TestF(t *testing.T) {
F()
}

View File

@ -1 +0,0 @@
package p

View File

@ -1,19 +0,0 @@
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}

View File

@ -1,10 +0,0 @@
package p_test
import (
. "cgocover4"
"testing"
)
func TestF(t *testing.T) {
F()
}