1 | ## compare_shells: bash zsh
|
2 |
|
3 | # dash and mksh don't implement 'dirs'
|
4 |
|
5 | #### pushd/popd
|
6 | set -o errexit
|
7 | cd /
|
8 | pushd /tmp
|
9 | echo -n pwd=; pwd
|
10 | popd
|
11 | echo -n pwd=; pwd
|
12 | ## status: 0
|
13 | ## STDOUT:
|
14 | /tmp /
|
15 | pwd=/tmp
|
16 | /
|
17 | pwd=/
|
18 | ## END
|
19 | ## OK zsh STDOUT:
|
20 | pwd=/tmp
|
21 | pwd=/
|
22 | ## END
|
23 | ## N-I dash/mksh status: 127
|
24 | ## N-I dash/mksh stdout-json: ""
|
25 |
|
26 | #### pushd usage
|
27 | pushd -z
|
28 | echo status=$?
|
29 | pushd /tmp >/dev/null
|
30 | echo status=$?
|
31 | pushd -- /tmp >/dev/null
|
32 | echo status=$?
|
33 | ## STDOUT:
|
34 | status=2
|
35 | status=0
|
36 | status=0
|
37 | ## END
|
38 | ## OK zsh STDOUT:
|
39 | status=1
|
40 | status=0
|
41 | status=0
|
42 | ## END
|
43 |
|
44 | #### popd usage error
|
45 | pushd / >/dev/null
|
46 | popd zzz
|
47 | echo status=$?
|
48 |
|
49 | popd -- >/dev/null
|
50 | echo status=$?
|
51 |
|
52 | popd -z
|
53 | echo status=$?
|
54 | ## STDOUT:
|
55 | status=2
|
56 | status=0
|
57 | status=2
|
58 | ## END
|
59 | ## BUG zsh STDOUT:
|
60 | status=0
|
61 | status=0
|
62 | status=0
|
63 | ## END
|
64 |
|
65 | #### popd returns error on empty directory stack
|
66 | message=$(popd 2>&1)
|
67 | echo $?
|
68 | echo "$message" | grep -o "directory stack"
|
69 | ## STDOUT:
|
70 | 1
|
71 | directory stack
|
72 | ## END
|
73 |
|
74 | #### cd replaces the lowest entry on the directory stack!
|
75 |
|
76 | # stable temp dir
|
77 | dir=/tmp/oils-spec/builtin-dirs
|
78 |
|
79 | mkdir -p $dir
|
80 | cd $dir
|
81 |
|
82 | pushd /tmp >/dev/null
|
83 | echo pushd=$?
|
84 |
|
85 | dirs
|
86 |
|
87 | cd /
|
88 | echo cd=$?
|
89 |
|
90 | dirs
|
91 |
|
92 | popd >/dev/null
|
93 | echo popd=$?
|
94 |
|
95 | popd >/dev/null
|
96 | echo popd=$?
|
97 |
|
98 | ## STDOUT:
|
99 | pushd=0
|
100 | /tmp /tmp/oils-spec/builtin-dirs
|
101 | cd=0
|
102 | / /tmp/oils-spec/builtin-dirs
|
103 | popd=0
|
104 | popd=1
|
105 | ## END
|
106 |
|
107 | #### dirs builtin
|
108 | cd /
|
109 | dirs
|
110 | ## status: 0
|
111 | ## STDOUT:
|
112 | /
|
113 | ## END
|
114 |
|
115 | #### dirs -c to clear the stack
|
116 | set -o errexit
|
117 | cd /
|
118 | pushd /tmp >/dev/null # zsh pushd doesn't print anything, but bash does
|
119 | echo --
|
120 | dirs
|
121 | dirs -c
|
122 | echo --
|
123 | dirs
|
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
|
133 | set -o errexit
|
134 | cd /
|
135 | pushd /tmp >/dev/null
|
136 | echo --
|
137 | dirs -v
|
138 | pushd /dev >/dev/null
|
139 | echo --
|
140 | dirs -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
|
156 | set -o errexit
|
157 | cd /
|
158 | pushd /tmp >/dev/null
|
159 | echo --
|
160 | dirs -p
|
161 | pushd /dev >/dev/null
|
162 | echo --
|
163 | dirs -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.
|
177 | cd /
|
178 | HOME=/tmp
|
179 | mkdir -p $HOME/oil_test
|
180 | pushd $HOME/oil_test >/dev/null
|
181 | dirs
|
182 | dirs -l
|
183 | ## status: 0
|
184 | ## STDOUT:
|
185 | ~/oil_test /
|
186 | /tmp/oil_test /
|
187 | ## END
|
188 |
|
189 | #### dirs to print using tilde-prefix format
|
190 | cd /
|
191 | HOME=/tmp
|
192 | mkdir -p $HOME/oil_test
|
193 | pushd $HOME/oil_test >/dev/null
|
194 | dirs
|
195 | ## stdout: ~/oil_test /
|
196 | ## status: 0
|
197 |
|
198 | #### dirs test converting true home directory to tilde
|
199 | cd /
|
200 | HOME=/tmp
|
201 | mkdir -p $HOME/oil_test/$HOME
|
202 | pushd $HOME/oil_test/$HOME >/dev/null
|
203 | dirs
|
204 | ## stdout: ~/oil_test/tmp /
|
205 | ## status: 0
|
206 |
|
207 | #### dirs don't convert to tilde when $HOME is substring
|
208 | cd /
|
209 | mkdir -p /tmp/oil_test
|
210 | mkdir -p /tmp/oil_tests
|
211 | HOME=/tmp/oil_test
|
212 | pushd /tmp/oil_tests
|
213 | dirs
|
214 |
|
215 | #### dirs tilde test when $HOME is exactly $PWD
|
216 | cd /
|
217 | mkdir -p /tmp/oil_test
|
218 | HOME=/tmp/oil_test
|
219 | pushd $HOME
|
220 | dirs
|
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 `..`
|
230 | cd /tmp
|
231 | pushd .. >/dev/null
|
232 | dirs
|
233 | ## stdout: / /tmp
|
234 | ## status: 0
|
235 |
|
236 | #### dirs test of path alias `.`
|
237 | cd /tmp
|
238 | pushd . >/dev/null
|
239 | dirs
|
240 | ## stdout: /tmp /tmp
|
241 | ## status: 0
|