-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors_test.go
53 lines (44 loc) · 1.25 KB
/
errors_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
package result_test
import (
"testing"
"github.com/bmheenan/result"
)
func TestErrorsOrReturnPanics(t *testing.T) {
defer func() {
r := recover()
e, ok := r.(error)
if !ok {
t.Errorf("Panic wasn't an error, it was a %T", r)
}
if x, g := "Unrecovered panic from result. Use `defer result.HandleReturn()`, `defer result.Handle(&r)`, or `defer result.HandleError(&err)` at the top of the func to convert the panic into a return",
e.Error(); x != g {
t.Errorf("Expected Error '%v' but got '%v'", x, g)
}
}()
errorsOrReturnPanics()
}
func errorsOrReturnPanics() {
errorsErr().
OrDoAndReturn(func(e error) {})
}
func TestErrorsOrErrPanics(t *testing.T) {
defer func() {
r := recover()
e, ok := r.(error)
if !ok {
t.Errorf("Panic wasn't an error, it was a %T", r)
}
if x, g := "Unrecovered panic from result. Use `defer result.Handle(&r)` or `defer result.HandleError(&err)` at the top of the func to convert the panic into a returned result or error: Expected error: Test error",
e.Error(); x != g {
t.Errorf("Expected Error '%v' but got '%v'", x, g)
}
}()
errorsOrErrPanics()
}
func errorsOrErrPanics() {
errorsErr().
OrError("Expected error")
}
func errorsErr() (r result.Status) {
return result.Errorf("Test error")
}