@@ -84,7 +84,6 @@ type C struct {
8484 testName string
8585 _status funcStatus
8686 logb * logger
87- logw io.Writer
8887 done chan * C
8988 reason string
9089 mustFail bool
@@ -109,25 +108,30 @@ func (c *C) stopNow() {
109108// logger is a concurrency safe byte.Buffer
110109type logger struct {
111110 sync.Mutex
112- writer bytes.Buffer
111+ buffer bytes.Buffer
112+ output io.Writer
113+ verbosity uint8
113114}
114115
115116func (l * logger ) Write (buf []byte ) (int , error ) {
116117 l .Lock ()
117118 defer l .Unlock ()
118- return l .writer .Write (buf )
119+ if l .verbosity > 1 {
120+ l .output .Write (buf )
121+ }
122+ return l .buffer .Write (buf )
119123}
120124
121125func (l * logger ) WriteTo (w io.Writer ) (int64 , error ) {
122126 l .Lock ()
123127 defer l .Unlock ()
124- return l .writer .WriteTo (w )
128+ return l .buffer .WriteTo (w )
125129}
126130
127131func (l * logger ) String () string {
128132 l .Lock ()
129133 defer l .Unlock ()
130- return l .writer .String ()
134+ return l .buffer .String ()
131135}
132136
133137// -----------------------------------------------------------------------
@@ -198,9 +202,6 @@ func (c *C) logNewLine() {
198202
199203func (c * C ) writeLog (buf []byte ) {
200204 c .logb .Write (buf )
201- if c .logw != nil {
202- c .logw .Write (buf )
203- }
204205}
205206
206207func hasStringOrError (x interface {}) (ok bool ) {
@@ -518,6 +519,7 @@ type suiteRunner struct {
518519 tracker * resultTracker
519520 tempDir * tempDir
520521 keepDir bool
522+ logOutput io.Writer
521523 output * outputWriter
522524 reportedProblemLast bool
523525 benchTime time.Duration
@@ -562,6 +564,7 @@ func newSuiteRunner(suite interface{}, runConf *RunConf) *suiteRunner {
562564
563565 runner := & suiteRunner {
564566 suite : suite ,
567+ logOutput : conf .Output ,
565568 output : newOutputWriter (conf .Output , verbosity ),
566569 tracker : newResultTracker (),
567570 benchTime : conf .BenchmarkTime ,
@@ -649,19 +652,17 @@ func (runner *suiteRunner) run() *Result {
649652// Create a call object with the given suite method, and fork a
650653// goroutine with the provided dispatcher for running it.
651654func (runner * suiteRunner ) forkCall (method * methodType , kind funcKind , testName string , logb * logger , dispatcher func (c * C )) * C {
652- var logw io.Writer
653- if runner .verbosity > 1 {
654- logw = runner .output
655- }
656655 if logb == nil {
657- logb = new (logger )
656+ logb = & logger {
657+ output : runner .logOutput ,
658+ verbosity : runner .verbosity ,
659+ }
658660 }
659661 c := & C {
660662 method : method ,
661663 kind : kind ,
662664 testName : testName ,
663665 logb : logb ,
664- logw : logw ,
665666 tempDir : runner .tempDir ,
666667 done : make (chan * C , 1 ),
667668 timer : timer {benchTime : runner .benchTime },
0 commit comments