Under go test -json (what gotestsum runs, so every CI coverage leg) the testing framework itself reassigns os.Stderr = os.Stdout inside M.Run so both streams interleave into one test2json event stream (go1.26 testing/testing.go:2391, go.dev/issue/33419). That swap lands after package var-init and before the first test, so a guard baselined at var-init convicts the framework on every -json run — the ubuntu-only zz_stdio_leak_guard failures bisected in #5881 (probe branch bee/zzleak-probe-5881: every TestMain checkpoint clean through pre-m.Run, first test already polluted; reproducible on darwin with plain go test -json). Capture the baseline in the alphabetically-first test instead (aaa_stdio_baseline_test.go), so the guard measures exactly what it promises: did any TEST leak a stdio swap. When a -run filter excludes the baseline test the guard skips rather than comparing against a pre-framework baseline. Verified: cmd/bd guard tests pass in plain mode and -json mode (both previously failed under -json), and skip cleanly under -run TestZZStdioNotLeaked alone.
22 lines
958 B
Go
22 lines
958 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
// baselineStdout/baselineStderr are the os.Stdout/os.Stderr objects as the
|
|
// FIRST test in this package saw them, captured here rather than at package
|
|
// var-init: under `go test -json` (what gotestsum runs, so every CI coverage
|
|
// leg) the testing framework itself reassigns os.Stderr = os.Stdout inside
|
|
// M.Run so both streams interleave cleanly into one test2json event stream
|
|
// (go1.26 testing/testing.go:2391, go.dev/issue/33419). That swap is the
|
|
// framework's, not a test's; a leak guard that baselines at var-init convicts
|
|
// the framework on every -json run (#5881) while measuring nothing about the
|
|
// tests. This file is named aaa_* so its test is declared first: go test runs
|
|
// tests in declaration order across files sorted by name (no -shuffle here).
|
|
var baselineStdout, baselineStderr *os.File
|
|
|
|
func TestAAAStdioBaseline(t *testing.T) {
|
|
baselineStdout, baselineStderr = os.Stdout, os.Stderr
|
|
}
|