fail: add test name for logged output

In case of a test failure, the test name will be logged to the output
with makes debugging easier, specially in case of table driven tests.
pull/465/head^2
Eyal 2017-07-09 14:22:15 +03:00 committed by Ernesto Jiménez
parent 6e494f9834
commit b3dfaa9086
1 changed files with 7 additions and 0 deletions

View File

@ -231,6 +231,13 @@ func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool {
{"Error", failureMessage},
}
// Add test name if the Go version supports it
if n, ok := t.(interface {
Name() string
}); ok {
content = append(content, labeledContent{"Test", n.Name()})
}
message := messageFromMsgAndArgs(msgAndArgs...)
if len(message) > 0 {
content = append(content, labeledContent{"Messages", message})