-
Notifications
You must be signed in to change notification settings - Fork 0
/
testx_test.go
46 lines (40 loc) · 930 Bytes
/
testx_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
package testx_test
import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/zpatrick/testx"
"github.com/zpatrick/testx/assert"
)
var (
stackTraceLoggingOpts = testx.StackTraceLoggingOptions{
BufferSize: 2000,
SkipLines: 6,
DisableMethods: testx.LoggingMethodSwitch{
Fatal: false,
Fatalf: true,
Log: true,
Logf: true,
},
}
prefixLoggingOpts = testx.PrefixLoggingOptions{
PrefixFunc: func() string {
return fmt.Sprintf("(%s)", time.Now().Format("15:04:05.9999"))
},
}
)
func setupTB(t testing.TB) testing.TB {
return testx.Wrap(t,
testx.WithStackTraceLogging(stackTraceLoggingOpts),
testx.WithPrefixLogging(prefixLoggingOpts),
)
}
func TestExample(t *testing.T) {
tb := setupTB(t)
tb.Log("test running")
assert.Equal(tb, 1, 1)
tb.Log("test is still running")
assert.Equal(testx.Prefix(tb, "unexpected random number generated:"), rand.Int(), 1)
tb.Log("test completed")
}