File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff 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+ ```
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ package is
3939import (
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.
7786func 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.
8594func NewRelaxed (t T ) * I {
86- return & I {t , t .Fail , os .Stdout , true }
95+ return & I {t , t .Fail , os .Stdout , isColorful }
8796}
8897
8998func (is * I ) log (args ... interface {}) {
You can’t perform that action at this time.
0 commit comments