-
Notifications
You must be signed in to change notification settings - Fork 2
/
error_test.go
42 lines (39 loc) · 972 Bytes
/
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
package main
import (
"testing"
)
func TestConsAsError(t *testing.T) {
inner := func() error {
return Cons(Atom{"anError"}, Nil)
}
err := inner()
if err == nil {
t.Error("expected error")
}
if err.Error() != "(anError)" {
t.Error("wrong error message")
}
}
func TestStackTrace(t *testing.T) {
inner1 := func() error {
return baseError("innerError")
}
inner2 := func() error {
return extendWithList(list(Atom{"middleError"},
stringsToList("with", "some", "extra", "info")), inner1())
}
inner3 := func() error {
return extendWithList(list(Atom{"outerError"}), inner2())
}
err := inner3().(*ConsCell)
if err == nil {
t.Error("expected error")
}
if err.Error() != "((outerError) (middleError (with some extra info)) (innerError))" {
t.Error("wrong error message:", err.Error())
}
// Ensure we can pick apart the stacktrace
if !err.car.Equal(list(Atom{"outerError"})) {
t.Error("incorrect car for error message:", err.Error())
}
}