This site is being rebuilt and some pages are out of date. For current details, write to [email protected]. This notice goes away when the rebuild is done.

No analytics unless you allow it, no tracking. This site keeps in your browser the language you pick, the theme, its colour, which site you chose, the currency on the pricing page and that you closed this notice; signing in adds session cookies. The legal page has the details.

Sign in

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() to testing.TB that returns an io.Writer. The writer writes to the same stream as TB.Log, is internally line buffered, and does not add source locations or newlines. After a test or subtest finishes, calling Output or Write will 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