1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-10 11:10:18 +02:00

Merge pull request #2336 from jesseduffield/migrate-even-more-tests

This commit is contained in:
Jesse Duffield 2022-12-28 16:01:11 +11:00 committed by GitHub
commit ff8823093c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
91 changed files with 176 additions and 195 deletions

View File

@ -79,6 +79,8 @@ To run a test in sandbox mode you can press 's' on a test in the test TUI or in
## Migration process
You can watch how to migrate tests in this youtube [video](https://youtu.be/cJtOJu6-HcA).
At the time of writing, most tests are created under an old approach, where you would record yourself in a lazygit session and then the test would replay the keybindings with the same timestamps. This old approach is great for writing tests quickly, but is much harder to maintain. It has to rely on snapshots to determining if a test passes or fails, and can't do assertions along the way. It's also harder to grok what's the intention behind certain actions that take place within the test (e.g. was the recorder intentionally switching to another panel or was that just a misclick?).
At the moment, all the deprecated test code lives in pkg/integration/deprecated. Hopefully in the very near future we migrate everything across so that we don't need to maintain two systems.

View File

@ -24,3 +24,26 @@ func (self *FileSystem) PathNotPresent(path string) {
return os.IsNotExist(err), fmt.Sprintf("Expected path '%s' to not exist, but it does", path)
})
}
// Asserts that the file at the given path has the given content
func (self *FileSystem) FileContent(path string, matcher *matcher) {
self.assertWithRetries(func() (bool, string) {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return false, fmt.Sprintf("Expected path '%s' to not exist, but it does", path)
}
output, err := os.ReadFile(path)
if err != nil {
return false, fmt.Sprintf("Expected error when reading file content at path '%s': %s", path, err.Error())
}
strOutput := string(output)
if ok, errMsg := matcher.context("").test(strOutput); !ok {
return false, fmt.Sprintf("Unexpected content in file %s: %s", path, errMsg)
}
return true, ""
})
}

View File

@ -0,0 +1,57 @@
package commit
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var DiscardOldFileChange = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Discarding a single file from an old commit (does rebase in background to remove the file but retain the other one)",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file0", "file0")
shell.Commit("first commit")
shell.CreateFileAndAdd("file1", "file2")
shell.CreateFileAndAdd("fileToRemove", "fileToRemove")
shell.Commit("commit to change")
shell.CreateFileAndAdd("file3", "file3")
shell.Commit("third commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("third commit").IsSelected(),
Contains("commit to change"),
Contains("first commit"),
).
SelectNextItem().
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
Contains("fileToRemove"),
).
SelectNextItem().
Press(keys.Universal.Remove)
t.ExpectPopup().Confirmation().
Title(Equals("Discard file changes")).
Content(Contains("Are you sure you want to discard this commit's changes to this file?")).
Confirm()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
)
t.FileSystem().PathNotPresent("fileToRemove")
},
})

View File

@ -0,0 +1,52 @@
package file
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var DiscardStagedChanges = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Discarding staged changes",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {
},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("fileToRemove", "original content")
shell.CreateFileAndAdd("file2", "original content")
shell.Commit("first commit")
shell.CreateFile("file3", "original content")
shell.UpdateFile("fileToRemove", "new content")
shell.UpdateFile("file2", "new content")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().
IsFocused().
Lines(
Contains(` M file2`).IsSelected(),
Contains(` M fileToRemove`),
Contains(`?? file3`),
).
SelectNextItem().
PressPrimaryAction().
Lines(
Contains(` M file2`),
Contains(`M fileToRemove`).IsSelected(),
Contains(`?? file3`),
).
Press(keys.Files.ViewResetOptions)
t.ExpectPopup().Menu().Title(Equals("")).Select(Contains("discard staged changes")).Confirm()
// staged file has been removed
t.Views().Files().
Lines(
Contains(` M file2`),
Contains(`?? file3`).IsSelected(),
)
// the file should have the same content that it originally had, given that that was committed already
t.FileSystem().FileContent("fileToRemove", Equals("original content"))
},
})

