Skip to content

Commit

Permalink
refactoring: simplified Log method
Browse files Browse the repository at this point in the history
  • Loading branch information
mg6maciej committed Jan 5, 2015
1 parent c0eb819 commit 72facd1
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions error_logger_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ type errorLoggerImpl struct {
}

const (
failOutput = "\n--- FAIL: %s\n\t%s:%d\n\t\t%s\n"
failOutputWithoutFailLine = "\t%s:%d\n\t\t%s\n"
failOutputWithoutLineNumber = "\t\t%s\n"
formatHeaderFull = "\n--- FAIL: %s\n\t%s:%d\n"
formatHeaderShort = "\t%s:%d\n"
formatMessage = "\t\t%s\n"
)

func (logger *errorLoggerImpl) Log(location *location, message string) {
args := []interface{}{location.Test, location.FileName, location.Line, message}
if logger.prevTestName != location.Test {
fmt.Fprintf(logger.writer, failOutput, args...)
fmt.Fprintf(logger.writer, formatHeaderFull, location.Test, location.FileName, location.Line)
} else if logger.prevTestLine != location.Line {
fmt.Fprintf(logger.writer, failOutputWithoutFailLine, args[1:]...)
} else {
fmt.Fprintf(logger.writer, failOutputWithoutLineNumber, message)
fmt.Fprintf(logger.writer, formatHeaderShort, location.FileName, location.Line)
}
fmt.Fprintf(logger.writer, formatMessage, message)
logger.prevTestName = location.Test
logger.prevTestLine = location.Line
}

0 comments on commit 72facd1

Please sign in to comment.