Skip to content

Commit ba6ccf3

Browse files
committed
testing: capture testname on --- PASS and --- FAIL lines
This fixes an issue raised at #38458 (comment) in which --- PASS and --- FAIL lines would not trigger --- CONT lines of other tests. Change-Id: I0d8cc54d682a370d0a6ea6816a11b2e462a92efe Reviewed-on: https://go-review.googlesource.com/c/go/+/235997 Run-TryBot: Emmanuel Odeke <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent a9cc105 commit ba6ccf3

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Run parallel chatty tests. Assert on CONT lines. This test makes sure that
2+
# multiple parallel outputs have the appropriate CONT lines between them.
3+
go test -parallel 3 chatty_parallel_test.go -v
4+
5+
stdout '--- PASS: TestFast \([0-9.]{4}s\)\n=== CONT TestSlow\n chatty_parallel_test.go:31: this is the second TestSlow log\n--- PASS: TestSlow \([0-9.]{4}s\)'
6+
7+
-- chatty_parallel_test.go --
8+
package chatty_paralell_test
9+
10+
import (
11+
"testing"
12+
"time"
13+
)
14+
15+
var (
16+
run = make(chan struct{})
17+
afterFirstLog = make(chan struct{})
18+
afterPass = make(chan struct{})
19+
)
20+
21+
func TestFast(t *testing.T) {
22+
t.Parallel()
23+
24+
<-afterFirstLog
25+
t.Cleanup(func() {
26+
close(afterPass)
27+
})
28+
}
29+
30+
func TestSlow(t *testing.T) {
31+
t.Parallel()
32+
33+
t.Logf("this is the first TestSlow log")
34+
close(afterFirstLog)
35+
36+
<-afterPass
37+
time.Sleep(100 * time.Millisecond)
38+
t.Logf("this is the second TestSlow log")
39+
}

src/testing/testing.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,14 @@ func (p *testPrinter) Print(testName, out string) {
353353
}
354354

355355
func (p *testPrinter) Fprint(w io.Writer, testName, out string) {
356-
if !p.chatty || strings.HasPrefix(out, "--- PASS") || strings.HasPrefix(out, "--- FAIL") {
357-
fmt.Fprint(w, out)
358-
return
359-
}
360-
361356
p.lastNameMu.Lock()
362357
defer p.lastNameMu.Unlock()
363358

364-
if strings.HasPrefix(out, "=== CONT") || strings.HasPrefix(out, "=== RUN") {
359+
if !p.chatty ||
360+
strings.HasPrefix(out, "--- PASS") ||
361+
strings.HasPrefix(out, "--- FAIL") ||
362+
strings.HasPrefix(out, "=== CONT") ||
363+
strings.HasPrefix(out, "=== RUN") {
365364
p.lastName = testName
366365
fmt.Fprint(w, out)
367366
return

0 commit comments

Comments
 (0)