Debian Codegraph @

td/t_struct_test.go

raw
1 // Copyright (c) 2018-2021, Maxime Soulé
2 // All rights reserved.
3 //
4 // This source code is licensed under the BSD-style license found in the
5 // LICENSE file in the root directory of this source tree.
6
7 package td_test
8
9 import (
10 "regexp"
11 "strings"
12 "sync"
13 "testing"
14 "time"
15
16 "github.com/maxatome/go-testdeep/internal/test"
17 "github.com/maxatome/go-testdeep/internal/trace"
18 "github.com/maxatome/go-testdeep/td"
19 )
20
21 func TestT(tt *testing.T) {
22 // We don't want to include "anchors" field in comparison
23 cmp := func(tt *testing.T, got, expected td.ContextConfig) {
24 tt.Helper()
25 td.Cmp(tt, got,
26 td.SStruct(expected, td.StructFields{
27 "anchors": td.Ignore(),
28 "hooks": td.Ignore(),
29 }),
30 )
31 }
32
33 tt.Run("without config", func(tt *testing.T) {
34 t := td.NewT(tt)
35 cmp(tt, t.Config, td.DefaultContextConfig)
36
37 tDup := td.NewT(t)
38 cmp(tt, tDup.Config, td.DefaultContextConfig)
39 })
40
41 tt.Run("explicit default config", func(tt *testing.T) {
42 t := td.NewT(tt, td.ContextConfig{})
43 cmp(tt, t.Config, td.DefaultContextConfig)
44
45 tDup := td.NewT(t)
46 cmp(tt, tDup.Config, td.DefaultContextConfig)
47 })
48
49 tt.Run("specific config", func(tt *testing.T) {
50 conf := td.ContextConfig{
51 RootName: "TEST",
52 MaxErrors: 33,
53 }
54 t := td.NewT(tt, conf)
55 cmp(tt, t.Config, conf)
56
57 tDup := td.NewT(t)
58 cmp(tt, tDup.Config, conf)
59
60 newConf := conf
61 newConf.MaxErrors = 34
62 tDup = td.NewT(t, newConf)
63 cmp(tt, tDup.Config, newConf)
64
65 t2 := t.RootName("T2")
66 cmp(tt, t.Config, conf)
67 cmp(tt, t2.Config, td.ContextConfig{
68 RootName: "T2",
69 MaxErrors: 33,
70 })
71
72 t3 := t.RootName("")
73 cmp(tt, t3.Config, td.ContextConfig{
74 RootName: "DATA",
75 MaxErrors: 33,
76 })
77 })
78
79 //
80 // Bad usages
81 ttb := test.NewTestingTB("usage params")
82 ttb.CatchFatal(func() {
83 td.NewT(ttb, td.ContextConfig{}, td.ContextConfig{})
84 })
85 test.IsTrue(tt, ttb.IsFatal)
86 test.IsTrue(tt, strings.Contains(ttb.Messages[0], "usage: NewT("))
87
88 test.CheckPanic(tt, func() { td.NewT(nil) }, "usage: NewT")
89 }
90
91 func TestTCmp(tt *testing.T) {
92 ttt := test.NewTestingTB(tt.Name())
93 t := td.NewT(ttt)
94 test.IsTrue(tt, t.Cmp(1, 1))
95 test.IsFalse(tt, ttt.Failed())
96
97 ttt = test.NewTestingTB(tt.Name())
98 t = td.NewT(ttt)
99 test.IsFalse(tt, t.Cmp(1, 2))
100 test.IsTrue(tt, ttt.Failed())
101 }
102
103 func TestTCmpDeeply(tt *testing.T) {
104 ttt := test.NewTestingTB(tt.Name())
105 t := td.NewT(ttt)
106 test.IsTrue(tt, t.CmpDeeply(1, 1))
107 test.IsFalse(tt, ttt.Failed())
108
109 ttt = test.NewTestingTB(tt.Name())
110 t = td.NewT(ttt)
111 test.IsFalse(tt, t.CmpDeeply(1, 2))
112 test.IsTrue(tt, ttt.Failed())
113 }
114
115 func TestParallel(t *testing.T) {
116 t.Run("without Parallel", func(tt *testing.T) {
117 ttt := test.NewTestingTB(tt.Name())
118
119 t := td.NewT(ttt)
120 t.Parallel()
121
122 // has no effect
123 })
124
125 t.Run("with Parallel", func(tt *testing.T) {
126 ttt := test.NewParallelTestingTB(tt.Name())
127
128 t := td.NewT(ttt)
129 t.Parallel()
130
131 test.IsTrue(tt, ttt.IsParallel)
132 })
133
134 t.Run("Run with Parallel", func(tt *testing.T) {
135 // This test verifies that subtests with t.Parallel() are run
136 // in parallel. We use a WaitGroup to make both subtests block
137 // until they're both ready. This test will block forever if
138 // the tests are not run together.
139 var ready sync.WaitGroup
140 ready.Add(2)
141
142 t := td.NewT(tt)
143
144 t.Run("level 1", func(t *td.T) {
145 t.Parallel()
146
147 ready.Done() // I'm ready.
148 ready.Wait() // Are you?
149 })
150
151 t.Run("level 2", func(t *td.T) {
152 t.Parallel()
153
154 ready.Done() // I'm ready.
155 ready.Wait() // Are you?
156 })
157 })
158 }
159
160 func TestRun(t *testing.T) {
161 t.Run("test.TB with Run", func(tt *testing.T) {
162 t := td.NewT(tt)
163
164 runPassed := false
165 nestedFailureIsFatal := false
166
167 ok := t.Run("Test level1",
168 func(t *td.T) {
169 ok := t.FailureIsFatal().Run("Test level2",
170 func(t *td.T) {
171 runPassed = t.True(true) // test succeeds!
172
173 // Check we inherit config from caller
174 nestedFailureIsFatal = t.Config.FailureIsFatal
175 })
176
177 t.True(ok)
178 })
179
180 test.IsTrue(tt, ok)
181 test.IsTrue(tt, runPassed)
182 test.IsTrue(tt, nestedFailureIsFatal)
183 })
184
185 t.Run("test.TB without Run", func(tt *testing.T) {
186 t := td.NewT(test.NewTestingTB("gg"))
187
188 runPassed := false
189
190 ok := t.Run("Test level1",
191 func(t *td.T) {
192 ok := t.Run("Test level2",
193 func(t *td.T) {
194 runPassed = t.True(true) // test succeeds!
195 })
196
197 t.True(ok)
198 })
199
200 t.True(ok)
201 t.True(runPassed)
202 })
203 }
204
205 func TestRunAssertRequire(t *testing.T) {
206 t.Run("test.TB with Run", func(tt *testing.T) {
207 t := td.NewT(tt)
208
209 runPassed := false
210 assertIsFatal := true
211 requireIsFatal := false
212
213 ok := t.RunAssertRequire("Test level1",
214 func(assert, require *td.T) {
215 assertIsFatal = assert.Config.FailureIsFatal
216 requireIsFatal = require.Config.FailureIsFatal
217
218 ok := assert.RunAssertRequire("Test level2",
219 func(assert, require *td.T) {
220 runPassed = assert.True(true) // test succeeds!
221 runPassed = runPassed && require.True(true) // test succeeds!
222
223 assertIsFatal = assertIsFatal || assert.Config.FailureIsFatal
224 requireIsFatal = requireIsFatal && require.Config.FailureIsFatal
225 })
226 assert.True(ok)
227 require.True(ok)
228
229 ok = require.RunAssertRequire("Test level2",
230 func(assert, require *td.T) {
231 runPassed = runPassed && assert.True(true) // test succeeds!
232 runPassed = runPassed && require.True(true) // test succeeds!
233
234 assertIsFatal = assertIsFatal || assert.Config.FailureIsFatal
235 requireIsFatal = requireIsFatal && require.Config.FailureIsFatal
236 })
237 assert.True(ok)
238 require.True(ok)
239 })
240
241 test.IsTrue(tt, ok)
242 test.IsTrue(tt, runPassed)
243 test.IsFalse(tt, assertIsFatal)
244 test.IsTrue(tt, requireIsFatal)
245 })
246
247 t.Run("test.TB without Run", func(tt *testing.T) {
248 t := td.NewT(test.NewTestingTB("gg"))
249
250 runPassed := false
251 assertIsFatal := true
252 requireIsFatal := false
253
254 ok := t.RunAssertRequire("Test level1",
255 func(assert, require *td.T) {
256 assertIsFatal = assert.Config.FailureIsFatal
257 requireIsFatal = require.Config.FailureIsFatal
258
259 ok := assert.RunAssertRequire("Test level2",
260 func(assert, require *td.T) {
261 runPassed = assert.True(true) // test succeeds!
262 runPassed = runPassed && require.True(true) // test succeeds!
263
264 assertIsFatal = assertIsFatal || assert.Config.FailureIsFatal
265 requireIsFatal = requireIsFatal && require.Config.FailureIsFatal
266 })
267 assert.True(ok)
268 require.True(ok)
269
270 ok = require.RunAssertRequire("Test level2",
271 func(assert, require *td.T) {
272 runPassed = runPassed && assert.True(true) // test succeeds!
273 runPassed = runPassed && require.True(true) // test succeeds!
274
275 assertIsFatal = assertIsFatal || assert.Config.FailureIsFatal
276 requireIsFatal = requireIsFatal && require.Config.FailureIsFatal
277 })
278 assert.True(ok)
279 require.True(ok)
280 })
281
282 test.IsTrue(tt, ok)
283 test.IsTrue(tt, runPassed)
284 test.IsFalse(tt, assertIsFatal)
285 test.IsTrue(tt, requireIsFatal)
286 })
287 }
288
289 // Deprecated RunT.
290 func TestRunT(t *testing.T) {
291 t.Run("test.TB with Run", func(tt *testing.T) {
292 t := td.NewT(tt)
293
294 runPassed := false
295
296 ok := t.RunT("Test level1", //nolint: staticcheck
297 func(t *td.T) {
298 ok := t.RunT("Test level2", //nolint: staticcheck
299 func(t *td.T) {
300 runPassed = t.True(true) // test succeeds!
301 })
302
303 t.True(ok)
304 })
305
306 test.IsTrue(tt, ok)
307 test.IsTrue(tt, runPassed)
308 })
309
310 t.Run("test.TB without Run", func(tt *testing.T) {
311 t := td.NewT(test.NewTestingTB("gg"))
312
313 runPassed := false
314
315 ok := t.RunT("Test level1", //nolint: staticcheck
316 func(t *td.T) {
317 ok := t.RunT("Test level2", //nolint: staticcheck
318 func(t *td.T) {
319 runPassed = t.True(true) // test succeeds!
320 })
321
322 t.True(ok)
323 })
324
325 test.IsTrue(tt, ok)
326 test.IsTrue(tt, runPassed)
327 })
328 }
329
330 func TestFailureIsFatal(tt *testing.T) {
331 // All t.True(false) tests of course fail
332
333 // Using default config
334 ttt := test.NewTestingTB(tt.Name())
335 t := td.NewT(ttt)
336 t.True(false) // failure
337 test.IsTrue(tt, ttt.LastMessage() != "")
338 test.IsFalse(tt, ttt.IsFatal, "by default it is not fatal")
339
340 // Using specific config
341 ttt = test.NewTestingTB(tt.Name())
342 t = td.NewT(ttt, td.ContextConfig{FailureIsFatal: true})
343 ttt.CatchFatal(func() { t.True(false) }) // failure
344 test.IsTrue(tt, ttt.LastMessage() != "")
345 test.IsTrue(tt, ttt.IsFatal, "it must be fatal")
346
347 // Using FailureIsFatal()
348 ttt = test.NewTestingTB(tt.Name())
349 t = td.NewT(ttt).FailureIsFatal()
350 ttt.CatchFatal(func() { t.True(false) }) // failure
351 test.IsTrue(tt, ttt.LastMessage() != "")
352 test.IsTrue(tt, ttt.IsFatal, "it must be fatal")
353
354 // Using FailureIsFatal(true)
355 ttt = test.NewTestingTB(tt.Name())
356 t = td.NewT(ttt).FailureIsFatal(true)
357 ttt.CatchFatal(func() { t.True(false) }) // failure
358 test.IsTrue(tt, ttt.LastMessage() != "")
359 test.IsTrue(tt, ttt.IsFatal, "it must be fatal")
360
361 // Using T.Assert()
362 ttt = test.NewTestingTB(tt.Name())
363 t = td.NewT(ttt, td.ContextConfig{FailureIsFatal: true}).Assert()
364 t.True(false) // failure
365 test.IsTrue(tt, ttt.LastMessage() != "")
366 test.IsFalse(tt, ttt.IsFatal, "by default it is not fatal")
367
368 // Using T.Require()
369 ttt = test.NewTestingTB(tt.Name())
370 t = td.NewT(ttt).Require()
371 ttt.CatchFatal(func() { t.True(false) }) // failure
372 test.IsTrue(tt, ttt.LastMessage() != "")
373 test.IsTrue(tt, ttt.IsFatal, "it must be fatal")
374
375 // Using Require()
376 ttt = test.NewTestingTB(tt.Name())
377 t = td.Require(ttt)
378 ttt.CatchFatal(func() { t.True(false) }) // failure
379 test.IsTrue(tt, ttt.LastMessage() != "")
380 test.IsTrue(tt, ttt.IsFatal, "it must be fatal")
381
382 // Using Require() with specific config (cannot override FailureIsFatal)
383 ttt = test.NewTestingTB(tt.Name())
384 t = td.Require(ttt, td.ContextConfig{FailureIsFatal: false})
385 ttt.CatchFatal(func() { t.True(false) }) // failure
386 test.IsTrue(tt, ttt.LastMessage() != "")
387 test.IsTrue(tt, ttt.IsFatal, "it must be fatal")
388
389 // Canceling specific config
390 ttt = test.NewTestingTB(tt.Name())
391 t = td.NewT(ttt, td.ContextConfig{FailureIsFatal: false}).
392 FailureIsFatal(false)
393 t.True(false) // failure
394 test.IsTrue(tt, ttt.LastMessage() != "")
395 test.IsFalse(tt, ttt.IsFatal, "it must be not fatal")
396
397 // Using Assert()
398 ttt = test.NewTestingTB(tt.Name())
399 t = td.Assert(ttt)
400 t.True(false) // failure
401 test.IsTrue(tt, ttt.LastMessage() != "")
402 test.IsFalse(tt, ttt.IsFatal, "it must be not fatal")
403
404 // Using Assert() with specific config (cannot override FailureIsFatal)
405 ttt = test.NewTestingTB(tt.Name())
406 t = td.Assert(ttt, td.ContextConfig{FailureIsFatal: true})
407 t.True(false) // failure
408 test.IsTrue(tt, ttt.LastMessage() != "")
409 test.IsFalse(tt, ttt.IsFatal, "it must be not fatal")
410
411 // AssertRequire() / assert
412 ttt = test.NewTestingTB(tt.Name())
413 t, _ = td.AssertRequire(ttt)
414 t.True(false) // failure
415 test.IsTrue(tt, ttt.LastMessage() != "")
416 test.IsFalse(tt, ttt.IsFatal, "it must be not fatal")
417
418 // Using AssertRequire() / assert with specific config (cannot
419 // override FailureIsFatal)
420 ttt = test.NewTestingTB(tt.Name())
421 t, _ = td.AssertRequire(ttt, td.ContextConfig{FailureIsFatal: true})
422 t.True(false) // failure
423 test.IsTrue(tt, ttt.LastMessage() != "")
424 test.IsFalse(tt, ttt.IsFatal, "it must be not fatal")
425
426 // AssertRequire() / require
427 ttt = test.NewTestingTB(tt.Name())
428 _, t = td.AssertRequire(ttt)
429 ttt.CatchFatal(func() { t.True(false) }) // failure
430 test.IsTrue(tt, ttt.LastMessage() != "")
431 test.IsTrue(tt, ttt.IsFatal, "it must be fatal")
432
433 // Using AssertRequire() / require with specific config (cannot
434 // override FailureIsFatal)
435 ttt = test.NewTestingTB(tt.Name())
436 _, t = td.AssertRequire(ttt, td.ContextConfig{FailureIsFatal: true})
437 ttt.CatchFatal(func() { t.True(false) }) // failure
438 test.IsTrue(tt, ttt.LastMessage() != "")
439 test.IsTrue(tt, ttt.IsFatal, "it must be fatal")
440 }
441
442 func TestUseEqual(tt *testing.T) {
443 ttt := test.NewTestingTB(tt.Name())
444
445 var time1, time2 time.Time
446 for {
447 time1 = time.Now()
448 time2 = time1.Truncate(0)
449 if !time1.Equal(time2) {
450 tt.Fatal("time.Equal() does not work as expected")
451 }
452 if time1 != time2 { // to avoid the bad luck case where time1.wall=0
453 break
454 }
455 }
456
457 // Using default config
458 t := td.NewT(ttt)
459 test.IsFalse(tt, t.Cmp(time1, time2))
460
461 // UseEqual
462 t = td.NewT(ttt).UseEqual() // enable globally
463 test.IsTrue(tt, t.Cmp(time1, time2))
464
465 t = td.NewT(ttt).UseEqual(true) // enable globally
466 test.IsTrue(tt, t.Cmp(time1, time2))
467
468 t = td.NewT(ttt).UseEqual(false) // disable globally
469 test.IsFalse(tt, t.Cmp(time1, time2))
470
471 t = td.NewT(ttt).UseEqual(time.Time{}) // enable only for time.Time
472 test.IsTrue(tt, t.Cmp(time1, time2))
473
474 t = t.UseEqual().UseEqual(false) // enable then disable globally
475 test.IsTrue(tt, t.Cmp(time1, time2)) // Equal() still used
476
477 test.EqualStr(tt,
478 ttt.CatchFatal(func() { td.NewT(ttt).UseEqual(42) }),
479 "UseEqual expects type int owns an Equal method (@0)")
480 }
481
482 func TestBeLax(tt *testing.T) {
483 ttt := test.NewTestingTB(tt.Name())
484
485 // Using default config
486 t := td.NewT(ttt)
487 test.IsFalse(tt, t.Cmp(int64(123), 123))
488
489 // BeLax
490 t = td.NewT(ttt).BeLax()
491 test.IsTrue(tt, t.Cmp(int64(123), 123))
492
493 t = td.NewT(ttt).BeLax(true)
494 test.IsTrue(tt, t.Cmp(int64(123), 123))
495
496 t = td.NewT(ttt).BeLax(false)
497 test.IsFalse(tt, t.Cmp(int64(123), 123))
498 }
499
500 func TestIgnoreUnexported(tt *testing.T) {
501 ttt := test.NewTestingTB(tt.Name())
502
503 type SType1 struct {
504 Public int
505 private string
506 }
507 a1, b1 := SType1{Public: 42, private: "test"}, SType1{Public: 42}
508
509 type SType2 struct {
510 Public int
511 private string
512 }
513 a2, b2 := SType2{Public: 42, private: "test"}, SType2{Public: 42}
514
515 // Using default config
516 t := td.NewT(ttt)
517 test.IsFalse(tt, t.Cmp(a1, b1))
518
519 // IgnoreUnexported
520 t = td.NewT(ttt).IgnoreUnexported() // ignore unexported globally
521 test.IsTrue(tt, t.Cmp(a1, b1))
522 test.IsTrue(tt, t.Cmp(a2, b2))
523
524 t = td.NewT(ttt).IgnoreUnexported(true) // ignore unexported globally
525 test.IsTrue(tt, t.Cmp(a1, b1))
526 test.IsTrue(tt, t.Cmp(a2, b2))
527
528 t = td.NewT(ttt).IgnoreUnexported(false) // handle unexported globally
529 test.IsFalse(tt, t.Cmp(a1, b1))
530 test.IsFalse(tt, t.Cmp(a2, b2))
531
532 t = td.NewT(ttt).IgnoreUnexported(SType1{}) // ignore only for SType1
533 test.IsTrue(tt, t.Cmp(a1, b1))
534 test.IsFalse(tt, t.Cmp(a2, b2))
535
536 t = t.UseEqual().UseEqual(false) // enable then disable globally
537 test.IsTrue(tt, t.Cmp(a1, b1))
538 test.IsFalse(tt, t.Cmp(a2, b2))
539
540 t = td.NewT(ttt).IgnoreUnexported(SType1{}, SType2{}) // enable for both
541 test.IsTrue(tt, t.Cmp(a1, b1))
542 test.IsTrue(tt, t.Cmp(a2, b2))
543
544 test.EqualStr(tt,
545 ttt.CatchFatal(func() { td.NewT(ttt).IgnoreUnexported(42) }),
546 "IgnoreUnexported expects type int be a struct, not a int (@0)")
547 }
548
549 func TestTestDeepInGotOK(tt *testing.T) {
550 ttt := test.NewTestingTB(tt.Name())
551
552 var t *td.T
553 cmp := func() bool { return t.Cmp(td.Ignore(), td.Ignore()) }
554
555 // Using default config
556 t = td.NewT(ttt)
557 test.CheckPanic(tt, func() { cmp() },
558 "Found a TestDeep operator in got param, can only use it in expected one!")
559
560 t = td.NewT(ttt).TestDeepInGotOK()
561 test.IsTrue(tt, cmp())
562
563 t = t.TestDeepInGotOK(false)
564 test.CheckPanic(tt, func() { cmp() },
565 "Found a TestDeep operator in got param, can only use it in expected one!")
566
567 t = t.TestDeepInGotOK(true)
568 test.IsTrue(tt, cmp())
569 }
570
571 func TestLogTrace(tt *testing.T) {
572 ttt := test.NewTestingTB(tt.Name())
573
574 t := td.NewT(ttt)
575
576 //line /t_struct_test.go:100
577 t.LogTrace()
578 test.EqualStr(tt, ttt.LastMessage(), `Stack trace:
579 TestLogTrace() /t_struct_test.go:100`)
580 test.IsFalse(tt, ttt.HasFailed)
581 test.IsFalse(tt, ttt.IsFatal)
582 ttt.ResetMessages()
583
584 //line /t_struct_test.go:110
585 t.LogTrace("This is the %s:", "stack")
586 test.EqualStr(tt, ttt.LastMessage(), `This is the stack:
587 TestLogTrace() /t_struct_test.go:110`)
588 ttt.ResetMessages()
589
590 //line /t_struct_test.go:120
591 t.LogTrace("This is the %s:\n", "stack")
592 test.EqualStr(tt, ttt.LastMessage(), `This is the stack:
593 TestLogTrace() /t_struct_test.go:120`)
594 ttt.ResetMessages()
595
596 //line /t_struct_test.go:130
597 t.LogTrace("This is the ", "stack")
598 test.EqualStr(tt, ttt.LastMessage(), `This is the stack
599 TestLogTrace() /t_struct_test.go:130`)
600 ttt.ResetMessages()
601
602 trace.IgnorePackage()
603 defer trace.UnignorePackage()
604 //line /t_struct_test.go:140
605 t.LogTrace("Stack:\n")
606 test.EqualStr(tt, ttt.LastMessage(), `Stack:
607 Empty stack trace`)
608 }
609
610 func TestErrorTrace(tt *testing.T) {
611 ttt := test.NewTestingTB(tt.Name())
612
613 t := td.NewT(ttt)
614
615 //line /t_struct_test.go:200
616 t.ErrorTrace()
617 test.EqualStr(tt, ttt.LastMessage(), `Stack trace:
618 TestErrorTrace() /t_struct_test.go:200`)
619 test.IsTrue(tt, ttt.HasFailed)
620 test.IsFalse(tt, ttt.IsFatal)
621 ttt.ResetMessages()
622
623 //line /t_struct_test.go:210
624 t.ErrorTrace("This is the %s:", "stack")
625 test.EqualStr(tt, ttt.LastMessage(), `This is the stack:
626 TestErrorTrace() /t_struct_test.go:210`)
627 ttt.ResetMessages()
628
629 //line /t_struct_test.go:220
630 t.ErrorTrace("This is the %s:\n", "stack")
631 test.EqualStr(tt, ttt.LastMessage(), `This is the stack:
632 TestErrorTrace() /t_struct_test.go:220`)
633 ttt.ResetMessages()
634
635 //line /t_struct_test.go:230
636 t.ErrorTrace("This is the ", "stack")
637 test.EqualStr(tt, ttt.LastMessage(), `This is the stack
638 TestErrorTrace() /t_struct_test.go:230`)
639 ttt.ResetMessages()
640
641 trace.IgnorePackage()
642 defer trace.UnignorePackage()
643 //line /t_struct_test.go:240
644 t.ErrorTrace("Stack:\n")
645 test.EqualStr(tt, ttt.LastMessage(), `Stack:
646 Empty stack trace`)
647 }
648
649 func TestFatalTrace(tt *testing.T) {
650 ttt := test.NewTestingTB(tt.Name())
651
652 t := td.NewT(ttt)
653
654 match := func(got, expectedRe string) {
655 tt.Helper()
656 re := regexp.MustCompile(expectedRe)
657 if !re.MatchString(got) {
658 test.EqualErrorMessage(tt, got, expectedRe)
659 }
660 }
661
662 //line /t_struct_test.go:300
663 match(ttt.CatchFatal(func() { t.FatalTrace() }), `Stack trace:
664 TestFatalTrace\.func\d\(\) /t_struct_test\.go:300
665 \(\*TestingT\)\.CatchFatal\(\) internal/test/types\.go:\d+
666 TestFatalTrace\(\) /t_struct_test\.go:300`)
667 test.IsTrue(tt, ttt.HasFailed)
668 test.IsTrue(tt, ttt.IsFatal)
669 ttt.ResetMessages()
670
671 //line /t_struct_test.go:310
672 match(ttt.CatchFatal(func() { t.FatalTrace("This is the %s:", "stack") }),
673 `This is the stack:
674 TestFatalTrace\.func\d\(\) /t_struct_test\.go:310
675 \(\*TestingT\)\.CatchFatal\(\) internal/test/types\.go:\d+
676 TestFatalTrace\(\) /t_struct_test\.go:310`)
677 ttt.ResetMessages()
678
679 //line /t_struct_test.go:320
680 match(ttt.CatchFatal(func() { t.FatalTrace("This is the %s:\n", "stack") }),
681 `This is the stack:
682 TestFatalTrace\.func\d\(\) /t_struct_test\.go:320
683 \(\*TestingT\)\.CatchFatal\(\) internal/test/types\.go:\d+
684 TestFatalTrace\(\) /t_struct_test\.go:320`)
685 ttt.ResetMessages()
686
687 //line /t_struct_test.go:330
688 match(ttt.CatchFatal(func() { t.FatalTrace("This is the ", "stack") }),
689 `This is the stack
690 TestFatalTrace\.func\d\(\) /t_struct_test\.go:330
691 \(\*TestingT\)\.CatchFatal\(\) internal/test/types\.go:\d+
692 TestFatalTrace\(\) /t_struct_test\.go:330`)
693 ttt.ResetMessages()
694
695 trace.IgnorePackage()
696 defer trace.UnignorePackage()
697 //line /t_struct_test.go:340
698 test.EqualStr(tt, ttt.CatchFatal(func() { t.FatalTrace("Stack:\n") }),
699 `Stack:
700 Empty stack trace`)
701 }