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.
12 func TestTBHelper(t *T) {
13 var buf strings.Builder
14 ctx := newTestContext(1, allMatcher())
17 signal: make(chan bool),
22 t1.Run("Test", testHelper)
24 want := `--- FAIL: Test (?s)
25 helperfuncs_test.go:12: 0
26 helperfuncs_test.go:40: 1
27 helperfuncs_test.go:21: 2
28 helperfuncs_test.go:42: 3
29 helperfuncs_test.go:49: 4
30 --- FAIL: Test/sub (?s)
31 helperfuncs_test.go:52: 5
32 helperfuncs_test.go:21: 6
33 helperfuncs_test.go:51: 7
34 helperfuncs_test.go:63: 8
35 --- FAIL: Test/sub2 (?s)
36 helperfuncs_test.go:78: 11
37 helperfuncs_test.go:82: recover 12
38 helperfuncs_test.go:84: GenericFloat64
39 helperfuncs_test.go:85: GenericInt
40 helperfuncs_test.go:71: 9
41 helperfuncs_test.go:67: 10
43 lines := strings.Split(buf.String(), "\n")
44 durationRE := regexp.MustCompile(`\(.*\)$`)
45 for i, line := range lines {
46 line = strings.TrimSpace(line)
47 line = durationRE.ReplaceAllString(line, "(?s)")
50 got := strings.Join(lines, "\n")
52 t.Errorf("got output:\n\n%s\nwant:\n\n%s", got, want)
56 func TestTBHelperParallel(t *T) {
57 var buf strings.Builder
58 ctx := newTestContext(1, newMatcher(regexp.MatchString, "", "", ""))
61 signal: make(chan bool),
66 t1.Run("Test", parallelTestHelper)
68 lines := strings.Split(strings.TrimSpace(buf.String()), "\n")
70 t.Fatalf("parallelTestHelper gave %d lines of output; want 6", len(lines))
72 want := "helperfuncs_test.go:21: parallel"
73 if got := strings.TrimSpace(lines[1]); got != want {
74 t.Errorf("got output line %q; want %q", got, want)
80 func (nw *noopWriter) Write(b []byte) (int, error) { return len(b), nil }
82 func BenchmarkTBHelper(b *B) {
84 ctx := newTestContext(1, allMatcher())
87 signal: make(chan bool),
100 for i := 0; i < b.N; i++ {