Skip to content

Commit

Permalink
tests: calling os.Exit in TestMain is not required (go-delve#3856)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Nov 12, 2024
1 parent b16e12f commit b4cfc8f
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/dlv/dlv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestMain(m *testing.M) {
}
}
}
os.Exit(protest.RunTestsWithFixtures(m))
protest.RunTestsWithFixtures(m)
}

func assertNoError(err error, t testing.TB, s string) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dwarf/line/line_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var userTestFile string
func TestMain(m *testing.M) {
flag.StringVar(&userTestFile, "user", "", "runs line parsing test on one extra file")
flag.Parse()
os.Exit(m.Run())
m.Run()
}

func grabDebugLineSection(p string, t *testing.T) []byte {
Expand Down
2 changes: 1 addition & 1 deletion pkg/proc/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMain(m *testing.M) {
fmt.Fprintf(os.Stderr, "unknown build mode %q", buildMode)
os.Exit(1)
}
os.Exit(test.RunTestsWithFixtures(m))
test.RunTestsWithFixtures(m)
}

func assertNoError(err error, t testing.TB, s string) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/proc/gdbserial/rr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
Expand All @@ -21,7 +20,7 @@ func TestMain(m *testing.M) {
flag.StringVar(&logConf, "log", "", "configures logging")
flag.Parse()
logflags.Setup(logConf != "", logConf, "")
os.Exit(protest.RunTestsWithFixtures(m))
protest.RunTestsWithFixtures(m)
}

func withTestRecording(name string, t testing.TB, fn func(grp *proc.TargetGroup, fixture protest.Fixture)) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/proc/proc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestMain(m *testing.M) {
os.Exit(1)
}
logflags.Setup(logConf != "", logConf, "")
os.Exit(protest.RunTestsWithFixtures(m))
protest.RunTestsWithFixtures(m)
}

func matchSkipConditions(conditions ...string) bool {
Expand Down
9 changes: 4 additions & 5 deletions pkg/proc/test/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ func BuildFixture(name string, flags BuildFlags) Fixture {
return fixtures[fk]
}

// RunTestsWithFixtures will pre-compile test fixtures before running test
// methods. Test binaries are deleted before exiting.
func RunTestsWithFixtures(m *testing.M) int {
// RunTestsWithFixtures sets the flag runningWithFixtures to compile fixtures on demand and runs tests with m.Run().
// After the tests are run, it removes the fixtures and paths from PathsToRemove.
func RunTestsWithFixtures(m *testing.M) {
runningWithFixtures = true
defer func() {
runningWithFixtures = false
}()
status := m.Run()
m.Run()

// Remove the fixtures.
for _, f := range fixtures {
Expand All @@ -237,7 +237,6 @@ func RunTestsWithFixtures(m *testing.M) int {
os.Remove(p)
}
}
return status
}

var recordingAllowed = map[string]bool{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/terminal/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestMain(m *testing.M) {
os.Exit(1)
}
logflags.Setup(logConf != "", logConf, "")
os.Exit(test.RunTestsWithFixtures(m))
test.RunTestsWithFixtures(m)
}

type FakeTerminal struct {
Expand Down
2 changes: 1 addition & 1 deletion service/dap/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestMain(m *testing.M) {
flag.Parse()
logflags.Setup(logOutput != "", logOutput, "")
protest.DefaultTestBackend(&testBackend)
os.Exit(protest.RunTestsWithFixtures(m))
protest.RunTestsWithFixtures(m)
}

// name is for _fixtures/<name>.go
Expand Down
2 changes: 1 addition & 1 deletion service/debugger/debugger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestMain(m *testing.M) {
flag.StringVar(&logConf, "log", "", "configures logging")
flag.Parse()
logflags.Setup(logConf != "", logConf, "")
os.Exit(protest.RunTestsWithFixtures(m))
protest.RunTestsWithFixtures(m)
}

func TestDebugger_LaunchNoMain(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion service/test/integration2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestMain(m *testing.M) {
os.Exit(1)
}
logflags.Setup(logOutput != "", logOutput, "")
os.Exit(protest.RunTestsWithFixtures(m))
protest.RunTestsWithFixtures(m)
}

func withTestClient2(name string, t *testing.T, fn func(c service.Client)) {
Expand Down

0 comments on commit b4cfc8f

Please sign in to comment.