Skip to content

Commit

Permalink
Merge pull request #10 from matryer/nocolorflag
Browse files Browse the repository at this point in the history
added -nocolor flag support
  • Loading branch information
matryer committed May 17, 2018
2 parents 56187c1 + 0a08690 commit be846f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ func Test(t *testing.T) {

}
```

## Color

To turn off the colors, run `go test` with the `-nocolor` flag.

```
go test -nocolor
```
13 changes: 11 additions & 2 deletions is.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ package is
import (
"bufio"
"bytes"
"flag"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -70,20 +71,28 @@ type I struct {
colorful bool
}

var isColorful bool

func init() {
noColor := flag.Bool("nocolor", false, "turns off colors")
flag.Parse()
isColorful = !*noColor
}

// New makes a new testing helper using the specified
// T through which failures will be reported.
// In strict mode, failures call T.FailNow causing the test
// to be aborted. See NewRelaxed for alternative behavior.
func New(t T) *I {
return &I{t, t.FailNow, os.Stdout, true}
return &I{t, t.FailNow, os.Stdout, isColorful}
}

// NewRelaxed makes a new testing helper using the specified
// T through which failures will be reported.
// In relaxed mode, failures call T.Fail allowing
// multiple failures per test.
func NewRelaxed(t T) *I {
return &I{t, t.Fail, os.Stdout, true}
return &I{t, t.Fail, os.Stdout, isColorful}
}

func (is *I) log(args ...interface{}) {
Expand Down

0 comments on commit be846f6

Please sign in to comment.