Commit 822094f0 authored by Michael Matloob's avatar Michael Matloob

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: default avatarJay Conrod <jayconrod@google.com>
parent d5967a71
......@@ -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")
......
[!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
[!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()
}
[!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
[!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
[!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
package p
/*
// hi
*/
import "C"
func F() {}
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}
package p
import "testing"
func TestF(t *testing.T) {
F()
}
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}
package p_test
import (
. "cgocover2"
"testing"
)
func TestF(t *testing.T) {
F()
}
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}
package p_test
import (
. "cgocover3"
"testing"
)
func TestF(t *testing.T) {
F()
}
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}
package p_test
import (
. "cgocover4"
"testing"
)
func TestF(t *testing.T) {
F()
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment