]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: convert TestTestRegexps to the script framework
authorMichael Matloob <matloob@golang.org>
Thu, 2 Jan 2020 21:42:43 +0000 (16:42 -0500)
committerMichael Matloob <matloob@golang.org>
Tue, 7 Jan 2020 17:53:52 +0000 (17:53 +0000)
It's hard to convert this one exactly because I don't think
we can guarantee that the grep command exists to filter stdout,
so I've tried to replicate the intent of the test.

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

Updates #36320
Updates #17751

Change-Id: Ib593799ef7634ce12efb3ff357eb34475e2ea321
Reviewed-on: https://go-review.googlesource.com/c/go/+/213130
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/go_test.go
src/cmd/go/testdata/script/test_regexps.txt [new file with mode: 0644]
src/cmd/go/testdata/src/testregexp/x_test.go [deleted file]
src/cmd/go/testdata/src/testregexp/z_test.go [deleted file]

index 072de5d18c817d3e187641af879869dbbe5738b4..ddc29fbff9e6de7e2179856ec7c0c034d31f51ef 100644 (file)
@@ -4086,60 +4086,6 @@ func main() {}`)
        }))
 }
 
-func TestTestRegexps(t *testing.T) {
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
-       tg.run("test", "-cpu=1", "-run=X/Y", "-bench=X/Y", "-count=2", "-v", "testregexp")
-       var lines []string
-       for _, line := range strings.SplitAfter(tg.getStdout(), "\n") {
-               if strings.Contains(line, "=== RUN") || strings.Contains(line, "--- BENCH") || strings.Contains(line, "LOG") {
-                       lines = append(lines, line)
-               }
-       }
-
-       // Important parts:
-       //      TestX is run, twice
-       //      TestX/Y is run, twice
-       //      TestXX is run, twice
-       //      TestZ is not run
-       //      BenchmarkX is run but only with N=1, once
-       //      BenchmarkXX is run but only with N=1, once
-       //      BenchmarkX/Y is run in full, twice
-       want := `=== RUN   TestX
-    TestX: x_test.go:6: LOG: X running
-=== RUN   TestX/Y
-    TestX/Y: x_test.go:8: LOG: Y running
-=== RUN   TestXX
-    TestXX: z_test.go:10: LOG: XX running
-=== RUN   TestX
-    TestX: x_test.go:6: LOG: X running
-=== RUN   TestX/Y
-    TestX/Y: x_test.go:8: LOG: Y running
-=== RUN   TestXX
-    TestXX: z_test.go:10: LOG: XX running
-    BenchmarkX: x_test.go:13: LOG: X running N=1
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=1
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=100
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=10000
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=1000000
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=100000000
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=1000000000
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=1
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=100
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=10000
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=1000000
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=100000000
-    BenchmarkX/Y: x_test.go:15: LOG: Y running N=1000000000
-    BenchmarkXX: z_test.go:18: LOG: XX running N=1
-`
-
-       have := strings.Join(lines, "")
-       if have != want {
-               t.Errorf("reduced output:<<<\n%s>>> want:<<<\n%s>>>", have, want)
-       }
-}
-
 func TestListTests(t *testing.T) {
        tooSlow(t)
        var tg *testgoData
diff --git a/src/cmd/go/testdata/script/test_regexps.txt b/src/cmd/go/testdata/script/test_regexps.txt
new file mode 100644 (file)
index 0000000..020b8dd
--- /dev/null
@@ -0,0 +1,68 @@
+go test -cpu=1 -run=X/Y -bench=X/Y -count=2 -v testregexp
+
+# Test the following:
+
+#      TestX is run, twice
+stdout -count=2 '^=== RUN   TestX$'
+stdout -count=2 '^    TestX: x_test.go:6: LOG: X running$'
+
+#      TestX/Y is run, twice
+stdout -count=2 '^=== RUN   TestX/Y$'
+stdout -count=2 '^    TestX/Y: x_test.go:8: LOG: Y running$'
+
+#      TestXX is run, twice
+stdout -count=2 '^=== RUN   TestXX$'
+stdout -count=2 '^    TestXX: z_test.go:10: LOG: XX running'
+
+#      TestZ is not run
+! stdout '^=== RUN   TestZ$'
+
+#      BenchmarkX is run but only with N=1, once
+stdout -count=1 '^    BenchmarkX: x_test.go:13: LOG: X running N=1$'
+! stdout '^    BenchmarkX: x_test.go:13: LOG: X running N=10$'
+
+#      BenchmarkXX is run but only with N=1, once
+stdout -count=1 '^    BenchmarkXX: z_test.go:18: LOG: XX running N=1$'
+! stdout  '^    BenchmarkXX: z_test.go:18: LOG: XX running N=10$'
+
+#      BenchmarkX/Y is run in full, twice
+stdout -count=2 '    BenchmarkX/Y: x_test.go:15: LOG: Y running N=1\n    BenchmarkX/Y: x_test.go:15: LOG: Y running N=100\n    BenchmarkX/Y: x_test.go:15: LOG: Y running N=10000\n    BenchmarkX/Y: x_test.go:15: LOG: Y running N=1000000\n    BenchmarkX/Y: x_test.go:15: LOG: Y running N=100000000\n    BenchmarkX/Y: x_test.go:15: LOG: Y running N=1000000000'
+
+-- testregexp/x_test.go --
+package x
+
+import "testing"
+
+func TestX(t *testing.T) {
+       t.Logf("LOG: X running")
+       t.Run("Y", func(t *testing.T) {
+               t.Logf("LOG: Y running")
+       })
+}
+
+func BenchmarkX(b *testing.B) {
+       b.Logf("LOG: X running N=%d", b.N)
+       b.Run("Y", func(b *testing.B) {
+               b.Logf("LOG: Y running N=%d", b.N)
+       })
+}
+-- testregexp/z_test.go --
+package x
+
+import "testing"
+
+func TestZ(t *testing.T) {
+       t.Logf("LOG: Z running")
+}
+
+func TestXX(t *testing.T) {
+       t.Logf("LOG: XX running")
+}
+
+func BenchmarkZ(b *testing.B) {
+       b.Logf("LOG: Z running N=%d", b.N)
+}
+
+func BenchmarkXX(b *testing.B) {
+       b.Logf("LOG: XX running N=%d", b.N)
+}
\ No newline at end of file
diff --git a/src/cmd/go/testdata/src/testregexp/x_test.go b/src/cmd/go/testdata/src/testregexp/x_test.go
deleted file mode 100644 (file)
index 7573e79..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-package x
-
-import "testing"
-
-func TestX(t *testing.T) {
-       t.Logf("LOG: X running")
-       t.Run("Y", func(t *testing.T) {
-               t.Logf("LOG: Y running")
-       })
-}
-
-func BenchmarkX(b *testing.B) {
-       b.Logf("LOG: X running N=%d", b.N)
-       b.Run("Y", func(b *testing.B) {
-               b.Logf("LOG: Y running N=%d", b.N)
-       })
-}
diff --git a/src/cmd/go/testdata/src/testregexp/z_test.go b/src/cmd/go/testdata/src/testregexp/z_test.go
deleted file mode 100644 (file)
index 4fd1979..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-package x
-
-import "testing"
-
-func TestZ(t *testing.T) {
-       t.Logf("LOG: Z running")
-}
-
-func TestXX(t *testing.T) {
-       t.Logf("LOG: XX running")
-}
-
-func BenchmarkZ(b *testing.B) {
-       b.Logf("LOG: Z running N=%d", b.N)
-}
-
-func BenchmarkXX(b *testing.B) {
-       b.Logf("LOG: XX running N=%d", b.N)
-}