Add common method setOutputWriter

This commit is contained in:
suntala 2025-03-14 19:31:01 +01:00
parent 8dda922069
commit cdd09ba62b
3 changed files with 9 additions and 9 deletions

View File

@ -755,7 +755,7 @@ func (s *benchState) processBench(b *B) {
benchFunc: b.benchFunc,
benchTime: b.benchTime,
}
b.o = b.newOutputWriter()
b.setOutputWriter()
b.run1()
}
r := b.doBench()
@ -832,7 +832,7 @@ func (b *B) Run(name string, f func(b *B)) bool {
benchTime: b.benchTime,
bstate: b.bstate,
}
sub.o = sub.newOutputWriter()
sub.setOutputWriter()
if partial {
// Partial name match, like -bench=X/Y matching BenchmarkX.
// Only process sub-benchmarks, if any.
@ -1009,7 +1009,7 @@ func Benchmark(f func(b *B)) BenchmarkResult {
benchFunc: f,
benchTime: benchTime,
}
b.o = b.newOutputWriter()
b.setOutputWriter()
if b.run1() {
b.run()
}

View File

@ -320,7 +320,7 @@ func (f *F) Fuzz(ff any) {
t.parent.w = captureOut
}
t.w = indenter{&t.common}
t.o = t.newOutputWriter()
t.setOutputWriter()
if t.chatty != nil {
t.chatty.Updatef(t.name, "=== RUN %s\n", t.name)
}
@ -530,7 +530,7 @@ func runFuzzTests(deps testDeps, fuzzTests []InternalFuzzTarget, deadline time.T
fstate: fstate,
}
f.w = indenter{&f.common}
f.o = f.newOutputWriter()
f.setOutputWriter()
if f.chatty != nil {
f.chatty.Updatef(f.name, "=== RUN %s\n", f.name)
}

View File

@ -1046,9 +1046,9 @@ func (c *common) callSite(skip int) string {
return fmt.Sprintf("%s:%d: ", file, line)
}
// newOutputWriter initializes a new outputWriter.
func (c *common) newOutputWriter() io.Writer {
return &outputWriter{c: c}
// setOutputWriter initializes an outputWriter and sets it as a common field.
func (c *common) setOutputWriter() {
c.o = &outputWriter{c: c}
}
// outputWriter buffers, formats and writes input.
@ -1871,7 +1871,7 @@ func (t *T) Run(name string, f func(t *T)) bool {
tstate: t.tstate,
}
t.w = indenter{&t.common}
t.o = t.newOutputWriter()
t.setOutputWriter()
if t.chatty != nil {
t.chatty.Updatef(t.name, "=== RUN %s\n", t.name)