Skip to content

Commit 3445c35

Browse files
jeanbzadmitshur
authored andcommitted
[release-branch.go1.14] 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. Updates #38458. For #39308. 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]> Reviewed-on: https://go-review.googlesource.com/c/go/+/242058 Reviewed-by: Jean de Klerk <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]>
1 parent 4298b46 commit 3445c35

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
@@ -348,15 +348,14 @@ func (p *testPrinter) Print(testName, out string) {
348348
}
349349

350350
func (p *testPrinter) Fprint(w io.Writer, testName, out string) {
351-
if !p.chatty || strings.HasPrefix(out, "--- PASS") || strings.HasPrefix(out, "--- FAIL") {
352-
fmt.Fprint(w, out)
353-
return
354-
}
355-
356351
p.lastNameMu.Lock()
357352
defer p.lastNameMu.Unlock()
358353

359-
if strings.HasPrefix(out, "=== CONT") || strings.HasPrefix(out, "=== RUN") {
354+
if !p.chatty ||
355+
strings.HasPrefix(out, "--- PASS") ||
356+
strings.HasPrefix(out, "--- FAIL") ||
357+
strings.HasPrefix(out, "=== CONT") ||
358+
strings.HasPrefix(out, "=== RUN") {
360359
p.lastName = testName
361360
fmt.Fprint(w, out)
362361
return

0 commit comments

Comments
 (0)