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

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