mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-22 00:03:58 +01:00
Add tests for fix for #238
This commit is contained in:
parent
f5d3899433
commit
5ea4fef6f6
@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
@ -3307,4 +3308,58 @@ func TestSanitizeEscapeCodes(t *testing.T) {
|
||||
require.Contains(t, out, "Search Query: >\n")
|
||||
}
|
||||
|
||||
func TestCreatedBashProfileSourcesProfile(t *testing.T) {
|
||||
if runtime.GOOS == "linux" {
|
||||
t.Skip("hishtory doesn't create .bash_profile on linux")
|
||||
}
|
||||
markTestForSharding(t, 18)
|
||||
defer testutils.BackupAndRestore(t)()
|
||||
tester := zshTester{}
|
||||
homedir, err := os.UserHomeDir()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Delete .bash_profile so hishtory will create a new one
|
||||
require.NoError(t, os.Remove(filepath.Join(homedir, ".bash_profile")))
|
||||
|
||||
// Install hishtory
|
||||
installHishtory(t, tester, "")
|
||||
|
||||
// Check that both files exist now
|
||||
require.FileExists(t, filepath.Join(homedir, ".bash_profile"))
|
||||
require.FileExists(t, filepath.Join(homedir, ".profile"))
|
||||
|
||||
// Check that .bash_profile sources .profile and that it contains the hishtory config
|
||||
bashProfileContent, err := os.ReadFile(filepath.Join(homedir, ".bash_profile"))
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, string(bashProfileContent), "source ~/.profile")
|
||||
require.Contains(t, string(bashProfileContent), "# Hishtory Config:\n")
|
||||
}
|
||||
|
||||
func TestExistingBashProfileDoesNotSourceProfile(t *testing.T) {
|
||||
if runtime.GOOS == "linux" {
|
||||
t.Skip("hishtory doesn't create .bash_profile on linux")
|
||||
}
|
||||
markTestForSharding(t, 18)
|
||||
defer testutils.BackupAndRestore(t)()
|
||||
tester := zshTester{}
|
||||
homedir, err := os.UserHomeDir()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Ensure .bash_profile exists so that hishtory doesn't create it
|
||||
require.FileExists(t, filepath.Join(homedir, ".bash_profile"))
|
||||
|
||||
// Install hishtory
|
||||
installHishtory(t, tester, "")
|
||||
|
||||
// Check that both files exist now
|
||||
require.FileExists(t, filepath.Join(homedir, ".bash_profile"))
|
||||
require.FileExists(t, filepath.Join(homedir, ".profile"))
|
||||
|
||||
// Check that .bash_profile does not source .profile and that it does contain the hishtory config
|
||||
bashProfileContent, err := os.ReadFile(filepath.Join(homedir, ".bash_profile"))
|
||||
require.NoError(t, err)
|
||||
require.NotContains(t, string(bashProfileContent), "source ~/.profile")
|
||||
require.Contains(t, string(bashProfileContent), "# Hishtory Config:\n")
|
||||
}
|
||||
|
||||
// TODO: somehow test/confirm that hishtory works even if only bash/only zsh is installed
|
||||
|
@ -99,6 +99,7 @@ func BackupAndRestoreWithId(t testing.TB, id string) func() {
|
||||
path.Join(homedir, ".zshrc"),
|
||||
path.Join(homedir, ".bashrc"),
|
||||
path.Join(homedir, ".bash_profile"),
|
||||
path.Join(homedir, ".profile"),
|
||||
}
|
||||
for _, file := range copyFiles {
|
||||
touchFile(file)
|
||||
|
Loading…
Reference in New Issue
Block a user