1
0
mirror of https://github.com/golang/go synced 2024-11-17 21:44:43 -07:00

cmd/go: convert some vet tests to the script framework

Part of converting all tests to script framework to improve
test parallelism.

Updates #36320
Updates #17751

Change-Id: I1f49a84f91735f39d5922c1347e79298780149c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/214218
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Michael Matloob 2020-01-09 17:18:12 -05:00
parent a9d344dac0
commit 68fab3e93f
10 changed files with 146 additions and 159 deletions

View File

@ -2146,66 +2146,6 @@ func TestGoTestBuildsAnXtestContainingOnlyNonRunnableExamples(t *testing.T) {
tg.grepStdout("File with non-runnable example was built.", "file with non-runnable example was not built")
}
func TestGoVetWithExternalTests(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("vet", "vetpkg")
tg.grepBoth("Printf", "go vet vetpkg did not find missing argument for Printf")
}
func TestGoVetWithTags(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("vet", "-tags", "tagtest", "vetpkg")
tg.grepBoth(`c\.go.*Printf`, "go vet vetpkg did not run scan tagged file")
}
func TestGoVetWithFlagsOn(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("vet", "-printf", "vetpkg")
tg.grepBoth("Printf", "go vet -printf vetpkg did not find missing argument for Printf")
}
func TestGoVetWithFlagsOff(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("vet", "-printf=false", "vetpkg")
}
// Issue 23395.
func TestGoVetWithOnlyTestFiles(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.tempFile("src/p/p_test.go", "package p; import \"testing\"; func TestMe(*testing.T) {}")
tg.setenv("GOPATH", tg.path("."))
tg.run("vet", "p")
}
// Issue 24193.
func TestVetWithOnlyCgoFiles(t *testing.T) {
if !canCgo {
t.Skip("skipping because cgo not enabled")
}
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.tempFile("src/p/p.go", "package p; import \"C\"; func F() {}")
tg.setenv("GOPATH", tg.path("."))
tg.run("vet", "p")
}
// Test that you cannot use a local import in a package
// accessed by a non-local import (found in a GOPATH/GOROOT).
// See golang.org/issue/17475.
@ -3527,53 +3467,6 @@ func TestTestCache(t *testing.T) {
}
}
func TestTestVet(t *testing.T) {
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.tempFile("p1_test.go", `
package p
import "testing"
func Test(t *testing.T) {
t.Logf("%d") // oops
}
`)
tg.runFail("test", tg.path("p1_test.go"))
tg.grepStderr(`Logf format %d`, "did not diagnose bad Logf")
tg.run("test", "-vet=off", tg.path("p1_test.go"))
tg.grepStdout(`^ok`, "did not print test summary")
tg.tempFile("p1.go", `
package p
import "fmt"
func F() {
fmt.Printf("%d") // oops
}
`)
tg.runFail("test", tg.path("p1.go"))
tg.grepStderr(`Printf format %d`, "did not diagnose bad Printf")
tg.run("test", "-x", "-vet=shift", tg.path("p1.go"))
tg.grepStderr(`[\\/]vet.*-shift`, "did not run vet with -shift")
tg.grepStdout(`\[no test files\]`, "did not print test summary")
tg.run("test", "-vet=off", tg.path("p1.go"))
tg.grepStdout(`\[no test files\]`, "did not print test summary")
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("test", "vetcycle") // must not fail; #22890
tg.runFail("test", "vetfail/...")
tg.grepStderr(`Printf format %d`, "did not diagnose bad Printf")
tg.grepStdout(`ok\s+vetfail/p2`, "did not run vetfail/p2")
// Use -a so that we need to recompute the vet-specific export data for
// vetfail/p1.
tg.run("test", "-a", "vetfail/p2")
tg.grepStderrNot(`invalid.*constraint`, "did diagnose bad build constraint in vetxonly mode")
}
func TestTestSkipVetAfterFailedBuild(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()

88
src/cmd/go/testdata/script/test_vet.txt vendored Normal file
View File

@ -0,0 +1,88 @@
[short] skip
# Test file
! go test p1_test.go
stderr 'Logf format %d'
go test -vet=off
stdout '^ok'
# Non-test file
! go test p1.go
stderr 'Printf format %d'
go test -x -vet=shift p1.go
stderr '[\\/]vet.*-shift'
stdout '\[no test files\]'
go test -vet=off p1.go
! stderr '[\\/]vet.*-shift'
stdout '\[no test files\]'
# Test issue #22890
go test vetcycle
stdout 'vetcycle.*\[no test files\]'
# Test with ...
! go test vetfail/...
stderr 'Printf format %d'
stdout 'ok\s+vetfail/p2'
# Check there's no diagnosis of a bad build constraint in vetxonly mode.
# Use -a so that we need to recompute the vet-specific export data for
# vetfail/p1.
go test -a vetfail/p2
! stderr 'invalid.*constraint'
-- p1_test.go --
package p
import "testing"
func Test(t *testing.T) {
t.Logf("%d") // oops
}
-- p1.go --
package p
import "fmt"
func F() {
fmt.Printf("%d") // oops
}
-- vetcycle/p.go --
package p
type (
_ interface{ m(B1) }
A1 interface{ a(D1) }
B1 interface{ A1 }
C1 interface {
B1 /* ERROR issue #18395 */
}
D1 interface{ C1 }
)
var _ A1 = C1 /* ERROR cannot use C1 */ (nil)
-- vetfail/p1/p1.go --
// +build !foo-bar
package p1
import "fmt"
func F() {
fmt.Printf("%d", "hello") // causes vet error
}
-- vetfail/p2/p2.go --
package p2
import _ "vetfail/p1"
func F() {
}
-- vetfail/p2/p2_test.go --
package p2
import "testing"
func TestF(t *testing.T) {
F()
}

58
src/cmd/go/testdata/script/vet.txt vendored Normal file
View File

@ -0,0 +1,58 @@
# Package with external tests
! go vet vetpkg
stderr 'Printf'
# With tags
! go vet -tags tagtest vetpkg
stderr 'c\.go.*Printf'
# With flags on
! go vet -printf vetpkg
stderr 'Printf'
# With flags off
go vet -printf=false vetpkg
! stderr .
# With only test files (tests issue #23395)
go vet onlytest
! stderr .
# With only cgo files (tests issue #24193)
[!cgo] skip
[short] skip
go vet onlycgo
! stderr .
-- vetpkg/a_test.go --
package p_test
-- vetpkg/b.go --
package p
import "fmt"
func f() {
fmt.Printf("%d")
}
-- vetpkg/c.go --
// +build tagtest
package p
import "fmt"
func g() {
fmt.Printf("%d", 3, 4)
}
-- onlytest/p_test.go --
package p
import "testing"
func TestMe(*testing.T) {}
-- onlycgo/p.go --
package p
import "C"
func F() {}

View File

@ -1,13 +0,0 @@
package p
type (
_ interface{ m(B1) }
A1 interface{ a(D1) }
B1 interface{ A1 }
C1 interface {
B1 /* ERROR issue #18395 */
}
D1 interface{ C1 }
)
var _ A1 = C1 /* ERROR cannot use C1 */ (nil)

View File

@ -1,9 +0,0 @@
// +build !foo-bar
package p1
import "fmt"
func F() {
fmt.Printf("%d", "hello") // causes vet error
}

View File

@ -1,6 +0,0 @@
package p2
import _ "vetfail/p1"
func F() {
}

View File

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

View File

@ -1 +0,0 @@
package p_test

View File

@ -1,7 +0,0 @@
package p
import "fmt"
func f() {
fmt.Printf("%d")
}

View File

@ -1,9 +0,0 @@
// +build tagtest
package p
import "fmt"
func g() {
fmt.Printf("%d", 3, 4)
}