---
title: "test-main-missing-exit"
description: "Detect legacy TestMain functions that lose the test exit code."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# test-main-missing-exit

**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

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

## Good

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

Source: https://strider.gempir.com/analyzers/test-main-missing-exit/index.mdx
