From 865fa879fe84c0cef8b930d174037b08574c93ee Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sat, 22 Oct 2022 00:27:53 -0700 Subject: [PATCH] Add control-r tests for selecting and executing a command --- client/client_test.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index 098fdc1..fe602d7 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1667,7 +1667,7 @@ func TestTui(t *testing.T) { │ │ └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘` if diff := cmp.Diff(expected, out); diff != "" { - t.Fatalf("hishtory export mismatch (-expected +got):\n%s", diff) + t.Fatalf("hishtory tquery mismatch (-expected +got):\n%s", diff) } // Check the output when there is a search @@ -1703,7 +1703,7 @@ func TestTui(t *testing.T) { │ │ └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘` if diff := cmp.Diff(expected, out); diff != "" { - t.Fatalf("hishtory export mismatch (-expected +got):\n%s", diff) + t.Fatalf("hishtory tquery mismatch (-expected +got):\n%s", diff) } // Check the output when there is a selected result @@ -1797,7 +1797,19 @@ func testControlR(t *testing.T, tester shellTester) { │ │ └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘` if diff := cmp.Diff(expected, stripped); diff != "" { - t.Fatalf("hishtory export mismatch (-expected +got):\n%s \n(out=%#v)", diff, out) + t.Fatalf("hishtory tquery mismatch (-expected +got):\n%s \n(out=%#v)", diff, out) + } + + // And check that we can scroll down and select an option + out = captureTerminalOutput(t, tester, []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"}) + if !strings.Contains(out, "echo 'aaaaaa bbbb'\naaaaaa bbbb\n") { + t.Fatalf("hishtory tquery executed the wrong result, out=%#v", out) } }