blob: 0f44b5dc4f3ba008db7f657cc686cfb365e53c50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package stub
import "testing"
// PanicExit is a magic panic value treated as a simulated exit.
const PanicExit = 0xdeadbeef
const (
panicFailNow = 0xcafe0000 + iota
panicFatal
panicFatalf
)
// HandleExit must be deferred before calling with the stub.
func (s *Stub[K]) HandleExit() { handleExit(s.TB, true) }
func handleExit(t testing.TB, root bool) {
switch r := recover(); r {
case PanicExit:
break
case panicFailNow:
if root {
t.FailNow()
} else {
t.Fail()
}
break
case panicFatal, panicFatalf, nil:
break
default:
panic(r)
}
}
|