-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathspec_helper_test.go
66 lines (54 loc) · 1.27 KB
/
spec_helper_test.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package testcase_test
import (
"bytes"
"testing"
"go.llib.dev/testcase/internal/doubles"
"go.llib.dev/testcase/sandbox"
"go.llib.dev/testcase/assert"
)
type CustomTB struct {
testing.TB
isFatalFCalled bool
}
func (tb *CustomTB) Run(name string, blk func(tb testing.TB)) bool {
switch tb := tb.TB.(type) {
case *testing.T:
return tb.Run(name, func(t *testing.T) { blk(t) })
case *testing.B:
return tb.Run(name, func(b *testing.B) { blk(b) })
default:
panic("implement me")
}
}
func (t *CustomTB) Fatalf(format string, args ...interface{}) {
t.isFatalFCalled = true
return
}
func unsupported(tb testing.TB) {
tb.Helper()
tb.Skip(`unsupported`)
}
func isFatalFn(stub *doubles.TB) func(block func()) bool {
return func(block func()) bool {
stub.IsFailed = false
defer func() { stub.IsFailed = false }()
var finished bool
sandbox.Run(func() {
block()
finished = true
})
ltb, ok := stub.LastRunTB()
if !ok {
ltb = stub
}
return !finished && (ltb.Failed() || stub.Failed())
}
}
func willFatalWithMessageFn(stub *doubles.TB) func(tb testing.TB, blk func()) string {
isFatal := isFatalFn(stub)
return func(tb testing.TB, blk func()) string {
stub.Logs = bytes.Buffer{}
assert.Must(tb).True(isFatal(blk))
return stub.Logs.String()
}
}