Skip to content

Commit

Permalink
staticcheck: Go 1.15+ does not require TestMain to call os.Exit
Browse files Browse the repository at this point in the history
Closes gh-708

(cherry picked from commit 4b3a258)
  • Loading branch information
dominikh committed Oct 10, 2020
1 parent a4a005d commit 8106b47
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions staticcheck/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,12 @@ func CheckDubiousDeferInChannelRangeLoop(pass *analysis.Pass) (interface{}, erro
}

func CheckTestMainExit(pass *analysis.Pass) (interface{}, error) {
if code.IsGoVersion(pass, 15) {
// Beginning with Go 1.15, the test framework will call
// os.Exit for us.
return nil, nil
}

var (
fnmain ast.Node
callsExit bool
Expand Down
9 changes: 8 additions & 1 deletion staticcheck/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ func TestAll(t *testing.T) {
"SA2001": {{Dir: "CheckEmptyCriticalSection"}},
"SA2002": {{Dir: "CheckConcurrentTesting"}},
"SA2003": {{Dir: "CheckDeferLock"}},
"SA3000": {{Dir: "CheckTestMainExit-1"}, {Dir: "CheckTestMainExit-2"}, {Dir: "CheckTestMainExit-3"}, {Dir: "CheckTestMainExit-4"}, {Dir: "CheckTestMainExit-5"}},
"SA3000": {
{Dir: "CheckTestMainExit-1"},
{Dir: "CheckTestMainExit-2"},
{Dir: "CheckTestMainExit-3"},
{Dir: "CheckTestMainExit-4"},
{Dir: "CheckTestMainExit-5"},
{Dir: "CheckTestMainExit-1_go115", Version: "1.15"},
},
"SA3001": {{Dir: "CheckBenchmarkN"}},
"SA4000": {{Dir: "CheckLhsRhsIdentical"}},
"SA4001": {{Dir: "CheckIneffectiveCopy"}},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pkg

import "testing"

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

0 comments on commit 8106b47

Please sign in to comment.