2016-02-22 00:27:08 -05:00
|
|
|
package gobottest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var errFunc = func(t *testing.T, message string) {
|
|
|
|
t.Errorf(message)
|
|
|
|
}
|
|
|
|
|
|
|
|
func logFailure(t *testing.T, message string) {
|
|
|
|
_, file, line, _ := runtime.Caller(2)
|
|
|
|
s := strings.Split(file, "/")
|
|
|
|
errFunc(t, fmt.Sprintf("%v:%v: %v", s[len(s)-1], line, message))
|
|
|
|
}
|
|
|
|
|
2016-05-24 20:25:16 -07:00
|
|
|
// Assert checks if a and b are equal, emits a t.Errorf if they are not equal.
|
2016-02-22 00:27:08 -05:00
|
|
|
func Assert(t *testing.T, a interface{}, b interface{}) {
|
|
|
|
if !reflect.DeepEqual(a, b) {
|
|
|
|
logFailure(t, fmt.Sprintf("%v - \"%v\", should equal, %v - \"%v\"",
|
|
|
|
a, reflect.TypeOf(a), b, reflect.TypeOf(b)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-24 20:25:16 -07:00
|
|
|
// Refute checks if a and b are equal, emits a t.Errorf if they are equal.
|
2016-02-22 00:27:08 -05:00
|
|
|
func Refute(t *testing.T, a interface{}, b interface{}) {
|
|
|
|
if reflect.DeepEqual(a, b) {
|
|
|
|
logFailure(t, fmt.Sprintf("%v - \"%v\", should not equal, %v - \"%v\"",
|
|
|
|
a, reflect.TypeOf(a), b, reflect.TypeOf(b)))
|
|
|
|
}
|
|
|
|
}
|