-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoops_test.go
More file actions
50 lines (43 loc) · 1.23 KB
/
oops_test.go
File metadata and controls
50 lines (43 loc) · 1.23 KB
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
package oops
import (
"errors"
"strings"
"testing"
)
// TODO: write the tests for Error funcs
var errorMessage = "testing"
var infoMessage = "info message"
var file = "github.com/5anthosh/oops/oops_test.go"
func test2() *Error {
return test()
}
func test() *Error {
return T(errors.New(errorMessage)).(*Error).Info(infoMessage)
}
func TestT(t *testing.T) {
err := test2()
if err.error.Error() != errorMessage {
t.Errorf("want %q instead got %q", errorMessage, err.error.Error())
}
if err.info != "info message" {
t.Errorf("want %q instead got %q", infoMessage, err.info)
}
errortrace := err.stackTrace
top := errortrace[0]
teststack(top, t, "github.com/5anthosh/oops.test", 19, file)
belowTest := errortrace[1]
teststack(belowTest, t, "github.com/5anthosh/oops.test2", 16, file)
testFunc := errortrace[2]
teststack(testFunc, t, "github.com/5anthosh/oops.TestT", 23, file)
}
func teststack(s Stack, t *testing.T, funcName string, line int, fileName string) {
if s.FuncName != funcName {
t.Errorf("want %q instead got %q", funcName, s.FuncName)
}
if s.Line != line {
t.Errorf("want %d instead got %d", line, s.Line)
}
if !strings.HasSuffix(s.File, fileName) {
t.Errorf("%q does not have suffix %q", s.File, fileName)
}
}