diff --git a/is.go b/is.go index 011e422..e8308ac 100644 --- a/is.go +++ b/is.go @@ -1,10 +1,14 @@ package is import ( + "io" "log" + "os" "testing" ) +var output io.Writer = os.Stdout + // Is provides methods that leverage the existing testing capabilities found // in the Go test framework. The methods provided allow for a more natural, // efficient and expressive approach to writing tests. The goal is to write @@ -146,3 +150,10 @@ func (is *Is) NotZero(o interface{}) { fail(is, "expected object '%s' not to be zero value", objectTypeName(o)) } } + +// SetOutput changes the message output Writer from the default (os.Stdout). +// This may be useful if the application under test takes over the console, or +// if logging to a file is desired. +func SetOutput(w io.Writer) { + output = w +} diff --git a/workers.go b/workers.go index 1536abe..40abc2f 100644 --- a/workers.go +++ b/workers.go @@ -73,9 +73,9 @@ var fail = failDefault // failDefault is the default failure function. func failDefault(is *Is, format string, args ...interface{}) { - fmt.Print(decorate(fmt.Sprintf(format, args...))) + fmt.Fprint(output, decorate(fmt.Sprintf(format, args...))) if len(is.failFormat) != 0 { - fmt.Printf(is.failFormat+"\n", is.failArgs...) + fmt.Fprintf(output, is.failFormat+"\n", is.failArgs...) } is.TB.FailNow() }