-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
62 lines (55 loc) · 1.51 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
52
53
54
55
56
57
58
59
60
61
62
package catch_test
import (
"errors"
"testing"
"github.com/tada/catch"
)
func TestError(t *testing.T) {
err := errors.New("the error")
ex := catch.Error(err)
if err.Error() != ex.Error() {
t.Error("Error() created error produces wrong error string")
}
if !catch.IsError(ex) {
t.Error("IsError() returns false for Error() created error ")
}
if catch.Cause(ex) != err {
t.Error("Cause() does not return original error for Error() created error ")
}
if catch.Cause(err) != nil {
t.Error("Cause() does not return nil on unknown errors")
}
}
func TestError_string(t *testing.T) {
ex := catch.Error("the error")
if ex.Error() != "the error" {
t.Error("Error() created error produces wrong error string")
}
if !catch.IsError(ex) {
t.Error("IsError() returns false for Error() created error ")
}
}
func TestError_fmt(t *testing.T) {
ex := catch.Error("the numbers %d and %d are illegal", 38, 70)
if ex.Error() != "the numbers 38 and 70 are illegal" {
t.Error("Error() created error produces wrong error string")
}
}
func TestError_noArgs(t *testing.T) {
defer func() {
err := recover()
if err == nil || err.(error).Error() != "catch.Error(): illegal argument" {
t.Errorf("expected illegal argument panic")
}
}()
_ = catch.Error()
}
func TestError_badArgs(t *testing.T) {
defer func() {
err := recover()
if err == nil || err.(error).Error() != "catch.Error(): illegal argument" {
t.Errorf("expected illegal argument panic")
}
}()
_ = catch.Error(errors.New("oops"), "bad additional arg")
}