-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror_test.go
51 lines (39 loc) · 1 KB
/
error_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
package e
import (
"errors"
"fmt"
"testing"
)
func _print(t *testing.T, err Error) {
t.Log("msg:", err.Error())
_printStack(t, err.Stack())
fmt.Printf("%#v\n", err)
}
func _printStack(t *testing.T, stack ErrorStackChain) {
for _, item := range stack {
t.Log(fmt.Sprintf("%s,%s:%v", item.FuncName, item.File, item.Line))
}
}
func TestNew(t *testing.T) {
err := New("only show a custom errors demo")
_print(t, err)
}
func TestNewWithError(t *testing.T) {
goErr := errors.New("这是官方标准错误")
err := NewWithError("手动添加的错误", goErr)
_print(t, err)
}
func TestError_Error(t *testing.T) {
err := New("only show a custom errors demo")
t.Log(err.Error())
fmt.Println("\n", err.ErrorWithStack())
}
func TestError_ErrorWithStack(t *testing.T) {
goErr := errors.New("这是官方标准错误")
err := NewWithError("手动添加的错误", goErr)
t.Log(err.Error())
}
func TestError_Stack(t *testing.T) {
err := New("only show a custom errors demo")
_printStack(t, err.Stack())
}