Created
January 16, 2017 14:37
-
-
Save tidwall/e3ba31c7e61cd042180078609d4d1d7e to your computer and use it in GitHub Desktop.
Golang Testing Helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testOrDie(t testing.TB, fn func() error) { | |
if err := fn(); err != nil { | |
testFatal(t, 1, err) | |
} | |
} | |
func testFatalf(t testing.TB, skip int, format string, args ...interface{}) { | |
if _, file, line, ok := runtime.Caller(skip + 1); ok { | |
msg := fmt.Sprintf(format, args...) | |
t.Fatalf("\r\t%s:%d: %s", filepath.Base(file), line, msg) | |
} | |
t.Fatalf(format, args...) | |
} | |
func testFatal(t testing.TB, skip int, args ...interface{}) { | |
testFatalf(t, skip+1, "%s", fmt.Sprint(args...)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment