1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

make it more likely for CI to work

This commit is contained in:
Jesse Duffield 2021-04-05 12:18:21 +10:00
parent 21af4927ac
commit 8ed490c780
2 changed files with 27 additions and 56 deletions

View File

@ -564,6 +564,14 @@ func (gui *Gui) RunAndHandleError() error {
} }
func (gui *Gui) runSubprocessWithSuspense(subprocess *exec.Cmd) 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 { if err := gocui.Screen.Suspend(); err != nil {
return gui.surfaceError(err) return gui.surfaceError(err)
} }

View File

@ -3,7 +3,6 @@ package gui
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -11,8 +10,6 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/creack/pty"
"github.com/davecgh/go-spew/spew"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/secureexec" "github.com/jesseduffield/lazygit/pkg/secureexec"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -181,10 +178,6 @@ func Test(t *testing.T) {
test := test test := test
t.Run(test.Name, func(t *testing.T) { t.Run(test.Name, func(t *testing.T) {
if runInParallel() {
t.Parallel()
}
speeds := getTestSpeeds(test.Speed, updateSnapshots) speeds := getTestSpeeds(test.Speed, updateSnapshots)
for i, speed := range speeds { for i, speed := range speeds {
@ -201,7 +194,9 @@ func Test(t *testing.T) {
err := createFixture(testPath, actualDir) err := createFixture(testPath, actualDir)
assert.NoError(t, err) 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 { if updateSnapshots {
err = oscommands.CopyDir(actualDir, expectedDir) 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 the snapshots and we haven't tried all playback speeds different we'll retry at a slower speed
if i == len(speeds)-1 { 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)) 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() osCommand := oscommands.NewDummyOSCommand()
replayPath := filepath.Join(testPath, "recording.json") 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") templateConfigDir = filepath.Join(testPath, "config")
} }
configDir := filepath.Join(testPath, "used_config")
err = os.RemoveAll(configDir) err = os.RemoveAll(configDir)
assert.NoError(t, err) assert.NoError(t, err)
err = oscommands.CopyDir(templateConfigDir, configDir) err = oscommands.CopyDir(templateConfigDir, configDir)
assert.NoError(t, err) 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 := osCommand.ExecutableFromString(cmdStr)
cmd.Env = append(cmd.Env, fmt.Sprintf("REPLAY_SPEED=%d", speed)) cmd.Env = append(cmd.Env, fmt.Sprintf("REPLAY_SPEED=%d", speed))
if record { cmd.Stdout = os.Stdout
cmd.Env = append( cmd.Stdin = os.Stdin
cmd.Env, cmd.Stderr = os.Stderr
fmt.Sprintf("RECORD_EVENTS_TO=%s", replayPath), cmd.Env = append(
) cmd.Env,
} else { fmt.Sprintf("REPLAY_EVENTS_FROM=%s", replayPath),
cmd.Stdout = os.Stdout "HEADLESS=true",
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") err = cmd.Run()
assert.NoError(t, err)
// 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") != ""
}
func runInPTY() bool {
return true
} }
func prepareIntegrationTestDir(actualDir string) { func prepareIntegrationTestDir(actualDir string) {