1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-21 21:47:32 +02:00
This commit is contained in:
Jesse Duffield 2020-10-05 21:00:31 +11:00
parent dc953ea680
commit 2724f3888a
2 changed files with 31 additions and 30 deletions

View File

@ -20,8 +20,8 @@ import (
// To record keypresses for an integration test, pass RECORD_EVENTS=true like so:
// RECORD_EVENTS=true go test pkg/gui/gui_test.go -run /commit
//
// To update a snapshot for an integration test, pass UPDATE_SNAPSHOT=true
// UPDATE_SNAPSHOT=true go test pkg/gui/gui_test.go -run /commit
// To update a snapshot for an integration test, pass UPDATE_SNAPSHOTS=true
// UPDATE_SNAPSHOTS=true go test pkg/gui/gui_test.go -run /commit
//
// When RECORD_EVENTS is true, updates will be updated automatically
//
@ -71,7 +71,7 @@ func tests() []integrationTest {
func generateSnapshot(t *testing.T) string {
osCommand := oscommands.NewDummyOSCommand()
cmd := `sh -c "git status; cat ./*; git log --pretty=%B -p"`
cmd := `bash -c "git status; cat ./*; git log --pretty=%B -p"`
snapshot, err := osCommand.RunCommandWithOutput(cmd)
assert.NoError(t, err)
@ -103,12 +103,21 @@ func Test(t *testing.T) {
panic(err)
}
record := os.Getenv("RECORD_EVENTS") != ""
updateSnapshots := record || os.Getenv("UPDATE_SNAPSHOTS") != ""
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
speeds := []int{10, 5, 1}
if updateSnapshots {
// have to go at original speed if updating snapshots in case we go to fast and create a junk snapshot
speeds = []int{1}
}
for i, speed := range speeds {
fmt.Printf("%s: trying again at speed %d\n", test.name, speed)
t.Logf("%s: attempting test at speed %d\n", test.name, speed)
testPath := filepath.Join(rootDir, "test", "integration", test.name)
findOrCreateDir(testPath)
@ -123,14 +132,11 @@ func Test(t *testing.T) {
err = createFixture(rootDir, test.fixture)
assert.NoError(t, err)
record := os.Getenv("RECORD_EVENTS") != ""
runLazygit(t, testPath, rootDir, record, speed)
updateSnapshot := record || os.Getenv("UPDATE_SNAPSHOT") != ""
actual := generateSnapshot(t)
if updateSnapshot {
if updateSnapshots {
err := ioutil.WriteFile(snapshotPath, []byte(actual), 0600)
assert.NoError(t, err)
}
@ -154,7 +160,7 @@ func Test(t *testing.T) {
func createFixture(rootDir string, name string) error {
osCommand := oscommands.NewDummyOSCommand()
cmd := exec.Command("sh", filepath.Join(rootDir, "test", "fixtures", fmt.Sprintf("%s.sh", name)))
cmd := exec.Command("bash", filepath.Join(rootDir, "test", "fixtures", fmt.Sprintf("%s.sh", name)))
if err := osCommand.RunExecutable(cmd); err != nil {
return err
@ -226,8 +232,11 @@ func runLazygit(t *testing.T, testPath string, rootDir string, record bool, spee
f, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 100, Cols: 100})
assert.NoError(t, err)
_, err = io.Copy(os.Stdout, f)
_, _ = io.Copy(ioutil.Discard, f)
assert.NoError(t, err)
_ = f.Close()
} else {
err := osCommand.RunExecutable(cmd)
assert.NoError(t, err)

View File

@ -1,9 +1,7 @@
On branch other_branch
nothing to commit, working tree clean
cat: ./directory: Is a directory
new1
original2
original3
new1\noriginal2\noriginal3
Here is a story that has been told throuhg the ages
once upon a time there was a cat
...
@ -76,38 +74,32 @@ asd
diff --git a/file b/file
index 37ec558..51c0b8a 100644
index 5da4d92..2410ee1 100644
--- a/file
+++ b/file
@@ -1,3 +1,3 @@
-original1
+new2
original2
original3
@@ -1 +1 @@
-original1\noriginal2\noriginal3
+new2\noriginal2\noriginal3
file changed
diff --git a/file b/file
index 37ec558..fa90625 100644
index 5da4d92..173a40e 100644
--- a/file
+++ b/file
@@ -1,3 +1,3 @@
-original1
+new1
original2
original3
@@ -1 +1 @@
-original1\noriginal2\noriginal3
+new1\noriginal2\noriginal3
file
diff --git a/file b/file
new file mode 100644
index 0000000..37ec558
index 0000000..5da4d92
--- /dev/null
+++ b/file
@@ -0,0 +1,3 @@
+original1
+original2
+original3
@@ -0,0 +1 @@
+original1\noriginal2\noriginal3
fourth commit on master