-
Notifications
You must be signed in to change notification settings - Fork 1
/
caller_test.go
47 lines (40 loc) · 1022 Bytes
/
caller_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
package structlog_test
import (
"bytes"
"testing"
"github.com/powerman/check"
"github.com/powerman/structlog"
)
func testPanic(log *structlog.Logger) {
defer log.Recover(nil)
panic("oops")
}
//go:noinline
func testPanicWrapper(log *structlog.Logger) {
testPanic(log)
log.Info("wrapper")
}
//go:inline
func testPanicThinWrapper(log *structlog.Logger) {
testPanic(log)
}
func TestRecover(tt *testing.T) {
t := check.T(tt)
var buf bytes.Buffer
log := structlog.New().SetOutput(&buf)
testPanicAnon := func(log *structlog.Logger) {
defer log.Recover(nil)
panic("oops")
}
testPanicAnon(log)
t.Match(buf.String(), `@ structlog_test.TestRecover.func1\(caller_test.go:34\)`)
buf.Reset()
testPanic(log)
t.Match(buf.String(), `@ structlog_test.testPanic\(caller_test.go:14\)`)
buf.Reset()
testPanicWrapper(log)
t.Match(buf.String(), `@ structlog_test.testPanic\(caller_test.go:14\)`)
buf.Reset()
testPanicThinWrapper(log)
t.Match(buf.String(), `@ structlog_test.testPanic\(caller_test.go:14\)`)
}