fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Łukasz WieczorekReformat with black.82750bbae

master
3.3 KiB124 linesraw
1#!/usr/bin/env python3
2from pexpect_helper import SpawnedProc
3import os
4
5sp = SpawnedProc()
6send, sendline, sleep, expect_prompt, expect_re, expect_str = (
7    sp.send,
8    sp.sendline,
9    sp.sleep,
10    sp.expect_prompt,
11    sp.expect_re,
12    sp.expect_str,
13)
14
15# We're going to use three history files, including the default, to verify
16# that the fish_history variable works as expected.
17# (using as a relative path to avoid interpolating $XDG_DATA_HOME)
18default_histfile = "xdg_data_home/fish/fish_history"
19my_histfile = "xdg_data_home/fish/my_history"
20env_histfile = "xdg_data_home/fish/env_history"
21
22
23def grephistfile(line, file):
24    sendline("grep '^" + line + "' " + file)
25
26
27# Verify that if we spawn fish with no fish_history env var it uses the
28# default file.
29expect_prompt()
30
31# Verify that a command is recorded in the default history file.
32cmd1 = "echo $fish_pid default histfile"
33hist_line = "- cmd: " + cmd1
34sendline(cmd1)
35expect_prompt()
36
37# TODO: Figure out why this `history --save` is only needed in one of the
38# three Travis CI build environments and neither of my OS X or Ubuntu servers.
39sendline("history --save")
40expect_prompt()
41
42grephistfile(hist_line, default_histfile)
43expect_str(hist_line)
44expect_prompt()
45
46# Switch to a new history file and verify it is written to and the default
47# history file is not written to.
48cmd2 = "echo $fish_pid my histfile"
49hist_line = "- cmd: " + cmd2
50sendline("set fish_history my")
51expect_prompt()
52sendline(cmd2)
53expect_prompt()
54
55grephistfile(hist_line, my_histfile)
56expect_str(hist_line)
57expect_prompt()
58
59# We expect this grep to fail to find the pattern and thus the expect_prompt
60# block is inverted.
61grephistfile(hist_line, default_histfile)
62expect_prompt()
63
64# Switch back to the default history file.
65cmd3 = "echo $fish_pid default histfile again"
66hist_line = "- cmd: " + cmd3
67sendline("set fish_history default")
68expect_prompt()
69sendline(cmd3)
70expect_prompt()
71
72# TODO: Figure out why this `history --save` is only needed in one of the
73# three Travis CI build environments and neither of my OS X or Ubuntu servers.
74sendline("history --save")
75expect_prompt()
76
77grephistfile(hist_line, default_histfile)
78expect_str(hist_line)
79expect_prompt()
80
81# We expect this grep to fail to find the pattern and thus the expect_prompt
82# block is inverted.
83sendline("grep '^" + hist_line + "' " + my_histfile)
84expect_prompt()
85grephistfile(hist_line, my_histfile)
86expect_prompt()
87
88# Verify that if we spawn fish with a HISTFILE env var it uses that file.
89# Start by shutting down the previous shell.
90sendline("jobs")
91expect_prompt("jobs: There are no jobs")
92sendline("exit")
93sendline("exit")
94sp.spawn.wait()
95
96# Set the fish_history env var.
97os.environ["fish_history"] = "env"
98
99# Spawn a new shell.
100sp = SpawnedProc()
101send, sendline, sleep, expect_prompt, expect_re, expect_str = (
102    sp.send,
103    sp.sendline,
104    sp.sleep,
105    sp.expect_prompt,
106    sp.expect_re,
107    sp.expect_str,
108)
109expect_prompt()
110
111# Verify that the new fish shell is using the fish_history value for history.
112cmd4 = "echo $fish_pid env histfile"
113hist_line = "- cmd: " + cmd4
114sendline(cmd4)
115expect_prompt()
116
117grephistfile(hist_line, env_histfile)
118expect_str(hist_line)
119expect_prompt()
120
121# We expect this grep to fail to find the pattern and thus the expect_prompt
122# block is inverted.
123grephistfile(hist_line, default_histfile)
124expect_prompt()