mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 04:45:47 +02:00
Use args struct for RunTests
There were too many position arguments
This commit is contained in:
parent
d8059d7f7d
commit
7e5f25e415
4 changed files with 53 additions and 52 deletions
|
@ -29,17 +29,17 @@ func RunCLI(testNames []string, slow bool, sandbox bool, waitForDebugger bool, r
|
||||||
inputDelay = SLOW_INPUT_DELAY
|
inputDelay = SLOW_INPUT_DELAY
|
||||||
}
|
}
|
||||||
|
|
||||||
err := components.RunTests(
|
err := components.RunTests(components.RunTestArgs{
|
||||||
getTestsToRun(testNames),
|
Tests: getTestsToRun(testNames),
|
||||||
log.Printf,
|
Logf: log.Printf,
|
||||||
runCmdInTerminal,
|
RunCmd: runCmdInTerminal,
|
||||||
runAndPrintFatalError,
|
TestWrapper: runAndPrintFatalError,
|
||||||
sandbox,
|
Sandbox: sandbox,
|
||||||
waitForDebugger,
|
WaitForDebugger: waitForDebugger,
|
||||||
raceDetector,
|
RaceDetector: raceDetector,
|
||||||
inputDelay,
|
InputDelay: inputDelay,
|
||||||
1,
|
MaxAttempts: 1,
|
||||||
)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err.Error())
|
log.Print(err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,11 @@ func TestIntegration(t *testing.T) {
|
||||||
raceDetector := os.Getenv("LAZYGIT_RACE_DETECTOR") != ""
|
raceDetector := os.Getenv("LAZYGIT_RACE_DETECTOR") != ""
|
||||||
testNumber := 0
|
testNumber := 0
|
||||||
|
|
||||||
err := components.RunTests(
|
err := components.RunTests(components.RunTestArgs{
|
||||||
tests.GetTests(),
|
Tests: tests.GetTests(),
|
||||||
t.Logf,
|
Logf: t.Logf,
|
||||||
runCmdHeadless,
|
RunCmd: runCmdHeadless,
|
||||||
func(test *components.IntegrationTest, f func() error) {
|
TestWrapper: func(test *components.IntegrationTest, f func() error) {
|
||||||
defer func() { testNumber += 1 }()
|
defer func() { testNumber += 1 }()
|
||||||
if testNumber%parallelTotal != parallelIndex {
|
if testNumber%parallelTotal != parallelIndex {
|
||||||
return
|
return
|
||||||
|
@ -52,13 +52,13 @@ func TestIntegration(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
false,
|
Sandbox: false,
|
||||||
false,
|
WaitForDebugger: false,
|
||||||
raceDetector,
|
RaceDetector: raceDetector,
|
||||||
0,
|
InputDelay: 0,
|
||||||
// Allow two attempts at each test to get around flakiness
|
// Allow two attempts at each test to get around flakiness
|
||||||
2,
|
MaxAttempts: 2,
|
||||||
)
|
})
|
||||||
|
|
||||||
assert.NoError(t, err)
|
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) {
|
func runTuiTest(test *components.IntegrationTest, sandbox bool, waitForDebugger bool, raceDetector bool, inputDelay int) {
|
||||||
err := components.RunTests(
|
err := components.RunTests(components.RunTestArgs{
|
||||||
[]*components.IntegrationTest{test},
|
Tests: []*components.IntegrationTest{test},
|
||||||
log.Printf,
|
Logf: log.Printf,
|
||||||
runCmdInTerminal,
|
RunCmd: runCmdInTerminal,
|
||||||
runAndPrintError,
|
TestWrapper: runAndPrintError,
|
||||||
sandbox,
|
Sandbox: sandbox,
|
||||||
waitForDebugger,
|
WaitForDebugger: waitForDebugger,
|
||||||
raceDetector,
|
RaceDetector: raceDetector,
|
||||||
inputDelay,
|
InputDelay: inputDelay,
|
||||||
1,
|
MaxAttempts: 1,
|
||||||
)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,21 +20,23 @@ const (
|
||||||
GIT_CONFIG_GLOBAL_ENV_VAR = "GIT_CONFIG_GLOBAL"
|
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.
|
// 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
|
// 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
|
// showing what's actually happening during the test, but it's still good at running
|
||||||
// tests in telling you about their results.
|
// tests in telling you about their results.
|
||||||
func RunTests(
|
func RunTests(args RunTestArgs) error {
|
||||||
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 {
|
|
||||||
projectRootDir := lazycoreUtils.GetLazyRootDirectory()
|
projectRootDir := lazycoreUtils.GetLazyRootDirectory()
|
||||||
err := os.Chdir(projectRootDir)
|
err := os.Chdir(projectRootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -42,8 +44,7 @@ func RunTests(
|
||||||
}
|
}
|
||||||
|
|
||||||
testDir := filepath.Join(projectRootDir, "test", "_results")
|
testDir := filepath.Join(projectRootDir, "test", "_results")
|
||||||
|
if err := buildLazygit(args.WaitForDebugger, args.RaceDetector); err != nil {
|
||||||
if err := buildLazygit(waitForDebugger, raceDetector); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,21 +53,21 @@ func RunTests(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range args.Tests {
|
||||||
test := test
|
test := test
|
||||||
|
|
||||||
testWrapper(test, func() error { //nolint: thelper
|
args.TestWrapper(test, func() error { //nolint: thelper
|
||||||
paths := NewPaths(
|
paths := NewPaths(
|
||||||
filepath.Join(testDir, test.Name()),
|
filepath.Join(testDir, test.Name()),
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := 0; i < maxAttempts; i++ {
|
for i := 0; i < args.MaxAttempts; i++ {
|
||||||
err := runTest(test, paths, projectRootDir, logf, runCmd, sandbox, waitForDebugger, raceDetector, inputDelay, gitVersion)
|
err := runTest(test, paths, projectRootDir, args.Logf, args.RunCmd, args.Sandbox, args.WaitForDebugger, args.RaceDetector, args.InputDelay, gitVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if i == maxAttempts-1 {
|
if i == args.MaxAttempts-1 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logf("retrying test %s", test.Name())
|
args.Logf("retrying test %s", test.Name())
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue