Skip to content

Commit

Permalink
Add test V for two interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Nov 4, 2017
1 parent ecd2711 commit e37ee2a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math"
"reflect"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -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{}) {
Expand All @@ -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)
Expand Down

0 comments on commit e37ee2a

Please sign in to comment.