Commit 98418c99 authored by Michael Matloob's avatar Michael Matloob

cmd/go: convert TestTestRegexps to the script framework

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: default avatarJay Conrod <jayconrod@google.com>
parent c399afef
......@@ -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
......
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
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)
})
}
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)
}
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