Accept an interface instead of testing.T (#1)

This commit is contained in:
Crow Crowcrow 2020-01-17 22:36:24 +01:00 committed by Gitea
부모 66ad00ea84
커밋 fe8a28286e
3개의 변경된 파일10개의 추가작업 그리고 5개의 파일을 삭제

파일 보기

@ -3,14 +3,13 @@ package assert
import (
"reflect"
"runtime"
"testing"
)
// Assert is a helper for tests
type Assert func(bool, ...interface{})
// New returns a new Assert
func New(t *testing.T) Assert {
func New(t T) Assert {
a := func(ok bool, msg ...interface{}) {
if !ok {
if msg == nil {

파일 보기

@ -5,7 +5,6 @@ import (
"reflect"
"runtime"
"strconv"
"testing"
)
func prepMsg(msg []interface{}, format string, args ...interface{}) []interface{} {
@ -16,9 +15,9 @@ func shell(i int) string {
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())
return ts[f]
}

7
type.go Normal file
파일 보기

@ -0,0 +1,7 @@
package assert
// T is an interface of what we use from testing.T
type T interface {
Error(...interface{})
Helper()
}