Commit 5176a4b3 authored by Marcel van Lohuizen's avatar Marcel van Lohuizen

testing: fix flakey test on plan9

allow for more than 0.00s.

Fixes #15149

Change-Id: I1d428a9b3c9bb3d1db8682c53b86e44cecc1dde1
Reviewed-on: https://go-review.googlesource.com/21602Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent ff7ba773
...@@ -122,8 +122,8 @@ func TestTRun(t *T) { ...@@ -122,8 +122,8 @@ func TestTRun(t *T) {
ok: false, ok: false,
maxPar: 1, maxPar: 1,
output: ` output: `
--- FAIL: failnow skips future sequential and parallel tests at same level (0.00s) --- FAIL: failnow skips future sequential and parallel tests at same level (N.NNs)
--- FAIL: failnow skips future sequential and parallel tests at same level/#00 (0.00s) --- FAIL: failnow skips future sequential and parallel tests at same level/#00 (N.NNs)
`, `,
f: func(t *T) { f: func(t *T) {
ranSeq := false ranSeq := false
...@@ -157,9 +157,9 @@ func TestTRun(t *T) { ...@@ -157,9 +157,9 @@ func TestTRun(t *T) {
ok: false, ok: false,
maxPar: 1, maxPar: 1,
output: ` output: `
--- FAIL: failure in parallel test propagates upwards (0.00s) --- FAIL: failure in parallel test propagates upwards (N.NNs)
--- FAIL: failure in parallel test propagates upwards/#00 (0.00s) --- FAIL: failure in parallel test propagates upwards/#00 (N.NNs)
--- FAIL: failure in parallel test propagates upwards/#00/par (0.00s) --- FAIL: failure in parallel test propagates upwards/#00/par (N.NNs)
`, `,
f: func(t *T) { f: func(t *T) {
t.Run("", func(t *T) { t.Run("", func(t *T) {
...@@ -176,7 +176,7 @@ func TestTRun(t *T) { ...@@ -176,7 +176,7 @@ func TestTRun(t *T) {
chatty: true, chatty: true,
output: ` output: `
=== RUN skipping without message, chatty === RUN skipping without message, chatty
--- SKIP: skipping without message, chatty (0.00s)`, --- SKIP: skipping without message, chatty (N.NNs)`,
f: func(t *T) { t.SkipNow() }, f: func(t *T) { t.SkipNow() },
}, { }, {
desc: "chatty with recursion", desc: "chatty with recursion",
...@@ -186,9 +186,9 @@ func TestTRun(t *T) { ...@@ -186,9 +186,9 @@ func TestTRun(t *T) {
=== RUN chatty with recursion === RUN chatty with recursion
=== RUN chatty with recursion/#00 === RUN chatty with recursion/#00
=== RUN chatty with recursion/#00/#00 === RUN chatty with recursion/#00/#00
--- PASS: chatty with recursion (0.00s) --- PASS: chatty with recursion (N.NNs)
--- PASS: chatty with recursion/#00 (0.00s) --- PASS: chatty with recursion/#00 (N.NNs)
--- PASS: chatty with recursion/#00/#00 (0.00s)`, --- PASS: chatty with recursion/#00/#00 (N.NNs)`,
f: func(t *T) { f: func(t *T) {
t.Run("", func(t *T) { t.Run("", func(t *T) {
t.Run("", func(t *T) {}) t.Run("", func(t *T) {})
...@@ -201,9 +201,9 @@ func TestTRun(t *T) { ...@@ -201,9 +201,9 @@ func TestTRun(t *T) {
}, { }, {
desc: "skipping after error", desc: "skipping after error",
output: ` output: `
--- FAIL: skipping after error (0.00s) --- FAIL: skipping after error (N.NNs)
sub_test.go:nnn: an error sub_test.go:NNN: an error
sub_test.go:nnn: skipped`, sub_test.go:NNN: skipped`,
f: func(t *T) { f: func(t *T) {
t.Error("an error") t.Error("an error")
t.Skip("skipped") t.Skip("skipped")
...@@ -383,9 +383,10 @@ func TestTRun(t *T) { ...@@ -383,9 +383,10 @@ func TestTRun(t *T) {
if ctx.running != 0 || ctx.numWaiting != 0 { if ctx.running != 0 || ctx.numWaiting != 0 {
t.Errorf("%s:running and waiting non-zero: got %d and %d", tc.desc, ctx.running, ctx.numWaiting) t.Errorf("%s:running and waiting non-zero: got %d and %d", tc.desc, ctx.running, ctx.numWaiting)
} }
got := sanitizeLog(buf.String()) got := strings.TrimSpace(buf.String())
want := sanitizeLog(tc.output) want := strings.TrimSpace(tc.output)
if got != want { re := makeRegexp(want)
if ok, err := regexp.MatchString(re, got); !ok || err != nil {
t.Errorf("%s:ouput:\ngot:\n%s\nwant:\n%s", tc.desc, got, want) t.Errorf("%s:ouput:\ngot:\n%s\nwant:\n%s", tc.desc, got, want)
} }
} }
...@@ -449,7 +450,7 @@ func TestBRun(t *T) { ...@@ -449,7 +450,7 @@ func TestBRun(t *T) {
chatty: true, chatty: true,
output: ` output: `
--- SKIP: root --- SKIP: root
sub_test.go:: skipping`, sub_test.go:NNN: skipping`,
f: func(b *B) { b.Skip("skipping") }, f: func(b *B) { b.Skip("skipping") },
}, { }, {
desc: "chatty with recursion", desc: "chatty with recursion",
...@@ -467,8 +468,8 @@ func TestBRun(t *T) { ...@@ -467,8 +468,8 @@ func TestBRun(t *T) {
failed: true, failed: true,
output: ` output: `
--- FAIL: root --- FAIL: root
sub_test.go:nnn: an error sub_test.go:NNN: an error
sub_test.go:nnn: skipped`, sub_test.go:NNN: skipped`,
f: func(b *B) { f: func(b *B) {
b.Error("an error") b.Error("an error")
b.Skip("skipped") b.Skip("skipped")
...@@ -523,25 +524,19 @@ func TestBRun(t *T) { ...@@ -523,25 +524,19 @@ func TestBRun(t *T) {
if root.result.N != 1 { if root.result.N != 1 {
t.Errorf("%s: N for parent benchmark was %d; want 1", tc.desc, root.result.N) t.Errorf("%s: N for parent benchmark was %d; want 1", tc.desc, root.result.N)
} }
got := sanitizeLog(buf.String()) got := strings.TrimSpace(buf.String())
want := sanitizeLog(tc.output) want := strings.TrimSpace(tc.output)
if got != want { re := makeRegexp(want)
if ok, err := regexp.MatchString(re, got); !ok || err != nil {
t.Errorf("%s:ouput:\ngot:\n%s\nwant:\n%s", tc.desc, got, want) t.Errorf("%s:ouput:\ngot:\n%s\nwant:\n%s", tc.desc, got, want)
} }
} }
} }
// sanitizeLog removes line numbers from log entries. func makeRegexp(s string) string {
func sanitizeLog(s string) string { s = strings.Replace(s, ":NNN:", `:\d\d\d:`, -1)
s = strings.TrimSpace(s) s = strings.Replace(s, "(N.NNs)", `\(\d*\.\d*s\)`, -1)
lines := strings.Split(s, "\n") return s
for i, line := range lines {
p := strings.IndexByte(line, ':')
if p > 0 && line[p+4] == ':' { // assuming 3-digit file positions
lines[i] = line[:p+1] + line[p+4:]
}
}
return strings.Join(lines, "\n")
} }
func TestBenchmarkOutput(t *T) { func TestBenchmarkOutput(t *T) {
......
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