Skip to content

Commit 4dee14e

Browse files
author
Leo Arias
committed
Join the Stream and Verbose flags into verbosity (#3)
1 parent 937a5a0 commit 4dee14e

File tree

4 files changed

+43
-47
lines changed

4 files changed

+43
-47
lines changed

check.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ type suiteRunner struct {
522522
reportedProblemLast bool
523523
benchTime time.Duration
524524
benchMem bool
525-
stream bool
525+
verbosity uint8
526526
}
527527

528528
type RunConf struct {
@@ -552,17 +552,24 @@ func newSuiteRunner(suite interface{}, runConf *RunConf) *suiteRunner {
552552
suiteType := reflect.TypeOf(suite)
553553
suiteNumMethods := suiteType.NumMethod()
554554
suiteValue := reflect.ValueOf(suite)
555-
555+
var verbosity uint8
556+
if conf.Verbose {
557+
verbosity = 1
558+
}
559+
if conf.Stream {
560+
verbosity = 2
561+
}
562+
556563
runner := &suiteRunner{
557564
suite: suite,
558-
output: newOutputWriter(conf.Output, conf.Stream, conf.Verbose),
565+
output: newOutputWriter(conf.Output, verbosity),
559566
tracker: newResultTracker(),
560567
benchTime: conf.BenchmarkTime,
561568
benchMem: conf.BenchmarkMem,
562569
tempDir: &tempDir{},
563570
keepDir: conf.KeepWorkDir,
564571
tests: make([]*methodType, 0, suiteNumMethods),
565-
stream: conf.Stream,
572+
verbosity: verbosity,
566573
}
567574
if runner.benchTime == 0 {
568575
runner.benchTime = 1 * time.Second
@@ -643,7 +650,7 @@ func (runner *suiteRunner) run() *Result {
643650
// goroutine with the provided dispatcher for running it.
644651
func (runner *suiteRunner) forkCall(method *methodType, kind funcKind, testName string, logb *logger, dispatcher func(c *C)) *C {
645652
var logw io.Writer
646-
if runner.stream {
653+
if runner.verbosity > 1 {
647654
logw = runner.output
648655
}
649656
if logb == nil {

export_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ func Indent(s, with string) string {
1010
return indent(s, with)
1111
}
1212

13-
func NewOutputWriter(writer io.Writer, stream, verbose bool) *outputWriter {
14-
return newOutputWriter(writer, stream, verbose)
13+
func NewOutputWriter(writer io.Writer, verbosity uint8) *outputWriter {
14+
return newOutputWriter(writer, verbosity)
1515
}
1616

1717
func (c *C) FakeSkip(reason string) {

reporter.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ type outputWriter struct {
1313
m sync.Mutex
1414
writer io.Writer
1515
wroteCallProblemLast bool
16-
stream bool
17-
verbose bool
16+
verbosity uint8
1817
}
1918

20-
func newOutputWriter(writer io.Writer, stream, verbose bool) *outputWriter {
21-
return &outputWriter{writer: writer, stream: stream, verbose: verbose}
19+
func newOutputWriter(writer io.Writer, verbosity uint8) *outputWriter {
20+
return &outputWriter{writer: writer, verbosity: verbosity}
2221
}
2322

2423
func (ow *outputWriter) Write(content []byte) (n int, err error) {
@@ -29,7 +28,7 @@ func (ow *outputWriter) Write(content []byte) (n int, err error) {
2928
}
3029

3130
func (ow *outputWriter) WriteCallStarted(label string, c *C) {
32-
if ow.stream {
31+
if ow.verbosity > 1 {
3332
header := renderCallHeader(label, c, "", "\n")
3433
ow.m.Lock()
3534
ow.writer.Write([]byte(header))
@@ -39,22 +38,22 @@ func (ow *outputWriter) WriteCallStarted(label string, c *C) {
3938

4039
func (ow *outputWriter) WriteCallProblem(label string, c *C) {
4140
var prefix string
42-
if !ow.stream {
41+
if ow.verbosity < 2 {
4342
prefix = "\n-----------------------------------" +
4443
"-----------------------------------\n"
4544
}
4645
header := renderCallHeader(label, c, prefix, "\n\n")
4746
ow.m.Lock()
4847
ow.wroteCallProblemLast = true
4948
ow.writer.Write([]byte(header))
50-
if !ow.stream {
49+
if ow.verbosity < 2 {
5150
c.logb.WriteTo(ow.writer)
5251
}
5352
ow.m.Unlock()
5453
}
5554

5655
func (ow *outputWriter) WriteCallSuccess(label string, c *C) {
57-
if ow.stream || (ow.verbose && c.kind == testKd) {
56+
if ow.verbosity > 1 || (ow.verbosity == 1 && c.kind == testKd) {
5857
// TODO Use a buffer here.
5958
var suffix string
6059
if c.reason != "" {
@@ -64,13 +63,13 @@ func (ow *outputWriter) WriteCallSuccess(label string, c *C) {
6463
suffix += "\t" + c.timerString()
6564
}
6665
suffix += "\n"
67-
if ow.stream {
66+
if ow.verbosity > 1 {
6867
suffix += "\n"
6968
}
7069
header := renderCallHeader(label, c, "", suffix)
7170
ow.m.Lock()
7271
// Resist temptation of using line as prefix above due to race.
73-
if !ow.stream && ow.wroteCallProblemLast {
72+
if ow.verbosity < 2 && ow.wroteCallProblemLast {
7473
header = "\n-----------------------------------" +
7574
"-----------------------------------\n" +
7675
header

reporter_test.go

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,42 @@ func (s *reporterS) TestWrite(c *C) {
2424
testString := "test string"
2525
output := String{}
2626

27-
dummyStream := true
28-
dummyVerbose := true
29-
o := NewOutputWriter(&output, dummyStream, dummyVerbose)
27+
var dummyVerbosity uint8
28+
o := NewOutputWriter(&output, dummyVerbosity)
3029

3130
o.Write([]byte(testString))
3231
c.Assert(output.value, Equals, testString)
3332
}
3433

3534
func (s *reporterS) TestWriteCallStartedWithStreamFlag(c *C) {
3635
testLabel := "test started label"
37-
stream := true
36+
var verbosity uint8 = 2
3837
output := String{}
3938

40-
dummyVerbose := true
41-
o := NewOutputWriter(&output, stream, dummyVerbose)
39+
o := NewOutputWriter(&output, verbosity)
4240

4341
o.WriteCallStarted(testLabel, c)
4442
expected := fmt.Sprintf("%s: %s:\\d+: %s\n", testLabel, s.testFile, c.TestName())
4543
c.Assert(output.value, Matches, expected)
4644
}
4745

4846
func (s *reporterS) TestWriteCallStartedWithoutStreamFlag(c *C) {
49-
stream := false
47+
var verbosity uint8 = 1
5048
output := String{}
5149

5250
dummyLabel := "dummy"
53-
dummyVerbose := true
54-
o := NewOutputWriter(&output, stream, dummyVerbose)
51+
o := NewOutputWriter(&output, verbosity)
5552

5653
o.WriteCallStarted(dummyLabel, c)
5754
c.Assert(output.value, Equals, "")
5855
}
5956

6057
func (s *reporterS) TestWriteCallProblemWithStreamFlag(c *C) {
6158
testLabel := "test problem label"
62-
stream := true
59+
var verbosity uint8 = 2
6360
output := String{}
6461

65-
dummyVerbose := true
66-
o := NewOutputWriter(&output, stream, dummyVerbose)
62+
o := NewOutputWriter(&output, verbosity)
6763

6864
o.WriteCallProblem(testLabel, c)
6965
expected := fmt.Sprintf("%s: %s:\\d+: %s\n\n", testLabel, s.testFile, c.TestName())
@@ -72,11 +68,10 @@ func (s *reporterS) TestWriteCallProblemWithStreamFlag(c *C) {
7268

7369
func (s *reporterS) TestWriteCallProblemWithoutStreamFlag(c *C) {
7470
testLabel := "test problem label"
75-
stream := false
71+
var verbosity uint8 = 1
7672
output := String{}
7773

78-
dummyVerbose := true
79-
o := NewOutputWriter(&output, stream, dummyVerbose)
74+
o := NewOutputWriter(&output, verbosity)
8075

8176
o.WriteCallProblem(testLabel, c)
8277
expected := fmt.Sprintf(""+
@@ -89,11 +84,10 @@ func (s *reporterS) TestWriteCallProblemWithoutStreamFlag(c *C) {
8984
func (s *reporterS) TestWriteCallProblemWithoutStreamFlagWithLog(c *C) {
9085
testLabel := "test problem label"
9186
testLog := "test log"
92-
stream := false
87+
var verbosity uint8 = 1
9388
output := String{}
9489

95-
dummyVerbose := true
96-
o := NewOutputWriter(&output, stream, dummyVerbose)
90+
o := NewOutputWriter(&output, verbosity)
9791

9892
c.Log(testLog)
9993
o.WriteCallProblem(testLabel, c)
@@ -106,11 +100,10 @@ func (s *reporterS) TestWriteCallProblemWithoutStreamFlagWithLog(c *C) {
106100

107101
func (s *reporterS) TestWriteCallSuccessWithStreamFlag(c *C) {
108102
testLabel := "test success label"
109-
stream := true
103+
var verbosity uint8 = 2
110104
output := String{}
111105

112-
dummyVerbose := true
113-
o := NewOutputWriter(&output, stream, dummyVerbose)
106+
o := NewOutputWriter(&output, verbosity)
114107

115108
o.WriteCallSuccess(testLabel, c)
116109
expected := fmt.Sprintf("%s: %s:\\d+: %s\t\\d\\.\\d+s\n\n", testLabel, s.testFile, c.TestName())
@@ -120,11 +113,10 @@ func (s *reporterS) TestWriteCallSuccessWithStreamFlag(c *C) {
120113
func (s *reporterS) TestWriteCallSuccessWithStreamFlagAndReason(c *C) {
121114
testLabel := "test success label"
122115
testReason := "test skip reason"
123-
stream := true
116+
var verbosity uint8 = 2
124117
output := String{}
125118

126-
dummyVerbose := true
127-
o := NewOutputWriter(&output, stream, dummyVerbose)
119+
o := NewOutputWriter(&output, verbosity)
128120
c.FakeSkip(testReason)
129121

130122
o.WriteCallSuccess(testLabel, c)
@@ -135,11 +127,10 @@ func (s *reporterS) TestWriteCallSuccessWithStreamFlagAndReason(c *C) {
135127

136128
func (s *reporterS) TestWriteCallSuccessWithoutStreamFlagWithVerboseFlag(c *C) {
137129
testLabel := "test success label"
138-
stream := false
139-
verbose := true
130+
var verbosity uint8 = 1
140131
output := String{}
141132

142-
o := NewOutputWriter(&output, stream, verbose)
133+
o := NewOutputWriter(&output, verbosity)
143134

144135
o.WriteCallSuccess(testLabel, c)
145136
expected := fmt.Sprintf("%s: %s:\\d+: %s\t\\d\\.\\d+s\n", testLabel, s.testFile, c.TestName())
@@ -148,11 +139,10 @@ func (s *reporterS) TestWriteCallSuccessWithoutStreamFlagWithVerboseFlag(c *C) {
148139

149140
func (s *reporterS) TestWriteCallSuccessWithoutStreamFlagWithoutVerboseFlag(c *C) {
150141
testLabel := "test success label"
151-
stream := false
152-
verbose := false
142+
var verbosity uint8 = 0
153143
output := String{}
154144

155-
o := NewOutputWriter(&output, stream, verbose)
145+
o := NewOutputWriter(&output, verbosity)
156146

157147
o.WriteCallSuccess(testLabel, c)
158148
c.Assert(output.value, Equals, "")

0 commit comments

Comments
 (0)