mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-01 13:17:53 +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
|
slow := false
|
||||||
sandbox := false
|
sandbox := false
|
||||||
waitForDebugger := false
|
waitForDebugger := false
|
||||||
|
raceDetector := false
|
||||||
testNames := parseFlags(os.Args[2:], []flagInfo{
|
testNames := parseFlags(os.Args[2:], []flagInfo{
|
||||||
{"slow", &slow},
|
{"slow", &slow},
|
||||||
{"sandbox", &sandbox},
|
{"sandbox", &sandbox},
|
||||||
{"debug", &waitForDebugger},
|
{"debug", &waitForDebugger},
|
||||||
|
{"race", &raceDetector},
|
||||||
})
|
})
|
||||||
clients.RunCLI(testNames, slow, sandbox, waitForDebugger)
|
clients.RunCLI(testNames, slow, sandbox, waitForDebugger, raceDetector)
|
||||||
case "tui":
|
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:
|
default:
|
||||||
log.Fatal(usage)
|
log.Fatal(usage)
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
// If invoked directly, you can specify tests to run by passing their names as positional arguments
|
// 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)
|
inputDelay := tryConvert(os.Getenv("INPUT_DELAY"), 0)
|
||||||
if slow {
|
if slow {
|
||||||
inputDelay = SLOW_INPUT_DELAY
|
inputDelay = SLOW_INPUT_DELAY
|
||||||
@ -36,6 +36,7 @@ func RunCLI(testNames []string, slow bool, sandbox bool, waitForDebugger bool) {
|
|||||||
runAndPrintFatalError,
|
runAndPrintFatalError,
|
||||||
sandbox,
|
sandbox,
|
||||||
waitForDebugger,
|
waitForDebugger,
|
||||||
|
raceDetector,
|
||||||
inputDelay,
|
inputDelay,
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
@ -27,6 +27,7 @@ func TestIntegration(t *testing.T) {
|
|||||||
|
|
||||||
parallelTotal := tryConvert(os.Getenv("PARALLEL_TOTAL"), 1)
|
parallelTotal := tryConvert(os.Getenv("PARALLEL_TOTAL"), 1)
|
||||||
parallelIndex := tryConvert(os.Getenv("PARALLEL_INDEX"), 0)
|
parallelIndex := tryConvert(os.Getenv("PARALLEL_INDEX"), 0)
|
||||||
|
raceDetector := os.Getenv("LAZYGIT_RACE_DETECTOR") != ""
|
||||||
testNumber := 0
|
testNumber := 0
|
||||||
|
|
||||||
err := components.RunTests(
|
err := components.RunTests(
|
||||||
@ -53,6 +54,7 @@ func TestIntegration(t *testing.T) {
|
|||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
raceDetector,
|
||||||
0,
|
0,
|
||||||
// Allow two attempts at each test to get around flakiness
|
// Allow two attempts at each test to get around flakiness
|
||||||
2,
|
2,
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
var SLOW_INPUT_DELAY = 600
|
var SLOW_INPUT_DELAY = 600
|
||||||
|
|
||||||
func RunTUI() {
|
func RunTUI(raceDetector bool) {
|
||||||
rootDir := utils.GetLazyRootDirectory()
|
rootDir := utils.GetLazyRootDirectory()
|
||||||
testDir := filepath.Join(rootDir, "test", "integration")
|
testDir := filepath.Join(rootDir, "test", "integration")
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ func RunTUI() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
suspendAndRunTest(currentTest, true, false, 0)
|
suspendAndRunTest(currentTest, true, false, raceDetector, 0)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -98,7 +98,7 @@ func RunTUI() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
suspendAndRunTest(currentTest, false, false, 0)
|
suspendAndRunTest(currentTest, false, false, raceDetector, 0)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -111,7 +111,7 @@ func RunTUI() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
suspendAndRunTest(currentTest, false, false, SLOW_INPUT_DELAY)
|
suspendAndRunTest(currentTest, false, false, raceDetector, SLOW_INPUT_DELAY)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -124,7 +124,7 @@ func RunTUI() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
suspendAndRunTest(currentTest, false, true, 0)
|
suspendAndRunTest(currentTest, false, true, raceDetector, 0)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}); err != 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 {
|
if err := gocui.Screen.Suspend(); err != nil {
|
||||||
panic(err)
|
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.Fprintf(os.Stdout, "\n%s", style.FgGreen.Sprint("press enter to return"))
|
||||||
fmt.Scanln() // wait for enter press
|
fmt.Scanln() // wait for enter press
|
||||||
@ -384,7 +384,7 @@ func quit(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return gocui.ErrQuit
|
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(
|
err := components.RunTests(
|
||||||
[]*components.IntegrationTest{test},
|
[]*components.IntegrationTest{test},
|
||||||
log.Printf,
|
log.Printf,
|
||||||
@ -392,6 +392,7 @@ func runTuiTest(test *components.IntegrationTest, sandbox bool, waitForDebugger
|
|||||||
runAndPrintError,
|
runAndPrintError,
|
||||||
sandbox,
|
sandbox,
|
||||||
waitForDebugger,
|
waitForDebugger,
|
||||||
|
raceDetector,
|
||||||
inputDelay,
|
inputDelay,
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
@ -30,6 +30,7 @@ func RunTests(
|
|||||||
testWrapper func(test *IntegrationTest, f func() error),
|
testWrapper func(test *IntegrationTest, f func() error),
|
||||||
sandbox bool,
|
sandbox bool,
|
||||||
waitForDebugger bool,
|
waitForDebugger bool,
|
||||||
|
raceDetector bool,
|
||||||
inputDelay int,
|
inputDelay int,
|
||||||
maxAttempts int,
|
maxAttempts int,
|
||||||
) error {
|
) error {
|
||||||
@ -41,7 +42,7 @@ func RunTests(
|
|||||||
|
|
||||||
testDir := filepath.Join(projectRootDir, "test", "_results")
|
testDir := filepath.Join(projectRootDir, "test", "_results")
|
||||||
|
|
||||||
if err := buildLazygit(); err != nil {
|
if err := buildLazygit(raceDetector); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,15 +132,18 @@ func prepareTestDir(
|
|||||||
return createFixture(test, paths, rootDir)
|
return createFixture(test, paths, rootDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildLazygit() error {
|
func buildLazygit(raceDetector bool) error {
|
||||||
// // TODO: remove this line!
|
// // TODO: remove this line!
|
||||||
// // skipping this because I'm not making changes to the app code atm.
|
// // skipping this because I'm not making changes to the app code atm.
|
||||||
// return nil
|
// 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()
|
osCommand := oscommands.NewDummyOSCommand()
|
||||||
return osCommand.Cmd.New([]string{
|
return osCommand.Cmd.New(args).Run()
|
||||||
"go", "build", "-o", tempLazygitPath(), filepath.FromSlash("pkg/integration/clients/injector/main.go"),
|
|
||||||
}).Run()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createFixture(test *IntegrationTest, paths Paths, rootDir string) error {
|
func createFixture(test *IntegrationTest, paths Paths, rootDir string) error {
|
||||||
@ -202,6 +206,9 @@ func getLazygitCommand(test *IntegrationTest, paths Paths, rootDir string, sandb
|
|||||||
if waitForDebugger {
|
if waitForDebugger {
|
||||||
cmdObj.AddEnvVars("WAIT_FOR_DEBUGGER=true")
|
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 {
|
if test.ExtraEnvVars() != nil {
|
||||||
for key, value := range test.ExtraEnvVars() {
|
for key, value := range test.ExtraEnvVars() {
|
||||||
cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", key, value))
|
cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", key, value))
|
||||||
@ -221,6 +228,10 @@ func tempLazygitPath() string {
|
|||||||
return filepath.Join("/tmp", "lazygit", "test_lazygit")
|
return filepath.Join("/tmp", "lazygit", "test_lazygit")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func raceDetectorLogsPath() string {
|
||||||
|
return filepath.Join("/tmp", "lazygit", "race_log")
|
||||||
|
}
|
||||||
|
|
||||||
func findOrCreateDir(path string) {
|
func findOrCreateDir(path string) {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user