This morning a one line change had several of us tearing up the fabric of reality trying to understand why a failing test wasn’t failing, or, in fact, being run at all. Increasingly frantic efforts to upgrade/downgrade Go, run the tests on another machine, run the tests in CI, all served to only unnerve us further.
Can you spot the bug?
package gosh_darn_important_test
import (
"testing"
"go.uber.org/goleak"
)
func TestMain(m *testing.M) {
// goleak.VerifyTestMain(m)
}
...
TestMain
is intended to be a middleware (so to speak) between the go test
test runner and the Test
functions in a package. The goleak
check had recently been commented out (not surprisingly because of yet another logging library that spawns goroutines in the background) which meant that TestMain
no longer called, indirectly, m.Run
to execute any tests.