View File

@ -0,0 +1,39 @@
package file
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ExcludeGitignore = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Failed attempt at excluding and ignoring the .gitignore file",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {
},
SetupRepo: func(shell *Shell) {
shell.CreateFile(".gitignore", "")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().
IsFocused().
Lines(
Contains(`?? .gitignore`).IsSelected(),
).
Press(keys.Files.IgnoreFile).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("ignore or exclude file")).Select(Contains("add to .git/info/exclude")).Confirm()
t.ExpectPopup().Alert().Title(Equals("Error")).Content(Equals("Cannot exclude .gitignore")).Confirm()
}).
Press(keys.Files.IgnoreFile).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("ignore or exclude file")).Select(Contains("add to .gitignore")).Confirm()
t.ExpectPopup().Alert().Title(Equals("Error")).Content(Equals("Cannot ignore .gitignore")).Confirm()
})
t.FileSystem().FileContent(".gitignore", Equals(""))
t.FileSystem().FileContent(".git/info/exclude", DoesNotContain(".gitignore"))
},
})

View File

@ -45,6 +45,7 @@ var tests = []*components.IntegrationTest{
commit.Staged,
commit.Unstaged,
commit.StagedWithoutHooks,
commit.DiscardOldFileChange,
custom_commands.Basic,
custom_commands.FormPrompts,
custom_commands.MenuFromCommand,
@ -52,6 +53,8 @@ var tests = []*components.IntegrationTest{
custom_commands.MultiplePrompts,
file.DirWithUntrackedFile,
file.DiscardChanges,
file.DiscardStagedChanges,
file.ExcludeGitignore,
interactive_rebase.AmendMerge,
interactive_rebase.One,
stash.Rename,

View File

@ -1 +0,0 @@
ref: refs/heads/master

View File

@ -1 +0,0 @@
7880a9728615a4d196df39600a0c8c71b40d96d6

View File

@ -1,10 +0,0 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[user]
email = CI@example.com
name = CI

View File

@ -1 +0,0 @@
Unnamed repository; edit this file 'description' to name the repository.

View File

@ -1,7 +0,0 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.DS_Store

View File

@ -1,9 +0,0 @@
0000000000000000000000000000000000000000 b7a702b642978f2a9b1af9c1c67b22127af78c92 CI <CI@example.com> 1641697108 +1100 commit (initial): file0
b7a702b642978f2a9b1af9c1c67b22127af78c92 7880a9728615a4d196df39600a0c8c71b40d96d6 CI <CI@example.com> 1641697108 +1100 commit: twoFiles
7880a9728615a4d196df39600a0c8c71b40d96d6 af6725ba23f43a286deff0747476d7874113df1e CI <CI@example.com> 1641697108 +1100 commit: file2
af6725ba23f43a286deff0747476d7874113df1e af6725ba23f43a286deff0747476d7874113df1e CI <CI@example.com> 1641697111 +1100 rebase: updating HEAD
af6725ba23f43a286deff0747476d7874113df1e b7a702b642978f2a9b1af9c1c67b22127af78c92 CI <CI@example.com> 1641697111 +1100 rebase -i (start): checkout b7a702b642978f2a9b1af9c1c67b22127af78c92
b7a702b642978f2a9b1af9c1c67b22127af78c92 7880a9728615a4d196df39600a0c8c71b40d96d6 CI <CI@example.com> 1641697111 +1100 rebase -i: fast-forward
7880a9728615a4d196df39600a0c8c71b40d96d6 d14505f281a54cda96fc5fb8cd4b4ee14bae6264 CI <CI@example.com> 1641697111 +1100 commit (amend): twoFiles
d14505f281a54cda96fc5fb8cd4b4ee14bae6264 225ad83faa797c1831a2bc956a21e2d472f21443 CI <CI@example.com> 1641697111 +1100 rebase -i (pick): file2
225ad83faa797c1831a2bc956a21e2d472f21443 225ad83faa797c1831a2bc956a21e2d472f21443 CI <CI@example.com> 1641697111 +1100 rebase -i (finish): returning to refs/heads/master

View File

@ -1,4 +0,0 @@
0000000000000000000000000000000000000000 b7a702b642978f2a9b1af9c1c67b22127af78c92 CI <CI@example.com> 1641697108 +1100 commit (initial): file0
b7a702b642978f2a9b1af9c1c67b22127af78c92 7880a9728615a4d196df39600a0c8c71b40d96d6 CI <CI@example.com> 1641697108 +1100 commit: twoFiles
7880a9728615a4d196df39600a0c8c71b40d96d6 af6725ba23f43a286deff0747476d7874113df1e CI <CI@example.com> 1641697108 +1100 commit: file2
af6725ba23f43a286deff0747476d7874113df1e 225ad83faa797c1831a2bc956a21e2d472f21443 CI <CI@example.com> 1641697111 +1100 rebase -i (finish): refs/heads/master onto b7a702b642978f2a9b1af9c1c67b22127af78c92

View File

@ -1 +0,0 @@
x��±j1DSßW¨„]iO+™ ®\åVÚD>s'C>?jÒ‡é†÷¦n½ çWz»™Ãd9±’VÐc\3{Z3VeÈæ…SÆD­.Ùí>œ´È~-âC£ >EµÖ€i&*'&Ä  í�‡ª%ªa›ZÔ¨*ÁG)LÃ"ÏqÛvw¹º÷Ëõl?ÒßöV·þá0Æ̈è^–ÙÎÃþ‰/Ÿw×å˜üÉÍ™írÜ~ìKò

