-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.go
More file actions
43 lines (39 loc) · 1.05 KB
/
test.go
File metadata and controls
43 lines (39 loc) · 1.05 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
package termstatus
import (
"fmt"
"reflect"
"testing"
)
// Assert fails the test if the condition is false.
func Assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
tb.Helper()
if !condition {
tb.Fatalf("\033[31m"+msg+"\033[39m\n\n", v...)
}
}
// OK fails the test if an err is not nil.
func OK(tb testing.TB, err error) {
tb.Helper()
if err != nil {
tb.Fatalf("\033[31munexpected error: %+v\033[39m\n\n", err)
}
}
// Equals fails the test if exp is not equal to act.
// msg is optional message to be printed, first param being format string and rest being arguments.
func Equals(tb testing.TB, exp, act interface{}, msgs ...string) {
tb.Helper()
if !reflect.DeepEqual(exp, act) {
var msgString string
length := len(msgs)
if length == 1 {
msgString = msgs[0]
} else if length > 1 {
args := make([]interface{}, length-1)
for i, msg := range msgs[1:] {
args[i] = msg
}
msgString = fmt.Sprintf(msgs[0], args...)
}
tb.Fatalf("\033[31m\n\n\t"+msgString+"\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", exp, act)
}
}