Skip to content
This repository has been archived by the owner on May 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3 from kalafut/master
Browse files Browse the repository at this point in the history
Add SetOutput function to change message output destination
  • Loading branch information
tylerb committed May 20, 2015
2 parents 3602bb8 + bf9962f commit 3fcf136
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions is.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 3fcf136

Please sign in to comment.