Make bash integration tests more robust on macOS

This commit is contained in:
Kovid Goyal 2024-01-24 23:07:38 +05:30
parent 1293ee60e0
commit fa11858a72
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 10 additions and 4 deletions

View file

@ -306,7 +306,7 @@ PS1="{ps1}"
self.ae(pty.screen_contents(), f'{ps1}printf "%s^G%s" "a" "b"\nab{ps1}')
self.assertTrue(pty.screen.last_reported_cwd.decode().endswith(self.home_dir))
pty.send_cmd_to_child('echo $HISTFILE')
pty.wait_till(lambda: '.bash_history' in pty.screen_contents())
pty.wait_till(lambda: '.bash_history' in pty.screen_contents().replace('\n', ''))
q = os.path.join(self.home_dir, 'testing-cwd-notification-🐱')
os.mkdir(q)
pty.send_cmd_to_child(f'cd {q}')

View file

@ -9,6 +9,7 @@ import (
"strings"
"kitty/tools/cli"
"kitty/tools/tty"
"kitty/tools/tui"
"kitty/tools/tui/shell_integration"
)
@ -68,6 +69,9 @@ func main(args []string, opts *Options) (rc int, err error) {
return
}
var debugprintln = tty.DebugPrintln
var _ = debugprintln
func EntryPoint(root *cli.Command) *cli.Command {
sc := root.AddSubCommand(&cli.Command{
Name: "run-shell",

View file

@ -163,7 +163,7 @@ func RunShell(shell_cmd []string, shell_integration_env_var_val, cwd string) (er
shell_env = env
}
exe := shell_cmd[0]
if runtime.GOOS == "darwin" {
if runtime.GOOS == "darwin" && os.Getenv("KITTY_RUNNING_BASH_INTEGRATION_TEST") != "" {
// ensure shell runs in login mode. On macOS lots of people use ~/.bash_profile instead of ~/.bashrc
// which means they expect the shell to run in login mode always. Le Sigh.
shell_cmd[0] = "-" + filepath.Base(shell_cmd[0])
@ -184,6 +184,9 @@ func RunShell(shell_cmd []string, shell_integration_env_var_val, cwd string) (er
return unix.Exec(utils.FindExe(exe), shell_cmd, env)
}
var debugprintln = tty.DebugPrintln
var _ = debugprintln
func RunCommandRestoringTerminalToSaneStateAfter(cmd []string) {
exe := utils.FindExe(cmd[0])
c := exec.Command(exe, cmd[1:]...)

View file

@ -328,8 +328,7 @@ func bash_setup_func(shell_integration_dir string, argv []string, env map[string
argv = slices.Insert(argv, 1, `--posix`)
if bashrc := os.Getenv(`KITTY_RUNNING_BASH_INTEGRATION_TEST`); bashrc != `` {
// prevent bash from source /etc/profile which is not under our control
os.Unsetenv(`KITTY_RUNNING_BASH_INTEGRATION_TEST`)
// prevent bash from sourcing /etc/profile which is not under our control
env[`KITTY_BASH_INJECT`] += ` posix`
env[`KITTY_BASH_POSIX_ENV`] = bashrc
}