Accept an interface instead of testing.T (#1)
This commit is contained in:
parent
66ad00ea84
commit
fe8a28286e
@ -3,14 +3,13 @@ package assert
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert is a helper for tests
|
// Assert is a helper for tests
|
||||||
type Assert func(bool, ...interface{})
|
type Assert func(bool, ...interface{})
|
||||||
|
|
||||||
// New returns a new Assert
|
// New returns a new Assert
|
||||||
func New(t *testing.T) Assert {
|
func New(t T) Assert {
|
||||||
a := func(ok bool, msg ...interface{}) {
|
a := func(ok bool, msg ...interface{}) {
|
||||||
if !ok {
|
if !ok {
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func prepMsg(msg []interface{}, format string, args ...interface{}) []interface{} {
|
func prepMsg(msg []interface{}, format string, args ...interface{}) []interface{} {
|
||||||
@ -16,9 +15,9 @@ func shell(i int) string {
|
|||||||
return "\x1B[" + strconv.Itoa(i) + "m"
|
return "\x1B[" + strconv.Itoa(i) + "m"
|
||||||
}
|
}
|
||||||
|
|
||||||
var ts = map[*runtime.Func]*testing.T{}
|
var ts = map[*runtime.Func]T{}
|
||||||
|
|
||||||
func t(a Assert) *testing.T {
|
func t(a Assert) T {
|
||||||
f := runtime.FuncForPC(reflect.ValueOf(a).Pointer())
|
f := runtime.FuncForPC(reflect.ValueOf(a).Pointer())
|
||||||
return ts[f]
|
return ts[f]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user