From 9c0d860980a2391d938e77bac54efdc2a5015103 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 14 Aug 2022 19:15:21 +1000 Subject: [PATCH] basic custom command test --- pkg/config/user_config.go | 4 ++- pkg/integration/clients/cli.go | 11 ++++++ .../tests/custom_commands/basic.go | 34 ++++++++++++++++++ pkg/integration/tests/tests.go | 2 ++ .../customCommands/config/config.yml | 18 ---------- .../expected/repo/.git_keep/COMMIT_EDITMSG | 1 - .../expected/repo/.git_keep/index | Bin 137 -> 0 bytes .../expected/repo/.git_keep/logs/HEAD | 1 - .../repo/.git_keep/logs/refs/heads/master | 1 - .../15/bdb2c31c825116ad5af06ee25517d90b24f13b | Bin 115 -> 0 bytes .../20/f11a5545b04a86ca81f7a9967d5207349052d7 | Bin 22 -> 0 bytes .../8a/2e45643093ea7cf7b06382e38470034c24e812 | Bin 49 -> 0 bytes .../expected/repo/.git_keep/refs/heads/master | 1 - .../customCommands/expected/repo/blah | 1 - .../integration/customCommands/recording.json | 1 - test/integration/customCommands/setup.sh | 10 ------ test/integration/customCommands/test.json | 1 - .../basic}/expected/repo/.git_keep/FETCH_HEAD | 0 .../basic}/expected/repo/.git_keep/HEAD | 0 .../basic}/expected/repo/.git_keep/config | 0 .../expected/repo/.git_keep/description | 0 .../expected/repo/.git_keep/info/exclude | 0 .../basic/expected/repo/myfile | 0 23 files changed, 50 insertions(+), 36 deletions(-) create mode 100644 pkg/integration/tests/custom_commands/basic.go delete mode 100644 test/integration/customCommands/config/config.yml delete mode 100644 test/integration/customCommands/expected/repo/.git_keep/COMMIT_EDITMSG delete mode 100644 test/integration/customCommands/expected/repo/.git_keep/index delete mode 100644 test/integration/customCommands/expected/repo/.git_keep/logs/HEAD delete mode 100644 test/integration/customCommands/expected/repo/.git_keep/logs/refs/heads/master delete mode 100644 test/integration/customCommands/expected/repo/.git_keep/objects/15/bdb2c31c825116ad5af06ee25517d90b24f13b delete mode 100644 test/integration/customCommands/expected/repo/.git_keep/objects/20/f11a5545b04a86ca81f7a9967d5207349052d7 delete mode 100644 test/integration/customCommands/expected/repo/.git_keep/objects/8a/2e45643093ea7cf7b06382e38470034c24e812 delete mode 100644 test/integration/customCommands/expected/repo/.git_keep/refs/heads/master delete mode 100644 test/integration/customCommands/expected/repo/blah delete mode 100644 test/integration/customCommands/recording.json delete mode 100644 test/integration/customCommands/setup.sh delete mode 100644 test/integration/customCommands/test.json rename test/{integration/customCommands => integration_new/custom_commands/basic}/expected/repo/.git_keep/FETCH_HEAD (100%) rename test/{integration/customCommands => integration_new/custom_commands/basic}/expected/repo/.git_keep/HEAD (100%) rename test/{integration/customCommands => integration_new/custom_commands/basic}/expected/repo/.git_keep/config (100%) rename test/{integration/customCommands => integration_new/custom_commands/basic}/expected/repo/.git_keep/description (100%) rename test/{integration/customCommands => integration_new/custom_commands/basic}/expected/repo/.git_keep/info/exclude (100%) create mode 100644 test/integration_new/custom_commands/basic/expected/repo/myfile diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 804a5bee0..7e6a21656 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -314,7 +314,9 @@ type CustomCommand struct { } type CustomCommandPrompt struct { - Type string `yaml:"type"` // one of 'input', 'menu', or 'confirm' + // one of 'input', 'menu', 'confirm', or 'menuFromCommand' + Type string `yaml:"type"` + Title string `yaml:"title"` // this only apply to input prompts diff --git a/pkg/integration/clients/cli.go b/pkg/integration/clients/cli.go index 76f0c9549..79bb96c4f 100644 --- a/pkg/integration/clients/cli.go +++ b/pkg/integration/clients/cli.go @@ -4,8 +4,11 @@ import ( "log" "os" "os/exec" + "regexp" "strconv" + "strings" + "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/integration/components" "github.com/jesseduffield/lazygit/pkg/integration/tests" ) @@ -47,6 +50,14 @@ func getTestsToRun(testNames []string) []*components.IntegrationTest { return tests.Tests } + testNames = slices.Map(testNames, func(name string) string { + // allowing full test paths to be passed for convenience + return strings.TrimSuffix( + regexp.MustCompile(`.*pkg/integration/tests/`).ReplaceAllString(name, ""), + ".go", + ) + }) + outer: for _, testName := range testNames { // check if our given test name actually exists diff --git a/pkg/integration/tests/custom_commands/basic.go b/pkg/integration/tests/custom_commands/basic.go new file mode 100644 index 000000000..5961dc0c5 --- /dev/null +++ b/pkg/integration/tests/custom_commands/basic.go @@ -0,0 +1,34 @@ +package custom_commands + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var Basic = components.NewIntegrationTest(components.NewIntegrationTestArgs{ + Description: "Using a custom command to create a new file", + ExtraCmdArgs: "", + Skip: false, + SetupRepo: func(shell *components.Shell) {}, + SetupConfig: func(cfg *config.AppConfig) { + cfg.UserConfig.CustomCommands = []config.CustomCommand{ + { + Key: "a", + Context: "files", + Command: "touch myfile", + }, + } + }, + Run: func( + shell *components.Shell, + input *components.Input, + assert *components.Assert, + keys config.KeybindingConfig, + ) { + assert.WorkingTreeFileCount(0) + + input.PressKeys("a") + assert.WorkingTreeFileCount(1) + assert.SelectedLineContains("myfile") + }, +}) diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go index e9794169a..704c2fd5b 100644 --- a/pkg/integration/tests/tests.go +++ b/pkg/integration/tests/tests.go @@ -4,6 +4,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/integration/components" "github.com/jesseduffield/lazygit/pkg/integration/tests/branch" "github.com/jesseduffield/lazygit/pkg/integration/tests/commit" + "github.com/jesseduffield/lazygit/pkg/integration/tests/custom_commands" "github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase" ) @@ -15,4 +16,5 @@ var Tests = []*components.IntegrationTest{ commit.NewBranch, branch.Suggestions, interactive_rebase.One, + custom_commands.Basic, } diff --git a/test/integration/customCommands/config/config.yml b/test/integration/customCommands/config/config.yml deleted file mode 100644 index 33c1d684e..000000000 --- a/test/integration/customCommands/config/config.yml +++ /dev/null @@ -1,18 +0,0 @@ -disableStartupPopups: true -customCommands: - - key : 'N' - description: 'Add file' - command: "echo {{index .PromptResponses 0}} > {{index .PromptResponses 1}}" - context: 'files' - prompts: - - type: 'input' - title: 'File name:' - - type: 'input' - title: 'File content:' -gui: - theme: - activeBorderColor: - - green - - bold - SelectedRangeBgcolor: - - reverse diff --git a/test/integration/customCommands/expected/repo/.git_keep/COMMIT_EDITMSG b/test/integration/customCommands/expected/repo/.git_keep/COMMIT_EDITMSG deleted file mode 100644 index 9daeafb98..000000000 --- a/test/integration/customCommands/expected/repo/.git_keep/COMMIT_EDITMSG +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/test/integration/customCommands/expected/repo/.git_keep/index b/test/integration/customCommands/expected/repo/.git_keep/index deleted file mode 100644 index 1cdf852e0713c3e8ea61b27b3724e82e40d966be..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 137 zcmZ?q402{*U|<4b#)RzWk4#>tJ%G`S3=Ax6dKG*O42?^G(qDmUM1YuG;iFWj>jtm3 zQ;pwOPOA-KH<=K0oq;7OCouyk3j`rSuC72zlEF~HfU8T-HN{}^tD5f{lA9j46fpa! cybzk@EPB+&F7%-8pPa^X6E7}at$1Dm09RfvN&o-= diff --git a/test/integration/customCommands/expected/repo/.git_keep/logs/HEAD b/test/integration/customCommands/expected/repo/.git_keep/logs/HEAD deleted file mode 100644 index db58e88aa..000000000 --- a/test/integration/customCommands/expected/repo/.git_keep/logs/HEAD +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 15bdb2c31c825116ad5af06ee25517d90b24f13b CI 1617684452 +1000 commit (initial): test diff --git a/test/integration/customCommands/expected/repo/.git_keep/logs/refs/heads/master b/test/integration/customCommands/expected/repo/.git_keep/logs/refs/heads/master deleted file mode 100644 index db58e88aa..000000000 --- a/test/integration/customCommands/expected/repo/.git_keep/logs/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 15bdb2c31c825116ad5af06ee25517d90b24f13b CI 1617684452 +1000 commit (initial): test diff --git a/test/integration/customCommands/expected/repo/.git_keep/objects/15/bdb2c31c825116ad5af06ee25517d90b24f13b b/test/integration/customCommands/expected/repo/.git_keep/objects/15/bdb2c31c825116ad5af06ee25517d90b24f13b deleted file mode 100644 index c309d426af063c2200992b0203261b2c5f1046f9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 115 zcmV-(0F3{50gcT~3IZ_PwL}ywl`(?HcaGrp@xg1O_eTJ! z>|%8XtL!>u6+DX9(r)F7S&Usw3!-Rabt6vo6Zf&gyufK*F8;0k_4Gp<{S1_;WK*3O V_JoLOtJ@^}PoBcxk$xpyDzKO3Izs>e diff --git a/test/integration/customCommands/expected/repo/.git_keep/objects/20/f11a5545b04a86ca81f7a9967d5207349052d7 b/test/integration/customCommands/expected/repo/.git_keep/objects/20/f11a5545b04a86ca81f7a9967d5207349052d7 deleted file mode 100644 index 368e30f82b6f1d0ed62195e609f39f366789cb27..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22 ecmb9VlXr?Ff%bxNXkjfU{Lrd73#XdtL;?d_m$IXgV;?b1YHLJ H0Pzl`!qXGp diff --git a/test/integration/customCommands/expected/repo/.git_keep/refs/heads/master b/test/integration/customCommands/expected/repo/.git_keep/refs/heads/master deleted file mode 100644 index ce73a61b4..000000000 --- a/test/integration/customCommands/expected/repo/.git_keep/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -15bdb2c31c825116ad5af06ee25517d90b24f13b diff --git a/test/integration/customCommands/expected/repo/blah b/test/integration/customCommands/expected/repo/blah deleted file mode 100644 index 20f11a554..000000000 --- a/test/integration/customCommands/expected/repo/blah +++ /dev/null @@ -1 +0,0 @@ -myfile diff --git a/test/integration/customCommands/recording.json b/test/integration/customCommands/recording.json deleted file mode 100644 index f49c696e3..000000000 --- a/test/integration/customCommands/recording.json +++ /dev/null @@ -1 +0,0 @@ -{"KeyEvents":[{"Timestamp":837,"Mod":0,"Key":256,"Ch":78},{"Timestamp":1622,"Mod":0,"Key":256,"Ch":109},{"Timestamp":1798,"Mod":0,"Key":256,"Ch":121},{"Timestamp":1918,"Mod":0,"Key":256,"Ch":102},{"Timestamp":2006,"Mod":0,"Key":256,"Ch":105},{"Timestamp":2078,"Mod":0,"Key":256,"Ch":108},{"Timestamp":2174,"Mod":0,"Key":256,"Ch":101},{"Timestamp":2431,"Mod":0,"Key":13,"Ch":13},{"Timestamp":3246,"Mod":0,"Key":256,"Ch":98},{"Timestamp":3294,"Mod":0,"Key":256,"Ch":108},{"Timestamp":3398,"Mod":0,"Key":256,"Ch":97},{"Timestamp":3462,"Mod":0,"Key":256,"Ch":104},{"Timestamp":3735,"Mod":0,"Key":13,"Ch":13},{"Timestamp":4206,"Mod":0,"Key":256,"Ch":32},{"Timestamp":4421,"Mod":0,"Key":256,"Ch":99},{"Timestamp":4646,"Mod":0,"Key":256,"Ch":116},{"Timestamp":4726,"Mod":0,"Key":256,"Ch":101},{"Timestamp":4886,"Mod":0,"Key":256,"Ch":115},{"Timestamp":4918,"Mod":0,"Key":256,"Ch":116},{"Timestamp":5190,"Mod":0,"Key":13,"Ch":13},{"Timestamp":5550,"Mod":0,"Key":256,"Ch":113}],"ResizeEvents":[{"Timestamp":0,"Width":272,"Height":74}]} \ No newline at end of file diff --git a/test/integration/customCommands/setup.sh b/test/integration/customCommands/setup.sh deleted file mode 100644 index fbd02e952..000000000 --- a/test/integration/customCommands/setup.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -set -e - -cd $1 - -git init - -git config user.email "CI@example.com" -git config user.name "CI" diff --git a/test/integration/customCommands/test.json b/test/integration/customCommands/test.json deleted file mode 100644 index c5c5aaf5c..000000000 --- a/test/integration/customCommands/test.json +++ /dev/null @@ -1 +0,0 @@ -{ "description": "Invoke a custom command that creates a file, and then stage and commit that file", "speed": 5 } diff --git a/test/integration/customCommands/expected/repo/.git_keep/FETCH_HEAD b/test/integration_new/custom_commands/basic/expected/repo/.git_keep/FETCH_HEAD similarity index 100% rename from test/integration/customCommands/expected/repo/.git_keep/FETCH_HEAD rename to test/integration_new/custom_commands/basic/expected/repo/.git_keep/FETCH_HEAD diff --git a/test/integration/customCommands/expected/repo/.git_keep/HEAD b/test/integration_new/custom_commands/basic/expected/repo/.git_keep/HEAD similarity index 100% rename from test/integration/customCommands/expected/repo/.git_keep/HEAD rename to test/integration_new/custom_commands/basic/expected/repo/.git_keep/HEAD diff --git a/test/integration/customCommands/expected/repo/.git_keep/config b/test/integration_new/custom_commands/basic/expected/repo/.git_keep/config similarity index 100% rename from test/integration/customCommands/expected/repo/.git_keep/config rename to test/integration_new/custom_commands/basic/expected/repo/.git_keep/config diff --git a/test/integration/customCommands/expected/repo/.git_keep/description b/test/integration_new/custom_commands/basic/expected/repo/.git_keep/description similarity index 100% rename from test/integration/customCommands/expected/repo/.git_keep/description rename to test/integration_new/custom_commands/basic/expected/repo/.git_keep/description diff --git a/test/integration/customCommands/expected/repo/.git_keep/info/exclude b/test/integration_new/custom_commands/basic/expected/repo/.git_keep/info/exclude similarity index 100% rename from test/integration/customCommands/expected/repo/.git_keep/info/exclude rename to test/integration_new/custom_commands/basic/expected/repo/.git_keep/info/exclude diff --git a/test/integration_new/custom_commands/basic/expected/repo/myfile b/test/integration_new/custom_commands/basic/expected/repo/myfile new file mode 100644 index 000000000..e69de29bb