mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-24 05:51:38 +02:00
Improve the zdotdir test
This commit is contained in:
parent
7b98f85bdb
commit
a269478273
@ -2231,19 +2231,27 @@ func TestZDotDir(t *testing.T) {
|
|||||||
defer testutils.BackupAndRestoreEnv("ZDOTDIR")()
|
defer testutils.BackupAndRestoreEnv("ZDOTDIR")()
|
||||||
homedir, err := os.UserHomeDir()
|
homedir, err := os.UserHomeDir()
|
||||||
testutils.Check(t, err)
|
testutils.Check(t, err)
|
||||||
os.Setenv("ZDOTDIR", path.Join(homedir, data.HISHTORY_PATH))
|
zdotdir := path.Join(homedir, "foo")
|
||||||
installHishtory(t, tester, "")
|
testutils.Check(t, os.MkdirAll(zdotdir, 0o744))
|
||||||
defer testutils.Check(t, os.Remove(path.Join(homedir, data.HISHTORY_PATH, ".zshrc")))
|
os.Setenv("ZDOTDIR", zdotdir)
|
||||||
|
userSecret := installHishtory(t, tester, "")
|
||||||
|
defer testutils.Check(t, os.Remove(path.Join(zdotdir, ".zshrc")))
|
||||||
|
|
||||||
|
// Check the status command
|
||||||
|
out := tester.RunInteractiveShell(t, `hishtory status`)
|
||||||
|
if out != fmt.Sprintf("hiSHtory: v0.Unknown\nEnabled: true\nSecret Key: %s\nCommit Hash: Unknown\n", userSecret) {
|
||||||
|
t.Fatalf("status command has unexpected output: %#v", out)
|
||||||
|
}
|
||||||
|
|
||||||
// Run a command and check that it was recorded
|
// Run a command and check that it was recorded
|
||||||
tester.RunInteractiveShell(t, `echo foo`)
|
tester.RunInteractiveShell(t, `echo foo`)
|
||||||
out := tester.RunInteractiveShell(t, `hishtory export -pipefail -install`)
|
out = tester.RunInteractiveShell(t, `hishtory export -pipefail -install`)
|
||||||
if out != "echo foo\n" {
|
if out != "echo foo\n" {
|
||||||
t.Fatalf("hishtory export had unexpected out=%#v", out)
|
t.Fatalf("hishtory export had unexpected out=%#v", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that hishtory respected ZDOTDIR
|
// Check that hishtory respected ZDOTDIR
|
||||||
zshrc, err := os.ReadFile(path.Join(homedir, data.HISHTORY_PATH, ".zshrc"))
|
zshrc, err := os.ReadFile(path.Join(zdotdir, ".zshrc"))
|
||||||
testutils.Check(t, err)
|
testutils.Check(t, err)
|
||||||
if !strings.Contains(string(zshrc), "# Hishtory Config:") {
|
if !strings.Contains(string(zshrc), "# Hishtory Config:") {
|
||||||
t.Fatalf("zshrc had unexpected contents=%#v", string(zshrc))
|
t.Fatalf("zshrc had unexpected contents=%#v", string(zshrc))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user