tests: calling os.Exit in TestMain is not required (#3856)
This commit is contained in:
parent
b16e12fde7
commit
b4cfc8f6c7
@ -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) {
|
func assertNoError(err error, t testing.TB, s string) {
|
||||||
|
@ -25,7 +25,7 @@ var userTestFile string
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
flag.StringVar(&userTestFile, "user", "", "runs line parsing test on one extra file")
|
flag.StringVar(&userTestFile, "user", "", "runs line parsing test on one extra file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
os.Exit(m.Run())
|
m.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func grabDebugLineSection(p string, t *testing.T) []byte {
|
func grabDebugLineSection(p string, t *testing.T) []byte {
|
||||||
|
@ -28,7 +28,7 @@ func TestMain(m *testing.M) {
|
|||||||
fmt.Fprintf(os.Stderr, "unknown build mode %q", buildMode)
|
fmt.Fprintf(os.Stderr, "unknown build mode %q", buildMode)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
os.Exit(test.RunTestsWithFixtures(m))
|
test.RunTestsWithFixtures(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertNoError(err error, t testing.TB, s string) {
|
func assertNoError(err error, t testing.TB, s string) {
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -21,7 +20,7 @@ func TestMain(m *testing.M) {
|
|||||||
flag.StringVar(&logConf, "log", "", "configures logging")
|
flag.StringVar(&logConf, "log", "", "configures logging")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
logflags.Setup(logConf != "", logConf, "")
|
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)) {
|
func withTestRecording(name string, t testing.TB, fn func(grp *proc.TargetGroup, fixture protest.Fixture)) {
|
||||||
|
@ -58,7 +58,7 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
logflags.Setup(logConf != "", logConf, "")
|
logflags.Setup(logConf != "", logConf, "")
|
||||||
os.Exit(protest.RunTestsWithFixtures(m))
|
protest.RunTestsWithFixtures(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func matchSkipConditions(conditions ...string) bool {
|
func matchSkipConditions(conditions ...string) bool {
|
||||||
|
@ -212,14 +212,14 @@ func BuildFixture(name string, flags BuildFlags) Fixture {
|
|||||||
return fixtures[fk]
|
return fixtures[fk]
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunTestsWithFixtures will pre-compile test fixtures before running test
|
// RunTestsWithFixtures sets the flag runningWithFixtures to compile fixtures on demand and runs tests with m.Run().
|
||||||
// methods. Test binaries are deleted before exiting.
|
// After the tests are run, it removes the fixtures and paths from PathsToRemove.
|
||||||
func RunTestsWithFixtures(m *testing.M) int {
|
func RunTestsWithFixtures(m *testing.M) {
|
||||||
runningWithFixtures = true
|
runningWithFixtures = true
|
||||||
defer func() {
|
defer func() {
|
||||||
runningWithFixtures = false
|
runningWithFixtures = false
|
||||||
}()
|
}()
|
||||||
status := m.Run()
|
m.Run()
|
||||||
|
|
||||||
// Remove the fixtures.
|
// Remove the fixtures.
|
||||||
for _, f := range fixtures {
|
for _, f := range fixtures {
|
||||||
@ -237,7 +237,6 @@ func RunTestsWithFixtures(m *testing.M) int {
|
|||||||
os.Remove(p)
|
os.Remove(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return status
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var recordingAllowed = map[string]bool{}
|
var recordingAllowed = map[string]bool{}
|
||||||
|
@ -41,7 +41,7 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
logflags.Setup(logConf != "", logConf, "")
|
logflags.Setup(logConf != "", logConf, "")
|
||||||
os.Exit(test.RunTestsWithFixtures(m))
|
test.RunTestsWithFixtures(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
type FakeTerminal struct {
|
type FakeTerminal struct {
|
||||||
|
@ -54,7 +54,7 @@ func TestMain(m *testing.M) {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
logflags.Setup(logOutput != "", logOutput, "")
|
logflags.Setup(logOutput != "", logOutput, "")
|
||||||
protest.DefaultTestBackend(&testBackend)
|
protest.DefaultTestBackend(&testBackend)
|
||||||
os.Exit(protest.RunTestsWithFixtures(m))
|
protest.RunTestsWithFixtures(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// name is for _fixtures/<name>.go
|
// name is for _fixtures/<name>.go
|
||||||
|
@ -21,7 +21,7 @@ func TestMain(m *testing.M) {
|
|||||||
flag.StringVar(&logConf, "log", "", "configures logging")
|
flag.StringVar(&logConf, "log", "", "configures logging")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
logflags.Setup(logConf != "", logConf, "")
|
logflags.Setup(logConf != "", logConf, "")
|
||||||
os.Exit(protest.RunTestsWithFixtures(m))
|
protest.RunTestsWithFixtures(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDebugger_LaunchNoMain(t *testing.T) {
|
func TestDebugger_LaunchNoMain(t *testing.T) {
|
||||||
|
@ -51,7 +51,7 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
logflags.Setup(logOutput != "", logOutput, "")
|
logflags.Setup(logOutput != "", logOutput, "")
|
||||||
os.Exit(protest.RunTestsWithFixtures(m))
|
protest.RunTestsWithFixtures(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func withTestClient2(name string, t *testing.T, fn func(c service.Client)) {
|
func withTestClient2(name string, t *testing.T, fn func(c service.Client)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user