]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: convert some vet tests to the script framework
authorMichael Matloob <matloob@golang.org>
Thu, 9 Jan 2020 22:18:12 +0000 (17:18 -0500)
committerMichael Matloob <matloob@golang.org>
Wed, 19 Feb 2020 20:59:01 +0000 (20:59 +0000)
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>
src/cmd/go/go_test.go
src/cmd/go/testdata/script/test_vet.txt [new file with mode: 0644]
src/cmd/go/testdata/script/vet.txt [new file with mode: 0644]
src/cmd/go/testdata/src/vetcycle/p.go [deleted file]
src/cmd/go/testdata/src/vetfail/p1/p1.go [deleted file]
src/cmd/go/testdata/src/vetfail/p2/p2.go [deleted file]
src/cmd/go/testdata/src/vetfail/p2/p2_test.go [deleted file]
src/cmd/go/testdata/src/vetpkg/a_test.go [deleted file]
src/cmd/go/testdata/src/vetpkg/b.go [deleted file]
src/cmd/go/testdata/src/vetpkg/c.go [deleted file]

index 89c949a6149beeac3331b06d1d46ea21277cc4d8..f43c7becc28b74d84e1fa2bc7a308e76c6737f61 100644 (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()
diff --git a/src/cmd/go/testdata/script/test_vet.txt b/src/cmd/go/testdata/script/test_vet.txt
new file mode 100644 (file)
index 0000000..af26b4d
--- /dev/null
@@ -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()
+}
diff --git a/src/cmd/go/testdata/script/vet.txt b/src/cmd/go/testdata/script/vet.txt
new file mode 100644 (file)
index 0000000..73fe295
--- /dev/null
@@ -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() {}
\ No newline at end of file
diff --git a/src/cmd/go/testdata/src/vetcycle/p.go b/src/cmd/go/testdata/src/vetcycle/p.go
deleted file mode 100644 (file)
index 5b058e7..0000000
+++ /dev/null
@@ -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)
diff --git a/src/cmd/go/testdata/src/vetfail/p1/p1.go b/src/cmd/go/testdata/src/vetfail/p1/p1.go
deleted file mode 100644 (file)
index eaa9b18..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// +build !foo-bar
-
-package p1
-
-import "fmt"
-
-func F() {
-       fmt.Printf("%d", "hello") // causes vet error
-}
diff --git a/src/cmd/go/testdata/src/vetfail/p2/p2.go b/src/cmd/go/testdata/src/vetfail/p2/p2.go
deleted file mode 100644 (file)
index 88b1cc2..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-package p2
-
-import _ "vetfail/p1"
-
-func F() {
-}
diff --git a/src/cmd/go/testdata/src/vetfail/p2/p2_test.go b/src/cmd/go/testdata/src/vetfail/p2/p2_test.go
deleted file mode 100644 (file)
index fde0d1a..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package p2
-
-import "testing"
-
-func TestF(t *testing.T) {
-       F()
-}
diff --git a/src/cmd/go/testdata/src/vetpkg/a_test.go b/src/cmd/go/testdata/src/vetpkg/a_test.go
deleted file mode 100644 (file)
index 9b64e8e..0000000
+++ /dev/null
@@ -1 +0,0 @@
-package p_test
diff --git a/src/cmd/go/testdata/src/vetpkg/b.go b/src/cmd/go/testdata/src/vetpkg/b.go
deleted file mode 100644 (file)
index 99e18f6..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package p
-
-import "fmt"
-
-func f() {
-       fmt.Printf("%d")
-}
diff --git a/src/cmd/go/testdata/src/vetpkg/c.go b/src/cmd/go/testdata/src/vetpkg/c.go
deleted file mode 100644 (file)
index ef5648f..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// +build tagtest
-
-package p
-
-import "fmt"
-
-func g() {
-       fmt.Printf("%d", 3, 4)
-}