diff --git a/test.go b/test.go index d133656..cf08437 100644 --- a/test.go +++ b/test.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "math" + "reflect" "runtime" "strings" "testing" @@ -45,6 +46,15 @@ func printable(s string) string { return s } +const ( + Red = "31" + Green = "32" +) + +func color(color string, s interface{}) string { + return fmt.Sprintf("\033[00;%sm%v\033[00m", color, s) +} + ///////////////////////////////////////////////////////////////// func That(t *testing.T, condition bool, msgs ...interface{}) { @@ -53,6 +63,17 @@ func That(t *testing.T, condition bool, msgs ...interface{}) { } } +func V(t *testing.T, context string, got, wanted interface{}) { + gotType := reflect.TypeOf(got) + wantedType := reflect.TypeOf(wanted) + if gotType != wantedType { + t.Errorf("%s: %s: type %v != %v", trace(), context, color(Red, gotType), color(Green, wantedType)) + } + if got != wanted { + t.Errorf("%s: %s: %v != %v", trace(), context, color(Red, got), color(Green, wanted)) + } +} + func Error(t *testing.T, err, expected error, msgs ...interface{}) { if err != expected { t.Errorf("%s%s error: %v\nexpected: %v\n", trace(), message(msgs...), err, expected)