A test is stopped with Fatal, FailNow or Skip from a goroutine it started
What it finds
go func() { ... t.Fatal(err) }(): Fatal, FailNow and Skip end the test by stopping the goroutine they run in, which must be the one running the test. Called from a goroutine the test started, they stop only that goroutine, and the test goes on as if the check had passed, or the runtime fails it later with a less clear message. t.Error and a return report the failure from any goroutine.
The receiver must be a parameter of type *testing.T, *testing.B, *testing.F or testing.TB, declared outside the function literal that the go statement runs, and the call must be in that literal itself rather than in a function nested in it.
From the rule's source, fatal_in_goroutine.rs.
package p import ( "sync" "testing") func TestWork(t *testing.T) { var wg sync.WaitGroup wg.Add(1) go func() { defer wg.Done() if err := work(); err != nil { t.Fatal(err)tx0 reports: t.Fatal stops only this goroutine, not the test } t.Fatalf("%d", 1)tx0 reports: t.Fatalf stops only this goroutine t.FailNow()tx0 reports: t.FailNow stops only this goroutine t.Error("reported from any goroutine") func() { t.Fatal("nested function") }() }() wg.Wait() t.Fatal("in the test's own goroutine") t.Run("sub", func(t *testing.T) { go func() { t.SkipNow()tx0 reports: t.SkipNow stops only this goroutine }() }) go func(t *testing.T) { t.Fatal("parameter of the literal") }(t)} func helper(tb testing.TB, b *testing.B, u *other) { go func() { tb.Fatal("x")tx0 reports: tb.Fatal stops only this goroutine b.Fatal("x")tx0 reports: b.Fatal stops only this goroutine u.Fatal("x") }()} type other struct{} func (*other) Fatal(...any) {} func work() error { return nil } Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/go:fatal-in-goroutine" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:fatal-in-goroutine] reason="..."tx0 explain tx0/go:fatal-in-goroutine shows the same in the terminal. Found a false positive? Report it.