@@ -11,22 +11,33 @@ import (
1111	" fmt" 
1212	" path/filepath" 
1313	" runtime" 
14+ 	" reflect" 
1415	" testing" 
1516)
1617
18+ //  assert fails the test if the condition is false.
1719func  assert (tb  testing .TB , condition  bool , msg  string , v  ...interface {}) {
1820	if  !condition {
1921		_ , file , line , _  :=  runtime.Caller (1 )
20- 		v = append ([]interface {}{filepath.Base (file), line}, v...)
21- 		fmt.Printf (" %s :%d : " " \n " 
22+ 		fmt.Printf (" \033 [31m%s :%d : " " \033 [39m\n\n " append ([]interface {}{filepath.Base (file), line}, v...)...)
2223		tb.FailNow ()
2324	}
2425}
2526
27+ //  ok fails the test if an err is not nil.
28+ func  ok (tb  testing .TB , err  error ) {
29+ 	if  err != nil  {
30+ 		_ , file , line , _  :=  runtime.Caller (1 )
31+ 		fmt.Printf (" \033 [31m%s :%d : unexpected error: %s \033 [39m\n\n " Base (file), line, err.Error ())
32+ 		tb.FailNow ()
33+ 	}
34+ }
35+ 
36+ //  equals fails the test if exp is not equal to act.
2637func  equals (tb  testing .TB , exp , act  interface {}) {
27- 	if  exp !=  act {
38+ 	if  !reflect. DeepEqual ( exp,  act)  {
2839		_ , file , line , _  :=  runtime.Caller (1 )
29- 		fmt.Printf (" %s :%d : exp : %#v , got : %#v \n " Base (file), line, exp, act)
40+ 		fmt.Printf (" \033 [31m %s :%d :\n\n\t exp : %#v \n\n\t got : %#v \033 [39m \n \n" Base (file), line, exp, act)
3041		tb.FailNow ()
3142	}
3243}
0 commit comments