Skip to content

test-main-missing-exit

Detect legacy TestMain functions that lose the test exit code.

Updated View as Markdown

Default severity: warning

Before Go 1.15, a custom TestMain that called testing.M.Run had to pass its result to os.Exit or failed tests could appear successful. Go 1.15 and newer propagate the returned status automatically, so the check is silent there.

Bad

func TestMain(m *testing.M) { m.Run() }

Good

func TestMain(m *testing.M) { os.Exit(m.Run()) }
Navigation

Type to search…

↑↓ navigate↵ selectEsc close