1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 func TestTBHelper(t
*T
) {
15 ctx
:= newTestContext(1, newMatcher(regexp
.MatchString
, "", ""))
18 signal
: make(chan bool),
23 t1
.Run("Test", testHelper
)
25 want
:= `--- FAIL: Test (?s)
26 helperfuncs_test.go:12: 0
27 helperfuncs_test.go:33: 1
28 helperfuncs_test.go:21: 2
29 helperfuncs_test.go:35: 3
30 helperfuncs_test.go:42: 4
31 --- FAIL: Test/sub (?s)
32 helperfuncs_test.go:45: 5
33 helperfuncs_test.go:21: 6
34 helperfuncs_test.go:44: 7
35 helperfuncs_test.go:56: 8
36 --- FAIL: Test/sub2 (?s)
37 helperfuncs_test.go:71: 11
38 helperfuncs_test.go:75: recover 12
39 helperfuncs_test.go:64: 9
40 helperfuncs_test.go:60: 10
42 lines
:= strings
.Split(buf
.String(), "\n")
43 durationRE
:= regexp
.MustCompile(`\(.*\)$`)
44 for i
, line
:= range lines
{
45 line
= strings
.TrimSpace(line
)
46 line
= durationRE
.ReplaceAllString(line
, "(?s)")
49 got
:= strings
.Join(lines
, "\n")
51 t
.Errorf("got output:\n\n%s\nwant:\n\n%s", got
, want
)
55 func TestTBHelperParallel(t
*T
) {
57 ctx
:= newTestContext(1, newMatcher(regexp
.MatchString
, "", ""))
60 signal
: make(chan bool),
65 t1
.Run("Test", parallelTestHelper
)
67 lines
:= strings
.Split(strings
.TrimSpace(buf
.String()), "\n")
69 t
.Fatalf("parallelTestHelper gave %d lines of output; want 6", len(lines
))
71 want
:= "helperfuncs_test.go:21: parallel"
72 if got
:= strings
.TrimSpace(lines
[1]); got
!= want
{
73 t
.Errorf("got output line %q; want %q", got
, want
)
79 func (nw
*noopWriter
) Write(b
[]byte) (int, error
) { return len(b
), nil }
81 func BenchmarkTBHelper(b
*B
) {
83 ctx
:= newTestContext(1, newMatcher(regexp
.MatchString
, "", ""))
86 signal
: make(chan bool),
99 for i
:= 0; i
< b
.N
; i
++ {