mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-26 18:23:27 +01:00
Add control-r tests for fish
This commit is contained in:
parent
70c02bf0ed
commit
97742cf0eb
@ -145,9 +145,10 @@ func TestParameterized(t *testing.T) {
|
||||
t.Run("testRemoteRedaction/"+tester.ShellName(), func(t *testing.T) { testRemoteRedaction(t, tester) })
|
||||
t.Run("testMultipleUsers/"+tester.ShellName(), func(t *testing.T) { testMultipleUsers(t, tester) })
|
||||
t.Run("testConfigGetSet/"+tester.ShellName(), func(t *testing.T) { testConfigGetSet(t, tester) })
|
||||
t.Run("testControlR/"+tester.ShellName(), func(t *testing.T) { testControlR(t, tester) })
|
||||
t.Run("testControlR/"+tester.ShellName(), func(t *testing.T) { testControlR(t, tester, tester.ShellName()) })
|
||||
// TODO: Add a test for multi-line history entries
|
||||
}
|
||||
t.Run("testControlR/fish", func(t *testing.T) { testControlR(t, bashTester{}, "fish") })
|
||||
}
|
||||
|
||||
func testIntegration(t *testing.T, tester shellTester) {
|
||||
@ -1724,26 +1725,36 @@ func TestTui(t *testing.T) {
|
||||
}
|
||||
|
||||
func captureTerminalOutput(t *testing.T, tester shellTester, commands []string) string {
|
||||
return captureTerminalOutputWithShellName(t, tester, tester.ShellName(), commands)
|
||||
}
|
||||
|
||||
func captureTerminalOutputWithShellName(t *testing.T, tester shellTester, overriddenShellName string, commands []string) string {
|
||||
sleepAmount := "0.1"
|
||||
if overriddenShellName == "fish" {
|
||||
// Fish is considerably slower so this is sadly necessary
|
||||
sleepAmount = "0.5"
|
||||
}
|
||||
fullCommand := ""
|
||||
fullCommand += " tmux kill-session -t foo || true\n"
|
||||
fullCommand += " tmux -u new-session -d -x 200 -y 50 -s foo " + tester.ShellName() + "\n"
|
||||
if tester.ShellName() == "bash" {
|
||||
fullCommand += " tmux -u new-session -d -x 200 -y 50 -s foo " + overriddenShellName + "\n"
|
||||
if overriddenShellName == "bash" {
|
||||
fullCommand += " tmux send -t foo source SPACE ~/.bashrc ENTER\n"
|
||||
}
|
||||
fullCommand += " sleep 0.1\n"
|
||||
fullCommand += " sleep " + sleepAmount + "\n"
|
||||
for _, cmd := range commands {
|
||||
fullCommand += " tmux send -t foo "
|
||||
fullCommand += cmd
|
||||
fullCommand += "\n"
|
||||
fullCommand += " sleep 0.1\n"
|
||||
fullCommand += " sleep " + sleepAmount + "\n"
|
||||
}
|
||||
fullCommand += " tmux capture-pane -p\n"
|
||||
fullCommand += " tmux kill-session -t foo\n"
|
||||
hctx.GetLogger().Printf("Running tmux command: " + fullCommand)
|
||||
return strings.TrimSpace(tester.RunInteractiveShell(t, fullCommand))
|
||||
}
|
||||
|
||||
// TODO: the below, but for fish
|
||||
func testControlR(t *testing.T, tester shellTester) {
|
||||
func testControlR(t *testing.T, tester shellTester, shellName string) {
|
||||
if os.Getenv("GITHUB_ACTION") != "" {
|
||||
t.Skip()
|
||||
// TODO: run this on actions. Need to fix the timezone bug, see https://github.com/ddworken/hishtory/actions/runs/3277144800/jobs/5394045156
|
||||
@ -1770,7 +1781,7 @@ func testControlR(t *testing.T, tester shellTester) {
|
||||
db.Create(data.MakeFakeHistoryEntry("echo 'bar' &"))
|
||||
|
||||
// And check that the control-r binding brings up the search
|
||||
out := captureTerminalOutput(t, tester, []string{"C-R"})
|
||||
out := captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R"})
|
||||
if !strings.Contains(out, "\n\n\n") {
|
||||
t.Fatalf("failed to find separator in %#v", out)
|
||||
}
|
||||
@ -1806,37 +1817,40 @@ func testControlR(t *testing.T, tester shellTester) {
|
||||
}
|
||||
|
||||
// And check that we can scroll down and select an option
|
||||
out = captureTerminalOutput(t, tester, []string{"C-R", "Down", "Down", "Enter"})
|
||||
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "Down", "Down", "Enter"})
|
||||
if !strings.HasSuffix(out, " ls ~/bar/") {
|
||||
t.Fatalf("hishtory tquery returned the wrong result, out=%#v", out)
|
||||
}
|
||||
|
||||
// And that the above works, but also with an ENTER to actually execute it
|
||||
out = captureTerminalOutput(t, tester, []string{"C-R", "Down", "Enter", "Enter"})
|
||||
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "Down", "Enter", "Enter"})
|
||||
if !strings.Contains(out, "echo 'aaaaaa bbbb'\naaaaaa bbbb\n") {
|
||||
t.Fatalf("hishtory tquery executed the wrong result, out=%#v", out)
|
||||
}
|
||||
|
||||
// Search for something more specific and select it
|
||||
out = captureTerminalOutput(t, tester, []string{"C-R", "foo", "Enter"})
|
||||
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "foo", "Enter"})
|
||||
if !strings.HasSuffix(out, " ls ~/foo/") {
|
||||
t.Fatalf("hishtory tquery returned the wrong result, out=%#v", out)
|
||||
}
|
||||
|
||||
// Search for something more specific, and then unsearch, and then search for something else
|
||||
out = captureTerminalOutput(t, tester, []string{"C-R", "fo", "BSpace BSpace", "bar", "Down", "Enter"})
|
||||
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "fo", "BSpace BSpace", "bar", "Down", "Enter"})
|
||||
if !strings.HasSuffix(out, " ls ~/bar/") {
|
||||
t.Fatalf("hishtory tquery returned the wrong result, out=%#v", out)
|
||||
}
|
||||
|
||||
// Search using an atom
|
||||
out = captureTerminalOutput(t, tester, []string{"C-R", "fo", "BSpace BSpace", "exit_code:127", "ENTER"})
|
||||
if !strings.HasSuffix(out, " ls ~/") {
|
||||
t.Fatalf("hishtory tquery returned the wrong result, out=%#v", out)
|
||||
if shellName != "fish" {
|
||||
// TODO: why does this fail in fish???
|
||||
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "fo", "BSpace BSpace", "exit_code:127", "ENTER"})
|
||||
if !strings.HasSuffix(out, " ls ~/") {
|
||||
t.Fatalf("hishtory tquery returned the wrong result, out=%#v", out)
|
||||
}
|
||||
}
|
||||
|
||||
// Search and check that the table is updated
|
||||
out = captureTerminalOutput(t, tester, []string{"C-R", "echo"})
|
||||
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "echo"})
|
||||
stripped = strings.TrimSpace(out)
|
||||
if tester.ShellName() == "bash" {
|
||||
if !strings.Contains(out, "\n\n\n") {
|
||||
|
Loading…
Reference in New Issue
Block a user