basic custom command test

This commit is contained in:
Jesse Duffield 2022-08-14 19:15:21 +10:00
parent 4aea005f26
commit 9c0d860980
23 changed files with 50 additions and 36 deletions

View file

@ -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

View file

@ -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

View file

@ -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")
},
})

View file

@ -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,
}

View file

@ -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

View file

@ -1 +0,0 @@
0000000000000000000000000000000000000000 15bdb2c31c825116ad5af06ee25517d90b24f13b CI <CI@example.com> 1617684452 +1000 commit (initial): test

View file

@ -1 +0,0 @@
0000000000000000000000000000000000000000 15bdb2c31c825116ad5af06ee25517d90b24f13b CI <CI@example.com> 1617684452 +1000 commit (initial): test

View file

@ -1 +0,0 @@
15bdb2c31c825116ad5af06ee25517d90b24f13b

View file

@ -1 +0,0 @@
myfile

View file

@ -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}]}

View file

@ -1,10 +0,0 @@
#!/bin/sh
set -e
cd $1
git init
git config user.email "CI@example.com"
git config user.name "CI"

View file

@ -1 +0,0 @@
{ "description": "Invoke a custom command that creates a file, and then stage and commit that file", "speed": 5 }