@@ -24,47 +24,37 @@ func pow2(x int) int64 {
2424
2525// https://github.com/benbjohnson/testing
2626// assert fails the test if the condition is false.
27- func assert (t * testing.T , condition bool , msg string , v ... interface {}) {
27+ func _assert (t * testing.T , condition bool , msg string , v ... interface {}) {
2828 t .Helper ()
2929
3030 if ! condition {
31- _ , file , line , _ := runtime .Caller (1 )
31+ _ , file , line , _ := runtime .Caller (2 )
3232 fmt .Printf ("\033 [31m%s:%d: " + msg + "\033 [39m\n \n " , append ([]interface {}{filepath .Base (file ), line }, v ... )... )
3333 t .FailNow ()
3434 }
3535}
3636
37+ func assert (t * testing.T , condition bool , msg string , v ... interface {}) {
38+ t .Helper ()
39+ _assert (t , condition , msg , v ... )
40+ }
41+
3742// ok fails the test if an err is not nil.
3843func ok (t * testing.T , err error ) {
3944 t .Helper ()
40-
41- if err != nil {
42- _ , file , line , _ := runtime .Caller (1 )
43- fmt .Printf ("\033 [31m%s:%d: unexpected error: %s\033 [39m\n \n " , filepath .Base (file ), line , err .Error ())
44- t .FailNow ()
45- }
45+ _assert (t , err == nil , "unexpected error: %v" , err )
4646}
4747
4848// nok fails the test if an err is nil.
4949func nok (t * testing.T , err error ) {
5050 t .Helper ()
51-
52- if err == nil {
53- _ , file , line , _ := runtime .Caller (1 )
54- fmt .Printf ("\033 [31m%s:%d: expected error: %s\033 [39m\n \n " , filepath .Base (file ), line , err .Error ())
55- t .FailNow ()
56- }
51+ _assert (t , err != nil , "expected error, got nil" )
5752}
5853
5954// equals fails the test if exp is not equal to act.
6055func equals (t * testing.T , exp , act interface {}) {
6156 t .Helper ()
62-
63- if ! reflect .DeepEqual (exp , act ) {
64- _ , file , line , _ := runtime .Caller (1 )
65- fmt .Printf ("\033 [31m%s:%d:\n \n \t exp: %#v\n \n \t got: %#v\033 [39m\n \n " , filepath .Base (file ), line , exp , act )
66- t .FailNow ()
67- }
57+ _assert (t , reflect .DeepEqual (exp , act ), "exp: %#v\n \n got: %#v" , exp , act )
6858}
6959
7060func zpoolTest (t * testing.T , fn func ()) {
0 commit comments