1 // Copyright 2020 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 TestBadFatalf(t *testing.T) {
17 for i := 0; i < 2; i++ {
21 t.Fatalf("TestFailed: id = %v\n", id) // want "call to .+T.+Fatalf from a non-test goroutine"
26 func TestOKErrorf(t *testing.T) {
30 for i := 0; i < 2; i++ {
34 t.Errorf("TestFailed: id = %v\n", id)
39 func BenchmarkBadFatalf(b *testing.B) {
43 for i := 0; i < b.N; i++ {
47 b.Fatalf("TestFailed: id = %v\n", id) // want "call to .+B.+Fatalf from a non-test goroutine"
52 func TestBadFatal(t *testing.T) {
56 for i := 0; i < 2; i++ {
60 t.Fatal("TestFailed") // want "call to .+T.+Fatal from a non-test goroutine"
65 func BenchmarkBadFatal(b *testing.B) {
69 for i := 0; i < b.N; i++ {
73 b.Fatal("TestFailed") // want "call to .+B.+Fatal from a non-test goroutine"
78 func BenchmarkOKErrorf(b *testing.B) {
82 for i := 0; i < b.N; i++ {
86 b.Errorf("TestFailed: %d", i)
91 func BenchmarkBadFatalGoGo(b *testing.B) {
95 for i := 0; i < b.N; i++ {
100 b.Fatal("TestFailed") // want "call to .+B.+Fatal from a non-test goroutine"
106 defer b.Fatal("here")
111 b.Fatal("in here") // want "call to .+B.+Fatal from a non-test goroutine"
120 b.Fatal("Here") // want "call to .+B.+Fatal from a non-test goroutine"
129 go b.Fatal("Failed") // want "call to .+B.+Fatal from a non-test goroutine"
134 go b.Fatal("Here") // want "call to .+B.+Fatal from a non-test goroutine"
138 func BenchmarkBadSkip(b *testing.B) {
139 for i := 0; i < b.N; i++ {
141 go b.Skip("Skipping") // want "call to .+B.+Skip from a non-test goroutine"
146 b.Skip("Skipping now") // want "call to .+B.+Skip from a non-test goroutine"
153 func TestBadSkip(t *testing.T) {
154 for i := 0; i < 1000; i++ {
156 go t.Skip("Skipping") // want "call to .+T.+Skip from a non-test goroutine"
161 t.Skip("Skipping now") // want "call to .+T.+Skip from a non-test goroutine"
168 func BenchmarkBadFailNow(b *testing.B) {
169 for i := 0; i < b.N; i++ {
171 go b.FailNow() // want "call to .+B.+FailNow from a non-test goroutine"
176 b.FailNow() // want "call to .+B.+FailNow from a non-test goroutine"
183 func TestBadFailNow(t *testing.T) {
184 for i := 0; i < 1000; i++ {
186 go t.FailNow() // want "call to .+T.+FailNow from a non-test goroutine"
191 t.FailNow() // want "call to .+T.+FailNow from a non-test goroutine"
198 func TestBadWithLoopCond(ty *testing.T) {
199 var wg sync.WaitGroup
202 for i := 0; i < 10; i++ {
205 defer ty.Fatalf("Why") // want "call to .+T.+Fatalf from a non-test goroutine"
207 for j := 0; j < 2; ty.FailNow() { // want "call to .+T.+FailNow from"
209 ty.Errorf("Done here")
218 func (ct *customType) Fatalf(fmtSpec string, args ...interface{}) {
220 panic("empty format specifier")
224 func (ct *customType) FailNow() {}
225 func (ct *customType) Skip() {}
227 func TestWithLogFatalf(t *testing.T) {
228 var wg sync.WaitGroup
231 for i := 0; i < 10; i++ {
235 for j := 0; j < 2; j++ {
236 log.Fatal("Done here")
243 func TestWithCustomType(t *testing.T) {
244 var wg sync.WaitGroup
247 ct := new(customType)
251 for i := 0; i < 10; i++ {
255 for j := 0; j < 2; j++ {
256 ct.Fatalf("Done here: %d", i)