mirror of
https://github.com/golang/go
synced 2024-11-19 03:34:41 -07:00
testing: fix flakey test on plan9
allow for more than 0.00s. Fixes #15149 Change-Id: I1d428a9b3c9bb3d1db8682c53b86e44cecc1dde1 Reviewed-on: https://go-review.googlesource.com/21602 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
ff7ba773f4
commit
5176a4b39b
@ -122,8 +122,8 @@ func TestTRun(t *T) {
|
||||
ok: false,
|
||||
maxPar: 1,
|
||||
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/#00 (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 (N.NNs)
|
||||
`,
|
||||
f: func(t *T) {
|
||||
ranSeq := false
|
||||
@ -157,9 +157,9 @@ func TestTRun(t *T) {
|
||||
ok: false,
|
||||
maxPar: 1,
|
||||
output: `
|
||||
--- FAIL: failure in parallel test propagates upwards (0.00s)
|
||||
--- FAIL: failure in parallel test propagates upwards/#00 (0.00s)
|
||||
--- FAIL: failure in parallel test propagates upwards/#00/par (0.00s)
|
||||
--- FAIL: failure in parallel test propagates upwards (N.NNs)
|
||||
--- FAIL: failure in parallel test propagates upwards/#00 (N.NNs)
|
||||
--- FAIL: failure in parallel test propagates upwards/#00/par (N.NNs)
|
||||
`,
|
||||
f: func(t *T) {
|
||||
t.Run("", func(t *T) {
|
||||
@ -176,7 +176,7 @@ func TestTRun(t *T) {
|
||||
chatty: true,
|
||||
output: `
|
||||
=== 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() },
|
||||
}, {
|
||||
desc: "chatty with recursion",
|
||||
@ -186,9 +186,9 @@ func TestTRun(t *T) {
|
||||
=== RUN chatty with recursion
|
||||
=== RUN chatty with recursion/#00
|
||||
=== RUN chatty with recursion/#00/#00
|
||||
--- PASS: chatty with recursion (0.00s)
|
||||
--- PASS: chatty with recursion/#00 (0.00s)
|
||||
--- PASS: chatty with recursion/#00/#00 (0.00s)`,
|
||||
--- PASS: chatty with recursion (N.NNs)
|
||||
--- PASS: chatty with recursion/#00 (N.NNs)
|
||||
--- PASS: chatty with recursion/#00/#00 (N.NNs)`,
|
||||
f: func(t *T) {
|
||||
t.Run("", func(t *T) {
|
||||
t.Run("", func(t *T) {})
|
||||
@ -201,9 +201,9 @@ func TestTRun(t *T) {
|
||||
}, {
|
||||
desc: "skipping after error",
|
||||
output: `
|
||||
--- FAIL: skipping after error (0.00s)
|
||||
sub_test.go:nnn: an error
|
||||
sub_test.go:nnn: skipped`,
|
||||
--- FAIL: skipping after error (N.NNs)
|
||||
sub_test.go:NNN: an error
|
||||
sub_test.go:NNN: skipped`,
|
||||
f: func(t *T) {
|
||||
t.Error("an error")
|
||||
t.Skip("skipped")
|
||||
@ -383,9 +383,10 @@ func TestTRun(t *T) {
|
||||
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)
|
||||
}
|
||||
got := sanitizeLog(buf.String())
|
||||
want := sanitizeLog(tc.output)
|
||||
if got != want {
|
||||
got := strings.TrimSpace(buf.String())
|
||||
want := strings.TrimSpace(tc.output)
|
||||
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)
|
||||
}
|
||||
}
|
||||
@ -449,7 +450,7 @@ func TestBRun(t *T) {
|
||||
chatty: true,
|
||||
output: `
|
||||
--- SKIP: root
|
||||
sub_test.go:: skipping`,
|
||||
sub_test.go:NNN: skipping`,
|
||||
f: func(b *B) { b.Skip("skipping") },
|
||||
}, {
|
||||
desc: "chatty with recursion",
|
||||
@ -467,8 +468,8 @@ func TestBRun(t *T) {
|
||||
failed: true,
|
||||
output: `
|
||||
--- FAIL: root
|
||||
sub_test.go:nnn: an error
|
||||
sub_test.go:nnn: skipped`,
|
||||
sub_test.go:NNN: an error
|
||||
sub_test.go:NNN: skipped`,
|
||||
f: func(b *B) {
|
||||
b.Error("an error")
|
||||
b.Skip("skipped")
|
||||
@ -523,25 +524,19 @@ func TestBRun(t *T) {
|
||||
if root.result.N != 1 {
|
||||
t.Errorf("%s: N for parent benchmark was %d; want 1", tc.desc, root.result.N)
|
||||
}
|
||||
got := sanitizeLog(buf.String())
|
||||
want := sanitizeLog(tc.output)
|
||||
if got != want {
|
||||
got := strings.TrimSpace(buf.String())
|
||||
want := strings.TrimSpace(tc.output)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sanitizeLog removes line numbers from log entries.
|
||||
func sanitizeLog(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
lines := strings.Split(s, "\n")
|
||||
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 makeRegexp(s string) string {
|
||||
s = strings.Replace(s, ":NNN:", `:\d\d\d:`, -1)
|
||||
s = strings.Replace(s, "(N.NNs)", `\(\d*\.\d*s\)`, -1)
|
||||
return s
|
||||
}
|
||||
|
||||
func TestBenchmarkOutput(t *T) {
|
||||
|
Loading…
Reference in New Issue
Block a user