-
Notifications
You must be signed in to change notification settings - Fork 316
Open
Labels
Description
Describe the bug
It seems that any use of os.Exit in TestMain is flagged by redundant-test-main-exit, regardless of if the return from m.Run is actually use
To Reproduce
Steps to reproduce the behavior:
- I updated revive
go install github.com/mgechev/revive@latest - I run it with the following flags & configuration file:
# flags
revive .# config file
[rule.redundant-test-main-exit]func TestMain(m *testing.M) {
err := vcr.CleanCassettes()
if err != nil {
fmt.Println("Error cleaning cassettes:", err)
os.Exit(1)
}
m.Run()
dirty, err := snaps.Clean(m, snaps.CleanOpts{Sort: true})
if err != nil {
fmt.Println("Error cleaning snaps:", err)
os.Exit(1)
}
if dirty {
fmt.Println("Some snapshots were outdated.")
os.Exit(1)
}
}A self-contained example:
// main_test.go
package main
import (
"fmt"
"os"
"testing"
)
func cleanSnapshots() bool {
// (in real life this actually does stuff)
return false
}
func TestMain(m *testing.M) {
m.Run()
dirty := cleanSnapshots()
if dirty {
fmt.Println("Some snapshots were outdated.")
os.Exit(1)
}
}Expected behavior
I expect nothing to be flagged, since none of my os.Exit calls are based on the return from m.Run
Logs
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Ubuntu 22.04 via WSLv2 Win11
- Version of Go
Additional context
Add any other context about the problem here.
Reactions are currently unavailable