mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 14:03:58 +00:00
Port histfile test to pexpect
This commit is contained in:
parent
25a73a77bb
commit
51e3258dbe
5 changed files with 119 additions and 133 deletions
|
@ -1,125 +0,0 @@
|
|||
# vim: set filetype=expect:
|
||||
# We're going to use three history files, including the default, to verify
|
||||
# that the fish_history variable works as expected.
|
||||
set default_histfile "../test/data/fish/fish_history"
|
||||
set my_histfile "../test/data/fish/my_history"
|
||||
set env_histfile "../test/data/fish/env_history"
|
||||
|
||||
# =============
|
||||
# Verify that if we spawn fish with no fish_history env var it uses the
|
||||
# default file.
|
||||
# =============
|
||||
set fish_pid [spawn $fish]
|
||||
expect_prompt
|
||||
|
||||
# Verify that a command is recorded in the default history file.
|
||||
set cmd1 "echo $fish_pid default histfile"
|
||||
set hist_line "- cmd: $cmd1"
|
||||
send "$cmd1\r"
|
||||
expect_prompt
|
||||
|
||||
# TODO: Figure out why this `history --save` is only needed in one of the
|
||||
# three Travis CI build environments and neither of my OS X or Ubuntu servers.
|
||||
send "history --save\r"
|
||||
expect_prompt
|
||||
|
||||
send "grep '^$hist_line' $default_histfile\r"
|
||||
expect_prompt -re "\r\n$hist_line\r\n" {
|
||||
puts "cmd1 found in default histfile"
|
||||
} unmatched {
|
||||
puts stderr "cmd1 not found in default histfile"
|
||||
}
|
||||
|
||||
# Switch to a new history file and verify it is written to and the default
|
||||
# history file is not written to.
|
||||
set cmd2 "echo $fish_pid my histfile"
|
||||
set hist_line "- cmd: $cmd2"
|
||||
send "set fish_history my\r"
|
||||
expect_prompt
|
||||
send "$cmd2\r"
|
||||
expect_prompt
|
||||
|
||||
send "grep '^$hist_line' $my_histfile\r"
|
||||
expect_prompt -re "\r\n$hist_line\r\n" {
|
||||
puts "cmd2 found in my histfile"
|
||||
} unmatched {
|
||||
puts stderr "cmd2 not found in my histfile"
|
||||
}
|
||||
# We expect this grep to fail to find the pattern and thus the expect_prompt
|
||||
# block is inverted.
|
||||
send "grep '^$hist_line' $default_histfile\r"
|
||||
expect_prompt -re "\r\n$hist_line\r\n" {
|
||||
puts stderr "cmd2 found in default histfile"
|
||||
} unmatched {
|
||||
puts "cmd2 not found in default histfile"
|
||||
}
|
||||
|
||||
# Switch back to the default history file.
|
||||
set cmd3 "echo $fish_pid default histfile again"
|
||||
set hist_line "- cmd: $cmd3"
|
||||
send "set fish_history default\r"
|
||||
expect_prompt
|
||||
send "$cmd3\r"
|
||||
expect_prompt
|
||||
|
||||
# TODO: Figure out why this `history --save` is only needed in one of the
|
||||
# three Travis CI build environments and neither of my OS X or Ubuntu servers.
|
||||
send "history --save\r"
|
||||
expect_prompt
|
||||
|
||||
send "grep '^$hist_line' $default_histfile\r"
|
||||
expect_prompt -re "\r\n$hist_line\r\n" {
|
||||
puts "cmd3 found in default histfile"
|
||||
} unmatched {
|
||||
puts stderr "cmd3 not found in default histfile"
|
||||
}
|
||||
# We expect this grep to fail to find the pattern and thus the expect_prompt
|
||||
# block is inverted.
|
||||
send "grep '^$hist_line' $my_histfile\r"
|
||||
expect_prompt -re "\r\n$hist_line\r\n" {
|
||||
puts stderr "cmd3 found in my histfile"
|
||||
} unmatched {
|
||||
puts "cmd3 not found in my histfile"
|
||||
}
|
||||
|
||||
# =============
|
||||
# Verify that if we spawn fish with a HISTFILE env var it uses that file.
|
||||
# =============
|
||||
# Start by shutting down the previous shell.
|
||||
send "exit\r"
|
||||
expect eof
|
||||
wait
|
||||
|
||||
# Set the fish_history env var.
|
||||
set ::env(fish_history) env
|
||||
|
||||
# Spawn a new shell.
|
||||
set prompt_counter 1
|
||||
set fish_pid [spawn $fish]
|
||||
expect_prompt
|
||||
|
||||
# Verify that the new fish shell is using the fish_history value for history.
|
||||
set cmd4 "echo $fish_pid env histfile"
|
||||
set hist_line "- cmd: $cmd4"
|
||||
send "$cmd4\r"
|
||||
expect_prompt
|
||||
|
||||
# TODO: Figure out why this `history --save` is only needed in one of the
|
||||
# three Travis CI build environments and neither of my OS X or Ubuntu servers.
|
||||
# send "history --save\r"
|
||||
# expect_prompt
|
||||
|
||||
send "grep '^$hist_line' $env_histfile\r"
|
||||
expect_prompt -re "\r\n$hist_line\r\n" {
|
||||
puts "cmd4 found in env histfile"
|
||||
} unmatched {
|
||||
puts stderr "cmd4 not found in env histfile"
|
||||
}
|
||||
# We expect this grep to fail to find the pattern and thus the expect_prompt
|
||||
# block is inverted.
|
||||
send "grep '^$hist_line' $default_histfile\r"
|
||||
expect_prompt -re "\r\n$hist_line\r\n" {
|
||||
puts stderr "cmd4 found in default histfile"
|
||||
} unmatched {
|
||||
puts "cmd4 not found in default histfile"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
cmd1 found in default histfile
|
||||
cmd2 found in my histfile
|
||||
cmd2 not found in default histfile
|
||||
cmd3 found in default histfile
|
||||
cmd3 not found in my histfile
|
||||
cmd4 found in env histfile
|
||||
cmd4 not found in default histfile
|
|
@ -1 +0,0 @@
|
|||
0
|
119
tests/pexpects/histfile.py
Normal file
119
tests/pexpects/histfile.py
Normal file
|
@ -0,0 +1,119 @@
|
|||
#!/usr/bin/env python3
|
||||
from pexpect_helper import SpawnedProc
|
||||
import os
|
||||
|
||||
sp = SpawnedProc()
|
||||
send, sendline, sleep, expect_prompt, expect_re, expect_str = (
|
||||
sp.send,
|
||||
sp.sendline,
|
||||
sp.sleep,
|
||||
sp.expect_prompt,
|
||||
sp.expect_re,
|
||||
sp.expect_str,
|
||||
)
|
||||
expect_prompt()
|
||||
|
||||
# We're going to use three history files, including the default, to verify
|
||||
# that the fish_history variable works as expected.
|
||||
default_histfile="../test/data/fish/fish_history"
|
||||
my_histfile="../test/data/fish/my_history"
|
||||
env_histfile="../test/data/fish/env_history"
|
||||
|
||||
def grephistfile(line, file):
|
||||
sendline("grep '^" + line + "' " + file)
|
||||
|
||||
# Verify that if we spawn fish with no fish_history env var it uses the
|
||||
# default file.
|
||||
expect_prompt
|
||||
|
||||
# Verify that a command is recorded in the default history file.
|
||||
cmd1="echo $fish_pid default histfile"
|
||||
hist_line="- cmd: " + cmd1
|
||||
sendline(cmd1)
|
||||
expect_prompt()
|
||||
|
||||
# TODO: Figure out why this `history --save` is only needed in one of the
|
||||
# three Travis CI build environments and neither of my OS X or Ubuntu servers.
|
||||
sendline("history --save")
|
||||
expect_prompt()
|
||||
|
||||
grephistfile(hist_line, default_histfile)
|
||||
expect_str(hist_line)
|
||||
expect_prompt()
|
||||
|
||||
# Switch to a new history file and verify it is written to and the default
|
||||
# history file is not written to.
|
||||
cmd2="echo $fish_pid my histfile"
|
||||
hist_line="- cmd: " + cmd2
|
||||
sendline("set fish_history my")
|
||||
expect_prompt()
|
||||
sendline(cmd2)
|
||||
expect_prompt()
|
||||
|
||||
grephistfile(hist_line, my_histfile)
|
||||
expect_str(hist_line)
|
||||
expect_prompt()
|
||||
|
||||
# We expect this grep to fail to find the pattern and thus the expect_prompt
|
||||
# block is inverted.
|
||||
grephistfile(hist_line, default_histfile)
|
||||
expect_prompt()
|
||||
|
||||
# Switch back to the default history file.
|
||||
cmd3="echo $fish_pid default histfile again"
|
||||
hist_line="- cmd: " + cmd3
|
||||
sendline("set fish_history default")
|
||||
expect_prompt()
|
||||
sendline(cmd3)
|
||||
expect_prompt()
|
||||
|
||||
# TODO: Figure out why this `history --save` is only needed in one of the
|
||||
# three Travis CI build environments and neither of my OS X or Ubuntu servers.
|
||||
sendline("history --save")
|
||||
expect_prompt()
|
||||
|
||||
grephistfile(hist_line, default_histfile)
|
||||
expect_str(hist_line)
|
||||
expect_prompt()
|
||||
|
||||
# We expect this grep to fail to find the pattern and thus the expect_prompt
|
||||
# block is inverted.
|
||||
sendline("grep '^" + hist_line + "' " + my_histfile)
|
||||
grephistfile(hist_line, my_histfile)
|
||||
expect_prompt()
|
||||
|
||||
# Verify that if we spawn fish with a HISTFILE env var it uses that file.
|
||||
# Start by shutting down the previous shell.
|
||||
sendline("exit")
|
||||
sp.spawn.wait()
|
||||
|
||||
# Set the fish_history env var.
|
||||
os.environ["fish_history"] = 'env'
|
||||
|
||||
# Spawn a new shell.
|
||||
sp = SpawnedProc()
|
||||
send, sendline, sleep, expect_prompt, expect_re, expect_str = (
|
||||
sp.send,
|
||||
sp.sendline,
|
||||
sp.sleep,
|
||||
sp.expect_prompt,
|
||||
sp.expect_re,
|
||||
sp.expect_str,
|
||||
)
|
||||
expect_prompt()
|
||||
|
||||
# Verify that the new fish shell is using the fish_history value for history.
|
||||
cmd4="echo $fish_pid env histfile"
|
||||
hist_line="- cmd: " + cmd4
|
||||
sendline(cmd4)
|
||||
expect_prompt()
|
||||
|
||||
grephistfile(hist_line, env_histfile)
|
||||
expect_str(hist_line)
|
||||
expect_prompt()
|
||||
|
||||
# We expect this grep to fail to find the pattern and thus the expect_prompt
|
||||
# block is inverted.
|
||||
grephistfile(hist_line, default_histfile)
|
||||
expect_prompt()
|
||||
|
Loading…
Reference in a new issue