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

238 lines, 143 significant
1
2#### pushd/popd
3set -o errexit
4cd /
5pushd /tmp
6echo -n pwd=; pwd
7popd
8echo -n pwd=; pwd
9## status: 0
10## STDOUT:
11/tmp /
12pwd=/tmp
13/
14pwd=/
15## END
16## OK zsh STDOUT:
17pwd=/tmp
18pwd=/
19## END
20## N-I dash/mksh status: 127
21## N-I dash/mksh stdout-json: ""
22
23#### pushd usage
24pushd -z
25echo status=$?
26pushd /tmp >/dev/null
27echo status=$?
28pushd -- /tmp >/dev/null
29echo status=$?
30## STDOUT:
31status=2
32status=0
33status=0
34## END
35## OK zsh STDOUT:
36status=1
37status=0
38status=0
39## END
40
41#### popd usage error
42pushd / >/dev/null
43popd zzz
44echo status=$?
45
46popd -- >/dev/null
47echo status=$?
48
49popd -z
50echo status=$?
51## STDOUT:
52status=2
53status=0
54status=2
55## END
56## BUG zsh STDOUT:
57status=0
58status=0
59status=0
60## END
61
62#### popd returns error on empty directory stack
63message=$(popd 2>&1)
64echo $?
65echo "$message" | grep -o "directory stack"
66## STDOUT:
671
68directory stack
69## END
70
71#### cd replaces the lowest entry on the directory stack!
72
73# stable temp dir
74dir=/tmp/oils-spec/builtin-dirs
75
76mkdir -p $dir
77cd $dir
78
79pushd /tmp >/dev/null
80echo pushd=$?
81
82dirs
83
84cd /
85echo cd=$?
86
87dirs
88
89popd >/dev/null
90echo popd=$?
91
92popd >/dev/null
93echo popd=$?
94
95## STDOUT:
96pushd=0
97/tmp /tmp/oils-spec/builtin-dirs
98cd=0
99/ /tmp/oils-spec/builtin-dirs
100popd=0
101popd=1
102## END
103
104#### dirs builtin
105cd /
106dirs
107## status: 0
108## STDOUT:
109/
110## END
111
112#### dirs -c to clear the stack
113set -o errexit
114cd /
115pushd /tmp >/dev/null # zsh pushd doesn't print anything, but bash does
116echo --
117dirs
118dirs -c
119echo --
120dirs
121## status: 0
122## STDOUT:
123--
124/tmp /
125--
126/tmp
127## END
128
129#### dirs -v to print numbered stack, one entry per line
130set -o errexit
131cd /
132pushd /tmp >/dev/null
133echo --
134dirs -v
135pushd /dev >/dev/null
136echo --
137dirs -v
138## status: 0
139## STDOUT:
140--
141 0 /tmp
142 1 /
143--
144 0 /dev
145 1 /tmp
146 2 /
147## END
148#
149# zsh uses tabs
150## OK zsh stdout-json: "--\n0\t/tmp\n1\t/\n--\n0\t/dev\n1\t/tmp\n2\t/\n"
151
152#### dirs -p to print one entry per line
153set -o errexit
154cd /
155pushd /tmp >/dev/null
156echo --
157dirs -p
158pushd /dev >/dev/null
159echo --
160dirs -p
161## STDOUT:
162--
163/tmp
164/
165--
166/dev
167/tmp
168/
169## END
170
171#### dirs -l to print in long format, no tilde prefix
172# Can't use the OSH test harness for this because
173# /home/<username> may be included in a path.
174cd /
175HOME=/tmp
176mkdir -p $HOME/oil_test
177pushd $HOME/oil_test >/dev/null
178dirs
179dirs -l
180## status: 0
181## STDOUT:
182~/oil_test /
183/tmp/oil_test /
184## END
185
186#### dirs to print using tilde-prefix format
187cd /
188HOME=/tmp
189mkdir -p $HOME/oil_test
190pushd $HOME/oil_test >/dev/null
191dirs
192## stdout: ~/oil_test /
193## status: 0
194
195#### dirs test converting true home directory to tilde
196cd /
197HOME=/tmp
198mkdir -p $HOME/oil_test/$HOME
199pushd $HOME/oil_test/$HOME >/dev/null
200dirs
201## stdout: ~/oil_test/tmp /
202## status: 0
203
204#### dirs don't convert to tilde when $HOME is substring
205cd /
206mkdir -p /tmp/oil_test
207mkdir -p /tmp/oil_tests
208HOME=/tmp/oil_test
209pushd /tmp/oil_tests
210dirs
211
212#### dirs tilde test when $HOME is exactly $PWD
213cd /
214mkdir -p /tmp/oil_test
215HOME=/tmp/oil_test
216pushd $HOME
217dirs
218## status: 0
219# zsh doesn't duplicate the stack I guess.
220## OK zsh stdout-json: "~ /\n"
221## STDOUT:
222~ /
223~ /
224## END
225
226#### dirs test of path alias `..`
227cd /tmp
228pushd .. >/dev/null
229dirs
230## stdout: / /tmp
231## status: 0
232
233#### dirs test of path alias `.`
234cd /tmp
235pushd . >/dev/null
236dirs
237## stdout: /tmp /tmp
238## status: 0