mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-22 05:29:44 +02:00
Support -race arg when running integration tests to turn on go's race detector
For the "cli" and "tui" modes of the test runner there's a "-race" parameter to turn it on; for running tests on CI with go test, you turn it on by setting the environment variable LAZYGIT_RACE_DETECTOR to a non-empty value.
This commit is contained in:
parent
8081b59a02
commit
f108fd2236
@ -61,14 +61,23 @@ func main() {
|
||||
slow := false
|
||||
sandbox := false
|
||||
waitForDebugger := false
|
||||
raceDetector := false
|
||||
testNames := parseFlags(os.Args[2:], []flagInfo{
|
||||
{"slow", &slow},
|
||||
{"sandbox", &sandbox},
|
||||
{"debug", &waitForDebugger},
|
||||
{"race", &raceDetector},
|
||||
})
|
||||
clients.RunCLI(testNames, slow, sandbox, waitForDebugger)
|
||||
clients.RunCLI(testNames, slow, sandbox, waitForDebugger, raceDetector)
|
||||
case "tui":
|
||||
clients.RunTUI()
|
||||
raceDetector := false
|
||||
remainingArgs := parseFlags(os.Args[2:], []flagInfo{
|
||||
{"race", &raceDetector},
|
||||
})
|
||||
if len(remainingArgs) > 0 {
|
||||
log.Fatal("tui only supports the -race argument.")
|
||||
}
|
||||
clients.RunTUI(raceDetector)
|
||||
default:
|
||||
log.Fatal(usage)
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
|
||||
// If invoked directly, you can specify tests to run by passing their names as positional arguments
|
||||
|
||||
func RunCLI(testNames []string, slow bool, sandbox bool, waitForDebugger bool) {
|
||||
func RunCLI(testNames []string, slow bool, sandbox bool, waitForDebugger bool, raceDetector bool) {
|
||||
inputDelay := tryConvert(os.Getenv("INPUT_DELAY"), 0)
|
||||
if slow {
|
||||
inputDelay = SLOW_INPUT_DELAY
|
||||
@ -36,6 +36,7 @@ func RunCLI(testNames []string, slow bool, sandbox bool, waitForDebugger bool) {
|
||||
runAndPrintFatalError,
|
||||
sandbox,
|
||||
waitForDebugger,
|
||||
raceDetector,
|
||||
inputDelay,
|
||||
1,
|
||||
)
|
||||
|
@ -27,6 +27,7 @@ func TestIntegration(t *testing.T) {
|
||||
|
||||
parallelTotal := tryConvert(os.Getenv("PARALLEL_TOTAL"), 1)
|
||||
parallelIndex := tryConvert(os.Getenv("PARALLEL_INDEX"), 0)
|
||||
raceDetector := os.Getenv("LAZYGIT_RACE_DETECTOR") != ""
|
||||
testNumber := 0
|
||||
|
||||
err := components.RunTests(
|
||||
@ -53,6 +54,7 @@ func TestIntegration(t *testing.T) {
|
||||
},
|
||||
false,
|
||||
false,
|
||||
raceDetector,
|
||||
0,
|
||||
// Allow two attempts at each test to get around flakiness
|
||||
2,
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
|
||||
var SLOW_INPUT_DELAY = 600
|
||||
|
||||
func RunTUI() {
|
||||
func RunTUI(raceDetector bool) {
|
||||
rootDir := utils.GetLazyRootDirectory()
|
||||
testDir := filepath.Join(rootDir, "test", "integration")
|
||||
|
||||
@ -85,7 +85,7 @@ func RunTUI() {
|
||||
return nil
|
||||
}
|
||||
|
||||
suspendAndRunTest(currentTest, true, false, 0)
|
||||
suspendAndRunTest(currentTest, true, false, raceDetector, 0)
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
@ -98,7 +98,7 @@ func RunTUI() {
|
||||
return nil
|
||||
}
|
||||
|
||||
suspendAndRunTest(currentTest, false, false, 0)
|
||||
suspendAndRunTest(currentTest, false, false, raceDetector, 0)
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
@ -111,7 +111,7 @@ func RunTUI() {
|
||||
return nil
|
||||
}
|
||||
|
||||
suspendAndRunTest(currentTest, false, false, SLOW_INPUT_DELAY)
|
||||
suspendAndRunTest(currentTest, false, false, raceDetector, SLOW_INPUT_DELAY)
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
@ -124,7 +124,7 @@ func RunTUI() {
|
||||
return nil
|
||||
}
|
||||
|
||||
suspendAndRunTest(currentTest, false, true, 0)
|
||||
suspendAndRunTest(currentTest, false, true, raceDetector, 0)
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
@ -284,12 +284,12 @@ func (self *app) wrapEditor(f func(v *gocui.View, key gocui.Key, ch rune, mod go
|
||||
}
|
||||
}
|
||||
|
||||
func suspendAndRunTest(test *components.IntegrationTest, sandbox bool, waitForDebugger bool, inputDelay int) {
|
||||
func suspendAndRunTest(test *components.IntegrationTest, sandbox bool, waitForDebugger bool, raceDetector bool, inputDelay int) {
|
||||
if err := gocui.Screen.Suspend(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
runTuiTest(test, sandbox, waitForDebugger, inputDelay)
|
||||
runTuiTest(test, sandbox, waitForDebugger, raceDetector, inputDelay)
|
||||
|
||||
fmt.Fprintf(os.Stdout, "\n%s", style.FgGreen.Sprint("press enter to return"))
|
||||
fmt.Scanln() // wait for enter press
|
||||
@ -384,7 +384,7 @@ func quit(g *gocui.Gui, v *gocui.View) error {
|
||||
return gocui.ErrQuit
|
||||
}
|
||||
|
||||
func runTuiTest(test *components.IntegrationTest, sandbox bool, waitForDebugger bool, inputDelay int) {
|
||||
func runTuiTest(test *components.IntegrationTest, sandbox bool, waitForDebugger bool, raceDetector bool, inputDelay int) {
|
||||
err := components.RunTests(
|
||||
[]*components.IntegrationTest{test},
|
||||
log.Printf,
|
||||
@ -392,6 +392,7 @@ func runTuiTest(test *components.IntegrationTest, sandbox bool, waitForDebugger
|
||||
runAndPrintError,
|
||||
sandbox,
|
||||
waitForDebugger,
|
||||
raceDetector,
|
||||
inputDelay,
|
||||
1,
|
||||
)
|
||||
|
@ -30,6 +30,7 @@ func RunTests(
|
||||
testWrapper func(test *IntegrationTest, f func() error),
|
||||
sandbox bool,
|
||||
waitForDebugger bool,
|
||||
raceDetector bool,
|
||||
inputDelay int,
|
||||
maxAttempts int,
|
||||
) error {
|
||||
@ -41,7 +42,7 @@ func RunTests(
|
||||
|
||||
testDir := filepath.Join(projectRootDir, "test", "_results")
|
||||
|
||||
if err := buildLazygit(); err != nil {
|
||||
if err := buildLazygit(raceDetector); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -131,15 +132,18 @@ func prepareTestDir(
|
||||
return createFixture(test, paths, rootDir)
|
||||
}
|
||||
|
||||
func buildLazygit() error {
|
||||
func buildLazygit(raceDetector bool) error {
|
||||
// // TODO: remove this line!
|
||||
// // skipping this because I'm not making changes to the app code atm.
|
||||
// return nil
|
||||
|
||||
args := []string{"go", "build"}
|
||||
if raceDetector {
|
||||
args = append(args, "-race")
|
||||
}
|
||||
args = append(args, "-o", tempLazygitPath(), filepath.FromSlash("pkg/integration/clients/injector/main.go"))
|
||||
osCommand := oscommands.NewDummyOSCommand()
|
||||
return osCommand.Cmd.New([]string{
|
||||
"go", "build", "-o", tempLazygitPath(), filepath.FromSlash("pkg/integration/clients/injector/main.go"),
|
||||
}).Run()
|
||||
return osCommand.Cmd.New(args).Run()
|
||||
}
|
||||
|
||||
func createFixture(test *IntegrationTest, paths Paths, rootDir string) error {
|
||||
@ -202,6 +206,9 @@ func getLazygitCommand(test *IntegrationTest, paths Paths, rootDir string, sandb
|
||||
if waitForDebugger {
|
||||
cmdObj.AddEnvVars("WAIT_FOR_DEBUGGER=true")
|
||||
}
|
||||
// Set a race detector log path only to avoid spamming the terminal with the
|
||||
// logs. We are not showing this anywhere yet.
|
||||
cmdObj.AddEnvVars(fmt.Sprintf("GORACE=log_path=%s", raceDetectorLogsPath()))
|
||||
if test.ExtraEnvVars() != nil {
|
||||
for key, value := range test.ExtraEnvVars() {
|
||||
cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", key, value))
|
||||
@ -221,6 +228,10 @@ func tempLazygitPath() string {
|
||||
return filepath.Join("/tmp", "lazygit", "test_lazygit")
|
||||
}
|
||||
|
||||
func raceDetectorLogsPath() string {
|
||||
return filepath.Join("/tmp", "lazygit", "race_log")
|
||||
}
|
||||
|
||||
func findOrCreateDir(path string) {
|
||||
_, err := os.Stat(path)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user