-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhelpers_test.go
More file actions
50 lines (44 loc) · 1.24 KB
/
helpers_test.go
File metadata and controls
50 lines (44 loc) · 1.24 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 parallel
import (
"fmt"
"path/filepath"
"reflect"
"runtime"
"sync"
"testing"
)
// Assert fails the test if the condition is false.
func testAssert(t *testing.T, condition bool, msg string, v ...interface{}) {
if !condition {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
t.FailNow()
}
}
// ok fails the test if an err is not nil.
func testNil(t *testing.T, val interface{}) {
if val != nil {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d: unexpected value: %s\033[39m\n\n", filepath.Base(file), line, val)
t.FailNow()
}
}
func testNotNil(t *testing.T, val interface{}) {
if val == nil {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d: expected not nil, got nil\033[39m\n\n", filepath.Base(file), line)
t.FailNow()
}
}
// equals fails the test if exp is not equal to act.
func testEquals(t *testing.T, exp, act interface{}) {
if !reflect.DeepEqual(exp, act) {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act)
t.FailNow()
}
}
type testStruct struct {
Counter int
Mutex sync.Mutex
}