Skip to content

Commit be846f6

Browse files
authored
Merge pull request #10 from matryer/nocolorflag
added -nocolor flag support
2 parents 56187c1 + 0a08690 commit be846f6

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ func Test(t *testing.T) {
2828

2929
}
3030
```
31+
32+
## Color
33+
34+
To turn off the colors, run `go test` with the `-nocolor` flag.
35+
36+
```
37+
go test -nocolor
38+
```

is.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ package is
3939
import (
4040
"bufio"
4141
"bytes"
42+
"flag"
4243
"fmt"
4344
"io"
4445
"os"
@@ -70,20 +71,28 @@ type I struct {
7071
colorful bool
7172
}
7273

74+
var isColorful bool
75+
76+
func init() {
77+
noColor := flag.Bool("nocolor", false, "turns off colors")
78+
flag.Parse()
79+
isColorful = !*noColor
80+
}
81+
7382
// New makes a new testing helper using the specified
7483
// T through which failures will be reported.
7584
// In strict mode, failures call T.FailNow causing the test
7685
// to be aborted. See NewRelaxed for alternative behavior.
7786
func New(t T) *I {
78-
return &I{t, t.FailNow, os.Stdout, true}
87+
return &I{t, t.FailNow, os.Stdout, isColorful}
7988
}
8089

8190
// NewRelaxed makes a new testing helper using the specified
8291
// T through which failures will be reported.
8392
// In relaxed mode, failures call T.Fail allowing
8493
// multiple failures per test.
8594
func NewRelaxed(t T) *I {
86-
return &I{t, t.Fail, os.Stdout, true}
95+
return &I{t, t.Fail, os.Stdout, isColorful}
8796
}
8897

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

0 commit comments

Comments
 (0)