View File

@ -1,2 +0,0 @@
x�ŽA
Â0E]ç³$“¦™DD„®zŒi2Á‚iK�Ðã›�{y»ÏûðâZÊ\Á �ê.è%xJ�å<¡A×2¶é †Éô6Gµñ.KÎŽL?±é²íØx—$gM¶áy²ˆ]Ê(Š?õ¹î0ŒpƇ\¶—\âZî€Î¢ „ˆpFÔZµµEUùSWó’ä€u�Âïöºþª Ï/1ê ÜZ@¼

View File

@ -1,3 +0,0 @@
x�ÎA
à @Ñ®=…ûB™‰qT(¥�UŽ1Ž# Ä& =~s„nñekméÓp釪�,R‹ó ^krÁåÌ©xrN*)…])Þì|è»Û#p
C$ô<LTªKÀ QæÊidøÓ_Ûa§ÙÞ§ù©_nûª7ÙÚÃ"�H) D{E0§žS]ÿÌM]V̈‘9n

View File

@ -1,2 +0,0 @@
x�ÍA
Â0Fa×9Å왉cÒ¡«#iþ`¡¡R"x|{·�Þ¼µ¶tÕSß\b6³’åC*ð�«Vö¹ToPSõ.}úkÛiœè>NO|S{¯¸Ì[{�•`Qx ³³;ê1éø“»º¬`÷Ü7+ò

View File

@ -1,2 +0,0 @@
x+)JMU03c040031QHヒフI5`ーアコイ燹ヨカwチ�w.ス��モ[H
矢y�5�来ミ(桍ァ ^-ンW(x9

View File

@ -1 +0,0 @@
225ad83faa797c1831a2bc956a21e2d472f21443

View File

@ -1 +0,0 @@
{"KeyEvents":[{"Timestamp":635,"Mod":0,"Key":259,"Ch":0},{"Timestamp":899,"Mod":0,"Key":259,"Ch":0},{"Timestamp":1227,"Mod":0,"Key":258,"Ch":0},{"Timestamp":1571,"Mod":0,"Key":13,"Ch":13},{"Timestamp":1971,"Mod":0,"Key":258,"Ch":0},{"Timestamp":2322,"Mod":0,"Key":256,"Ch":100},{"Timestamp":2731,"Mod":0,"Key":13,"Ch":13},{"Timestamp":3707,"Mod":0,"Key":256,"Ch":113}],"ResizeEvents":[{"Timestamp":0,"Width":272,"Height":74}]}

View File

@ -1,26 +0,0 @@
#!/bin/sh
set -e
cd $1
git init
git config user.email "CI@example.com"
git config user.name "CI"
echo test0 > file0
git add .
git commit -am file0
echo test1 > file1
echo testZ > fileZ
git add .
git commit -am twoFiles
echo test2 > file2
git add .
git commit -am file2
echo test3 > file3
git add .

View File

@ -1,4 +0,0 @@
{
"description": "Discarding a single file from an old commit (does rebase in background to remove the file but retain the other one)",
"speed": 5
}

View File

@ -1 +0,0 @@
ref: refs/heads/master

View File

@ -1 +0,0 @@
02f629e46dbaa03b58196cced3df07b02c0daf22

View File

@ -1,8 +0,0 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[user]
email = CI@example.com
name = CI

View File

@ -1 +0,0 @@
Unnamed repository; edit this file 'description' to name the repository.

View File

@ -1,6 +0,0 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~

View File

@ -1,5 +0,0 @@
0000000000000000000000000000000000000000 22f24c5fcc97c1ff826ecb66b60bdc01937f6052 CI <CI@example.com> 1652009263 +0200 commit (initial): file0
22f24c5fcc97c1ff826ecb66b60bdc01937f6052 9e7ff93a5c67a0ef098e9e436961746f333edf98 CI <CI@example.com> 1652009263 +0200 commit: file1
9e7ff93a5c67a0ef098e9e436961746f333edf98 02f629e46dbaa03b58196cced3df07b02c0daf22 CI <CI@example.com> 1652009263 +0200 commit: file2
02f629e46dbaa03b58196cced3df07b02c0daf22 02f629e46dbaa03b58196cced3df07b02c0daf22 CI <CI@example.com> 1652009266 +0200 reset: moving to HEAD
02f629e46dbaa03b58196cced3df07b02c0daf22 02f629e46dbaa03b58196cced3df07b02c0daf22 CI <CI@example.com> 1652009266 +0200 reset: moving to HEAD

View File

@ -1,3 +0,0 @@
0000000000000000000000000000000000000000 22f24c5fcc97c1ff826ecb66b60bdc01937f6052 CI <CI@example.com> 1652009263 +0200 commit (initial): file0
22f24c5fcc97c1ff826ecb66b60bdc01937f6052 9e7ff93a5c67a0ef098e9e436961746f333edf98 CI <CI@example.com> 1652009263 +0200 commit: file1
9e7ff93a5c67a0ef098e9e436961746f333edf98 02f629e46dbaa03b58196cced3df07b02c0daf22 CI <CI@example.com> 1652009263 +0200 commit: file2

View File

@ -1,3 +0,0 @@
x��Á
Â0=ç+ö.È&ݦ.ˆ=õ3’æ )%‚Ÿo>ÁÛ0 ÌZKÙY‘K;²২ª)Úqò!Y€ï1KfSv
Qg§½ëIóB�yyáʱã¶Öò$ëGǬÎtåN¦Û>iø37yÛÁæÙ2+à

View File

@ -1,3 +0,0 @@
x+)JMU°΄d040031QHΛΜI5`°±Ί²ΰ�Φ¶wΑ‡ήw.½ωhοTΣ[H
�Ώe“ς"Η¨ΰSς,αΚgu"��YH
�$x~5(ν;χrΥΆπ�ώ–WΪσ-ΤΠ–+^

View File

@ -1,2 +0,0 @@
x�ŽÁ
Â0D=ç+ö.Èv›n<õ3²É ¦-5‚Ÿo.Þ½ üáŵ”¹uã¡îªÀ,ú˜BNŽÇ˜}O(YF묈ËÁyg­3[Øu©€”™¼ZNö2¸ÎsŒšú”q¤ˆí‰È„w}¬;Ü'¸Ü§›~BÙžzŠk¹BÇ!zb†#¶dZÛ¤ªþ97ó’ôë%¼uþYAžŸJæ  BP

View File

@ -1,2 +0,0 @@
x�ŽA
Â0E]çÙ 2™$"BW=F2™Á‚µ¥Dðøæî>�÷àó¶®K·.ã©"¶A"æÌ ¹p)Ø<iåTrÔæ=PÈ�‚3{9äÝ-¢bਣIìT¯H•¨ÔÆà²OJÑ”On‡�f{›æ‡|˺¿äÂÛz·Ž"d$oÏ0–tœêò§nty‰3?ÄÇ9Ø

View File

@ -1,2 +0,0 @@
x+)JMU03c040031QHヒフI5`ーアコイ燹ヨカwチ�w.ス��モ[H
矢y�5�来ミ(桍ァ ^-ンW(x9

View File

@ -1 +0,0 @@
02f629e46dbaa03b58196cced3df07b02c0daf22

View File

@ -1 +0,0 @@
hello there

View File

@ -1 +0,0 @@
hello there

View File

@ -1 +0,0 @@
{"KeyEvents":[{"Timestamp":1175,"Mod":0,"Key":256,"Ch":32},{"Timestamp":1991,"Mod":0,"Key":256,"Ch":68},{"Timestamp":2923,"Mod":0,"Key":256,"Ch":83},{"Timestamp":4453,"Mod":0,"Key":256,"Ch":113}],"ResizeEvents":[{"Timestamp":0,"Width":213,"Height":56}]}

View File

@ -1,26 +0,0 @@
#!/bin/sh
set -e
cd $1
git init
git config user.email "CI@example.com"
git config user.name "CI"
echo test0 > file0
git add .
git commit -am file0
echo test1 > file1
git add .
git commit -am file1
echo test2 > file2
git add .
git commit -am file2
echo "hello there" > file1
echo "hello there" > file2
echo "hello there" > file3

View File

@ -1 +0,0 @@
{ "description": "Discarding staged changes", "speed": 5 }

View File

@ -1 +0,0 @@
ref: refs/heads/master

View File

@ -1,10 +0,0 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[user]
email = CI@example.com
name = CI

View File

@ -1 +0,0 @@
Unnamed repository; edit this file 'description' to name the repository.

View File

@ -1,7 +0,0 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.DS_Store

View File

@ -1 +0,0 @@
0000000000000000000000000000000000000000 e976bc07c8784964cf239ac9fbdc3535df55269c CI <CI@example.com> 1657012812 +1000 commit (initial): Initial commit

View File

@ -1 +0,0 @@
0000000000000000000000000000000000000000 e976bc07c8784964cf239ac9fbdc3535df55269c CI <CI@example.com> 1657012812 +1000 commit (initial): Initial commit

View File

@ -1 +0,0 @@
e976bc07c8784964cf239ac9fbdc3535df55269c

View File

@ -1 +0,0 @@
{"KeyEvents":[{"Timestamp":642,"Mod":0,"Key":256,"Ch":105},{"Timestamp":1529,"Mod":0,"Key":256,"Ch":101},{"Timestamp":2522,"Mod":0,"Key":27,"Ch":0},{"Timestamp":2962,"Mod":0,"Key":256,"Ch":113}],"ResizeEvents":[{"Timestamp":0,"Width":238,"Height":61}]}

View File

@ -1,15 +0,0 @@
#!/bin/sh
set -e
cd $1
git init
git config user.email "CI@example.com"
git config user.name "CI"
git commit --allow-empty -m "Initial commit"
echo test1 > .gitignore

View File

@ -1,4 +0,0 @@
{
"description": "In this test we attempt to add .gitignore to .git/info/exclude to ensure lazygit rejects the action",
"speed": 5
}