From 8301bba8ad3df46b4cecea687aac027df6d42f76 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 5 Apr 2021 12:18:21 +1000 Subject: make it more likely for CI to work --- pkg/gui/gui.go | 8 ++++++ pkg/gui/gui_test.go | 75 ++++++++++++++--------------------------------------- 2 files changed, 27 insertions(+), 56 deletions(-) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index f334c59b0..0dfc8ecb1 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -564,6 +564,14 @@ func (gui *Gui) RunAndHandleError() error { } func (gui *Gui) runSubprocessWithSuspense(subprocess *exec.Cmd) error { + if replaying() { + // we do not yet support running subprocesses within integration tests. So if + // we're replaying an integration test and we're inside this method, something + // has gone wrong, so we should fail + + log.Fatal("opening subprocesses not yet supported in integration tests. Chances are that this test is running too fast and a subprocess is accidentally opened") + } + if err := gocui.Screen.Suspend(); err != nil { return gui.surfaceError(err) } diff --git a/pkg/gui/gui_test.go b/pkg/gui/gui_test.go index b77113aa2..6d43a6554 100644 --- a/pkg/gui/gui_test.go +++ b/pkg/gui/gui_test.go @@ -3,7 +3,6 @@ package gui import ( "encoding/json" "fmt" - "io" "io/ioutil" "os" "path/filepath" @@ -11,8 +10,6 @@ import ( "strings" "testing" - "github.com/creack/pty" - "github.com/davecgh/go-spew/spew" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/secureexec" "github.com/stretchr/testify/assert" @@ -181,10 +178,6 @@ func Test(t *testing.T) { test := test t.Run(test.Name, func(t *testing.T) { - if runInParallel() { - t.Parallel() - } - speeds := getTestSpeeds(test.Speed, updateSnapshots) for i, speed := range speeds { @@ -201,7 +194,9 @@ func Test(t *testing.T) { err := createFixture(testPath, actualDir) assert.NoError(t, err) - runLazygit(t, testPath, rootDir, record, speed) + configDir := filepath.Join(testPath, "used_config") + + runLazygit(t, testPath, rootDir, configDir, record, speed) if updateSnapshots { err = oscommands.CopyDir(actualDir, expectedDir) @@ -241,6 +236,10 @@ func Test(t *testing.T) { // if the snapshots and we haven't tried all playback speeds different we'll retry at a slower speed if i == len(speeds)-1 { + // get the log file and print that + bytes, err := ioutil.ReadFile(filepath.Join(configDir, "development.log")) + assert.NoError(t, err) + t.Log(string(bytes)) assert.Equal(t, expected, actual, fmt.Sprintf("expected:\n%s\nactual:\n%s\n", expected, actual)) } } @@ -285,7 +284,7 @@ func getRootDirectory() string { } } -func runLazygit(t *testing.T, testPath string, rootDir string, record bool, speed int) { +func runLazygit(t *testing.T, testPath string, rootDir string, configDir string, record bool, speed int) { osCommand := oscommands.NewDummyOSCommand() replayPath := filepath.Join(testPath, "recording.json") @@ -299,63 +298,27 @@ func runLazygit(t *testing.T, testPath string, rootDir string, record bool, spee templateConfigDir = filepath.Join(testPath, "config") } - configDir := filepath.Join(testPath, "used_config") - err = os.RemoveAll(configDir) assert.NoError(t, err) err = oscommands.CopyDir(templateConfigDir, configDir) assert.NoError(t, err) - cmdStr := fmt.Sprintf("%s --use-config-dir=%s --path=%s", tempLazygitPath(), configDir, actualDir) + cmdStr := fmt.Sprintf("%s -debug --use-config-dir=%s --path=%s", tempLazygitPath(), configDir, actualDir) cmd := osCommand.ExecutableFromString(cmdStr) cmd.Env = append(cmd.Env, fmt.Sprintf("REPLAY_SPEED=%d", speed)) - if record { - cmd.Env = append( - cmd.Env, - fmt.Sprintf("RECORD_EVENTS_TO=%s", replayPath), - ) - } else { - cmd.Stdout = os.Stdout - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - cmd.Env = append( - cmd.Env, - fmt.Sprintf("REPLAY_EVENTS_FROM=%s", replayPath), - ) - t.Log(spew.Sdump(cmd)) - } - - t.Log("here") - - // if we're on CI we'll need to use a PTY. We can work that out by seeing if the 'TERM' env is defined. - if runInPTY() { - t.Log("1") - cmd.Env = append(cmd.Env, "TERM=xterm") - t.Log(cmd.Env) - - f, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 100, Cols: 100}) - assert.NoError(t, err) - - _, _ = io.Copy(ioutil.Discard, f) - - assert.NoError(t, err) - - _ = f.Close() - } else { - t.Log("2") - err := cmd.Run() - assert.NoError(t, err) - } -} - -func runInParallel() bool { - return os.Getenv("PARALLEL") != "" -} + cmd.Stdout = os.Stdout + cmd.Stdin = os.Stdin + cmd.Stderr = os.Stderr + cmd.Env = append( + cmd.Env, + fmt.Sprintf("REPLAY_EVENTS_FROM=%s", replayPath), + "HEADLESS=true", + ) -func runInPTY() bool { - return true + err = cmd.Run() + assert.NoError(t, err) } func prepareIntegrationTestDir(actualDir string) { -- cgit v1.2.3