Radar · Go · Archive · Week 11 · Mar 10 – 16, 2025
testing: Add T.Output() etc
Worth knowingstdlib
- What changed
- The proposal adds a new method
Output()totesting.TBthat returns anio.Writer. The writer writes to the same stream asTB.Log, is internally line buffered, and does not add source locations or newlines. After a test or subtest finishes, callingOutputorWritewill panic. - Production impact
- The source does not say.
- Try it
- Create a test that calls
t.Output()and writes a line, then run the test to see the output appear with the test’s log formatting. - Source
- github.com/golang/go/issues/59928
Understand it, then run it
Testing in Go often needs a way to print messages that are tied to the test’s output stream. The testing package already provides t.Log and t.Logf, but those helpers add source‑location information and newlines automatically. A new method, Output, was proposed for the testing.TB interface. It returns an io.Writer that writes to the same stream as t.Log, but it does not add caller information or newlines. The writer is line‑buffered and flushes when the test ends. After a test finishes, calling Output or writing to it panics.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed