mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-11-28 09:08:41 +02:00
Use args struct for RunTests
There were too many position arguments
This commit is contained in:
parent
d8059d7f7d
commit
7e5f25e415
@ -29,17 +29,17 @@ func RunCLI(testNames []string, slow bool, sandbox bool, waitForDebugger bool, r
|
||||
inputDelay = SLOW_INPUT_DELAY
|
||||
}
|
||||
|
||||
err := components.RunTests(
|
||||
getTestsToRun(testNames),
|
||||
log.Printf,
|
||||
runCmdInTerminal,
|
||||
runAndPrintFatalError,
|
||||
sandbox,
|
||||
waitForDebugger,
|
||||
raceDetector,
|
||||
inputDelay,
|
||||
1,
|
||||
)
|
||||
err := components.RunTests(components.RunTestArgs{
|
||||
Tests: getTestsToRun(testNames),
|
||||
Logf: log.Printf,
|
||||
RunCmd: runCmdInTerminal,
|
||||
TestWrapper: runAndPrintFatalError,
|
||||
Sandbox: sandbox,
|
||||
WaitForDebugger: waitForDebugger,
|
||||
RaceDetector: raceDetector,
|
||||
InputDelay: inputDelay,
|
||||
MaxAttempts: 1,
|
||||
})
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ func TestIntegration(t *testing.T) {
|
||||
raceDetector := os.Getenv("LAZYGIT_RACE_DETECTOR") != ""
|
||||
testNumber := 0
|
||||
|
||||
err := components.RunTests(
|
||||
tests.GetTests(),
|
||||
t.Logf,
|
||||
runCmdHeadless,
|
||||
func(test *components.IntegrationTest, f func() error) {
|
||||
err := components.RunTests(components.RunTestArgs{
|
||||
Tests: tests.GetTests(),
|
||||
Logf: t.Logf,
|
||||
RunCmd: runCmdHeadless,
|
||||
TestWrapper: func(test *components.IntegrationTest, f func() error) {
|
||||
defer func() { testNumber += 1 }()
|
||||
if testNumber%parallelTotal != parallelIndex {
|
||||
return
|
||||
@ -52,13 +52,13 @@ func TestIntegration(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
},
|
||||
false,
|
||||
false,
|
||||
raceDetector,
|
||||
0,
|
||||
Sandbox: false,
|
||||
WaitForDebugger: false,
|
||||
RaceDetector: raceDetector,
|
||||
InputDelay: 0,
|
||||
// Allow two attempts at each test to get around flakiness
|
||||
2,
|
||||
)
|
||||
MaxAttempts: 2,
|
||||
})
|
||||
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
@ -385,17 +385,17 @@ func quit(g *gocui.Gui, v *gocui.View) error {
|
||||
}
|
||||
|
||||
func runTuiTest(test *components.IntegrationTest, sandbox bool, waitForDebugger bool, raceDetector bool, inputDelay int) {
|
||||
err := components.RunTests(
|
||||
[]*components.IntegrationTest{test},
|
||||
log.Printf,
|
||||
runCmdInTerminal,
|
||||
runAndPrintError,
|
||||
sandbox,
|
||||
waitForDebugger,
|
||||
raceDetector,
|
||||
inputDelay,
|
||||
1,
|
||||
)
|
||||
err := components.RunTests(components.RunTestArgs{
|
||||
Tests: []*components.IntegrationTest{test},
|
||||
Logf: log.Printf,
|
||||
RunCmd: runCmdInTerminal,
|
||||
TestWrapper: runAndPrintError,
|
||||
Sandbox: sandbox,
|
||||
WaitForDebugger: waitForDebugger,
|
||||
RaceDetector: raceDetector,
|
||||
InputDelay: inputDelay,
|
||||
MaxAttempts: 1,
|
||||
})
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
|
@ -20,21 +20,23 @@ const (
|
||||
GIT_CONFIG_GLOBAL_ENV_VAR = "GIT_CONFIG_GLOBAL"
|
||||
)
|
||||
|
||||
type RunTestArgs struct {
|
||||
Tests []*IntegrationTest
|
||||
Logf func(format string, formatArgs ...interface{})
|
||||
RunCmd func(cmd *exec.Cmd) (int, error)
|
||||
TestWrapper func(test *IntegrationTest, f func() error)
|
||||
Sandbox bool
|
||||
WaitForDebugger bool
|
||||
RaceDetector bool
|
||||
InputDelay int
|
||||
MaxAttempts int
|
||||
}
|
||||
|
||||
// This function lets you run tests either from within `go test` or from a regular binary.
|
||||
// The reason for having two separate ways of testing is that `go test` isn't great at
|
||||
// showing what's actually happening during the test, but it's still good at running
|
||||
// tests in telling you about their results.
|
||||
func RunTests(
|
||||
tests []*IntegrationTest,
|
||||
logf func(format string, formatArgs ...interface{}),
|
||||
runCmd func(cmd *exec.Cmd) (int, error),
|
||||
testWrapper func(test *IntegrationTest, f func() error),
|
||||
sandbox bool,
|
||||
waitForDebugger bool,
|
||||
raceDetector bool,
|
||||
inputDelay int,
|
||||
maxAttempts int,
|
||||
) error {
|
||||
func RunTests(args RunTestArgs) error {
|
||||
projectRootDir := lazycoreUtils.GetLazyRootDirectory()
|
||||
err := os.Chdir(projectRootDir)
|
||||
if err != nil {
|
||||
@ -42,8 +44,7 @@ func RunTests(
|
||||
}
|
||||
|
||||
testDir := filepath.Join(projectRootDir, "test", "_results")
|
||||
|
||||
if err := buildLazygit(waitForDebugger, raceDetector); err != nil {
|
||||
if err := buildLazygit(args.WaitForDebugger, args.RaceDetector); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -52,21 +53,21 @@ func RunTests(
|
||||
return err
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
for _, test := range args.Tests {
|
||||
test := test
|
||||
|
||||
testWrapper(test, func() error { //nolint: thelper
|
||||
args.TestWrapper(test, func() error { //nolint: thelper
|
||||
paths := NewPaths(
|
||||
filepath.Join(testDir, test.Name()),
|
||||
)
|
||||
|
||||
for i := 0; i < maxAttempts; i++ {
|
||||
err := runTest(test, paths, projectRootDir, logf, runCmd, sandbox, waitForDebugger, raceDetector, inputDelay, gitVersion)
|
||||
for i := 0; i < args.MaxAttempts; i++ {
|
||||
err := runTest(test, paths, projectRootDir, args.Logf, args.RunCmd, args.Sandbox, args.WaitForDebugger, args.RaceDetector, args.InputDelay, gitVersion)
|
||||
if err != nil {
|
||||
if i == maxAttempts-1 {
|
||||
if i == args.MaxAttempts-1 {
|
||||
return err
|
||||
}
|
||||
logf("retrying test %s", test.Name())
|
||||
args.Logf("retrying test %s", test.Name())
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user