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