-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.go
More file actions
48 lines (43 loc) · 1.15 KB
/
testing.go
File metadata and controls
48 lines (43 loc) · 1.15 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
package kronasje
import (
"fmt"
"path/filepath"
"runtime"
"reflect"
"testing"
)
const (
colorRED = "\033[31m"
colorNORMAL = "\033[39m"
)
// assert fails the test if the condition is false.
func assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
if !condition {
_, file, line, _ := runtime.Caller(1)
fmt.Printf(colorRED)
fmt.Printf("%s:%d:\n\n"+msg, append([]interface{}{filepath.Base(file), line}, v...)...)
fmt.Printf(colorNORMAL)
tb.FailNow()
}
}
// ok fails the test if an err is not nil.
func ok(tb testing.TB, err error) {
if err != nil {
_, file, line, _ := runtime.Caller(1)
fmt.Printf(colorRED)
fmt.Printf("%s:%d: unexpected error: %s\n\n", filepath.Base(file), line, err.Error())
fmt.Printf(colorNORMAL)
tb.FailNow()
}
}
// equals fails the test if exp is not equal to act.
func equals(tb testing.TB, exp, act interface{}) {
if !reflect.DeepEqual(exp, act) {
pc, file, line, _ := runtime.Caller(1)
fn := runtime.FuncForPC(pc).Name()
fmt.Printf(colorRED)
fmt.Printf("%s:%d (%v)\n\n\texp: %+v\n\n\tgot: %+v\n\n", filepath.Base(file), line, fn, exp, act)
fmt.Printf(colorNORMAL)
tb.FailNow()
}
}