3
0
corteza/internal/test/assert.go
2019-01-22 14:46:29 +01:00

32 lines
680 B
Go

package test
import (
"fmt"
"runtime"
"testing"
)
func Assert(t *testing.T, ok bool, format string, args ...interface{}) bool {
if !ok {
_, file, line, _ := runtime.Caller(1)
caller := fmt.Sprintf("\nAsserted at:%s:%d", file, line)
t.Fatalf(format+caller, args...)
}
return ok
}
func NoError(t *testing.T, err error, format string, args ...interface{}) bool {
if err != nil {
_, file, line, _ := runtime.Caller(1)
caller := fmt.Sprintf("\nAsserted at:%s:%d", file, line)
t.Fatalf(format+caller, append([]interface{}{err}, args...)...)
return false
}
return true
}
func Error(t *testing.T, err error, message string) {
Assert(t, err != nil, message)
}