OILS / spec / builtin-history.test.sh View on Github | oilshell.org

196 lines, 73 significant
1## tags: interactive
2## compare_shells: bash
3
4#### history -a
5rm -f tmp
6
7echo '
8history -c
9
10HISTFILE=tmp
11echo 1
12history -a
13cat tmp
14
15echo 2
16
17cat tmp
18' | $SH -i
19
20# match osh's behaviour of echoing ^D for EOF
21case $SH in bash) echo '^D' ;; esac
22
23## STDOUT:
241
25HISTFILE=tmp
26echo 1
27history -a
282
29HISTFILE=tmp
30echo 1
31history -a
32^D
33## END
34
35#### history -r
36rm -f tmp
37echo 'foo' > tmp
38
39echo '
40history -c
41
42HISTFILE=tmp
43history -r
44history
45' | $SH -i
46
47# match osh's behaviour of echoing ^D for EOF
48case $SH in bash) echo '^D' ;; esac
49
50## STDOUT:
51 1 HISTFILE=tmp
52 2 history -r
53 3 foo
54 4 history
55^D
56## END
57
58#### HISTFILE is defined initially
59echo '
60if test -n $HISTFILE; then echo exists; fi
61' | $SH -i
62
63# match osh's behaviour of echoing ^D for EOF
64case $SH in bash) echo '^D' ;; esac
65
66## STDOUT:
67exists
68^D
69## END
70
71#### HISTFILE must point to a file
72
73rm -f _tmp/does-not-exist
74
75echo '
76HISTFILE=_tmp/does-not-exist
77history -r
78echo status=$?
79' | $SH -i
80
81# match osh's behaviour of echoing ^D for EOF
82case $SH in bash) echo '^D' ;; esac
83
84## STDOUT:
85status=1
86^D
87## END
88
89#### HISTFILE set to array
90
91echo '
92HISTFILE=(a b c)
93history -a
94echo status=$?
95' | $SH -i
96
97case $SH in bash) echo '^D' ;; esac
98
99# note that bash actually writes the file 'a', since that's ${HISTFILE[0]}
100
101## STDOUT:
102status=1
103^D
104## END
105
106## OK bash STDOUT:
107status=0
108^D
109## END
110
111#### HISTFILE unset
112
113echo '
114unset HISTFILE
115history -a
116echo status=$?
117' | $SH -i
118
119case $SH in bash) echo '^D' ;; esac
120
121## STDOUT:
122status=1
123^D
124## END
125
126
127#### history -d to delete history item
128
129rm -f myhist
130export HISTFILE=myhist
131
132$SH --norc -i <<'EOF'
133
134echo 42
135echo 43
136echo 44
137
138history -a
139
140history -d 1
141echo status=$?
142
143# Invalid integers
144history -d -1
145echo status=$?
146history -d -2
147echo status=$?
148history -d 99
149echo status=$?
150
151case $SH in bash) echo '^D' ;; esac
152
153EOF
154
155## STDOUT:
15642
15743
15844
159status=0
160status=2
161status=2
162status=2
163^D
164## END
165
166## OK bash STDOUT:
16742
16843
16944
170status=0
171status=1
172status=1
173status=1
174^D
175## END
176
177#### history usage
178
179history not-a-number
180echo status=$?
181
182history 3 too-many
183echo status=$?
184
185## STDOUT:
186status=2
187status=2
188## END
189
190## OK bash STDOUT:
191status=1
192status=1
193## END
194
195
196