Fix failing lib_test + add test for displaying the correct cwd in the table

This commit is contained in:
David Dworken 2022-04-18 22:45:07 -07:00
parent 76f12ab64a
commit d6a142dfe7
2 changed files with 32 additions and 1 deletions

View File

@ -773,6 +773,37 @@ func testTimestampsAreReasonablyCorrect(t *testing.T, tester shellTester) {
}
}
func testTableDisplayCwd(t *testing.T, tester shellTester) {
// Setup
defer shared.BackupAndRestore(t)()
installHishtory(t, tester, "")
// Record a command
out := tester.RunInteractiveShell(t, `cd ~/.hishtory/
echo hello
cd /tmp/
echo other`)
if out != "hello\nother\n" {
t.Fatalf("running echo hello had unexpected out=%#v", out)
}
// Query for it and check that the directory gets recorded correctly
out = hishtoryQuery(t, tester, "echo hello")
if strings.Count(out, "\n") != 2 {
t.Fatalf("hishtory query has unexpected number of lines: out=%#v", out)
}
if !strings.Contains(out, "~/.hishtory/") {
t.Fatalf("hishtory query has an incorrect CWD: out=%#v", out)
}
out = hishtoryQuery(t, tester, "echo other")
if strings.Count(out, "\n") != 2 {
t.Fatalf("hishtory query has unexpected number of lines: out=%#v", out)
}
if !strings.Contains(out, "/tmp/") {
t.Fatalf("hishtory query has an incorrect CWD: out=%#v", out)
}
}
func testHishtoryBackgroundSaving(t *testing.T, tester shellTester) {
// Setup
defer shared.BackupAndRestore(t)()

View File

@ -37,7 +37,7 @@ func TestBuildHistoryEntry(t *testing.T) {
shared.Check(t, Setup([]string{}))
// Test building an actual entry for bash
entry, err := BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "bash", "120", " 123 ls /foo ", "1641774958326745663"})
entry, err := BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "bash", "120", " 123 ls /foo ", "1641774958"})
shared.Check(t, err)
if entry.ExitCode != 120 {
t.Fatalf("history entry has unexpected exit code: %v", entry.ExitCode)