Skip to content

Commit b4cfc8f

Browse files
authored
tests: calling os.Exit in TestMain is not required (#3856)
1 parent b16e12f commit b4cfc8f

File tree

10 files changed

+13
-15
lines changed

10 files changed

+13
-15
lines changed

‎cmd/dlv/dlv_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestMain(m *testing.M) {
4444
}
4545
}
4646
}
47-
os.Exit(protest.RunTestsWithFixtures(m))
47+
protest.RunTestsWithFixtures(m)
4848
}
4949

5050
func assertNoError(err error, t testing.TB, s string) {

‎pkg/dwarf/line/line_parser_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var userTestFile string
2525
func TestMain(m *testing.M) {
2626
flag.StringVar(&userTestFile, "user", "", "runs line parsing test on one extra file")
2727
flag.Parse()
28-
os.Exit(m.Run())
28+
m.Run()
2929
}
3030

3131
func grabDebugLineSection(p string, t *testing.T) []byte {

‎pkg/proc/core/core_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestMain(m *testing.M) {
2828
fmt.Fprintf(os.Stderr, "unknown build mode %q", buildMode)
2929
os.Exit(1)
3030
}
31-
os.Exit(test.RunTestsWithFixtures(m))
31+
test.RunTestsWithFixtures(m)
3232
}
3333

3434
func assertNoError(err error, t testing.TB, s string) {

‎pkg/proc/gdbserial/rr_test.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"flag"
66
"fmt"
7-
"os"
87
"os/exec"
98
"path/filepath"
109
"runtime"
@@ -21,7 +20,7 @@ func TestMain(m *testing.M) {
2120
flag.StringVar(&logConf, "log", "", "configures logging")
2221
flag.Parse()
2322
logflags.Setup(logConf != "", logConf, "")
24-
os.Exit(protest.RunTestsWithFixtures(m))
23+
protest.RunTestsWithFixtures(m)
2524
}
2625

2726
func withTestRecording(name string, t testing.TB, fn func(grp *proc.TargetGroup, fixture protest.Fixture)) {

‎pkg/proc/proc_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestMain(m *testing.M) {
5858
os.Exit(1)
5959
}
6060
logflags.Setup(logConf != "", logConf, "")
61-
os.Exit(protest.RunTestsWithFixtures(m))
61+
protest.RunTestsWithFixtures(m)
6262
}
6363

6464
func matchSkipConditions(conditions ...string) bool {

‎pkg/proc/test/support.go‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ func BuildFixture(name string, flags BuildFlags) Fixture {
212212
return fixtures[fk]
213213
}
214214

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

224224
// Remove the fixtures.
225225
for _, f := range fixtures {
@@ -237,7 +237,6 @@ func RunTestsWithFixtures(m *testing.M) int {
237237
os.Remove(p)
238238
}
239239
}
240-
return status
241240
}
242241

243242
var recordingAllowed = map[string]bool{}

‎pkg/terminal/command_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestMain(m *testing.M) {
4141
os.Exit(1)
4242
}
4343
logflags.Setup(logConf != "", logConf, "")
44-
os.Exit(test.RunTestsWithFixtures(m))
44+
test.RunTestsWithFixtures(m)
4545
}
4646

4747
type FakeTerminal struct {

‎service/dap/server_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestMain(m *testing.M) {
5454
flag.Parse()
5555
logflags.Setup(logOutput != "", logOutput, "")
5656
protest.DefaultTestBackend(&testBackend)
57-
os.Exit(protest.RunTestsWithFixtures(m))
57+
protest.RunTestsWithFixtures(m)
5858
}
5959

6060
// name is for _fixtures/<name>.go

‎service/debugger/debugger_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestMain(m *testing.M) {
2121
flag.StringVar(&logConf, "log", "", "configures logging")
2222
flag.Parse()
2323
logflags.Setup(logConf != "", logConf, "")
24-
os.Exit(protest.RunTestsWithFixtures(m))
24+
protest.RunTestsWithFixtures(m)
2525
}
2626

2727
func TestDebugger_LaunchNoMain(t *testing.T) {

‎service/test/integration2_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestMain(m *testing.M) {
5151
os.Exit(1)
5252
}
5353
logflags.Setup(logOutput != "", logOutput, "")
54-
os.Exit(protest.RunTestsWithFixtures(m))
54+
protest.RunTestsWithFixtures(m)
5555
}
5656

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

0 commit comments

Comments
 (0)