3 ## Test for tpwd script
4 ## Copyright (c) 2014 by Michal Nazareicz (mina86/AT/mina86.com)
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
19 ## This is part of Tiny Applications Collection
20 ## -> http://tinyapps.sourceforge.net/
26 self
="$PWD/tpwd-test.sh"
28 if ! [ -x "$self" ] ||
! [ -x "$tpwd" ]; then
29 echo "Expected $self and $tpwd to be executable." >&2
33 temp
=$
(mktemp
-d ||
exit 2)
34 trap 'rm -r -- "$temp"' 0
36 mkdir
"$temp/foobar" "$temp/foobar/baz"
41 echo >$temp/expected
'---------- >8 --------------------------------------------------
50 $ tpwd 5 ... 1 <.../qux
54 $ tpwd -n <~/foobar/qux> 0
56 $ tpwd -n 5 { <{/qux> 0
57 $ tpwd -n 5 ... 1 <.../qux> 0
58 $ tpwd -n 5 1 </qux> 0
59 $ tpwd -L <~/foobar/qux
65 $ tpwd -L 5 ... 1 <.../qux
69 $ tpwd -L -n <~/foobar/qux> 0
70 $ tpwd -L -n 5 <...ux> 0
71 $ tpwd -L -n 5 { <{/qux> 0
72 $ tpwd -L -n 5 ... 1 <.../qux> 0
73 $ tpwd -L -n 5 1 </qux> 0
74 $ tpwd -P <~/foobar/baz
80 $ tpwd -P 5 ... 1 <.../baz
84 $ tpwd -P -n <~/foobar/baz> 0
85 $ tpwd -P -n 5 <...az> 0
86 $ tpwd -P -n 5 { <{/baz> 0
87 $ tpwd -P -n 5 ... 1 <.../baz> 0
88 $ tpwd -P -n 5 1 </baz> 0
89 ---------- >8 --------------------------------------------------
92 $ tpwd <$HOME/foobar/qux
98 $ tpwd 5 ... 1 <.../qux
102 $ tpwd -n <$HOME/foobar/qux> 0
103 $ tpwd -n 5 <...ux> 0
104 $ tpwd -n 5 { <{/qux> 0
105 $ tpwd -n 5 ... 1 <.../qux> 0
106 $ tpwd -n 5 1 </qux> 0
107 $ tpwd -L <$HOME/foobar/qux
113 $ tpwd -L 5 ... 1 <.../qux
117 $ tpwd -L -n <$HOME/foobar/qux> 0
118 $ tpwd -L -n 5 <...ux> 0
119 $ tpwd -L -n 5 { <{/qux> 0
120 $ tpwd -L -n 5 ... 1 <.../qux> 0
121 $ tpwd -L -n 5 1 </qux> 0
122 $ tpwd -P <$HOME/foobar/baz
128 $ tpwd -P 5 ... 1 <.../baz
132 $ tpwd -P -n <$HOME/foobar/baz> 0
133 $ tpwd -P -n 5 <...az> 0
134 $ tpwd -P -n 5 { <{/baz> 0
135 $ tpwd -P -n 5 ... 1 <.../baz> 0
136 $ tpwd -P -n 5 1 </baz> 0
137 ---------- >8 --------------------------------------------------
146 $ tpwd 5 ... 1 <.../qux
150 $ tpwd -n <~/foobar/qux> 0
151 $ tpwd -n 5 <...ux> 0
152 $ tpwd -n 5 { <{/qux> 0
153 $ tpwd -n 5 ... 1 <.../qux> 0
154 $ tpwd -n 5 1 </qux> 0
155 $ tpwd -L <~/foobar/qux
161 $ tpwd -L 5 ... 1 <.../qux
165 $ tpwd -L -n <~/foobar/qux> 0
166 $ tpwd -L -n 5 <...ux> 0
167 $ tpwd -L -n 5 { <{/qux> 0
168 $ tpwd -L -n 5 ... 1 <.../qux> 0
169 $ tpwd -L -n 5 1 </qux> 0
170 $ tpwd -P <~/foobar/baz
176 $ tpwd -P 5 ... 1 <.../baz
180 $ tpwd -P -n <~/foobar/baz> 0
181 $ tpwd -P -n 5 <...az> 0
182 $ tpwd -P -n 5 { <{/baz> 0
183 $ tpwd -P -n 5 ... 1 <.../baz> 0
184 $ tpwd -P -n 5 1 </baz> 0
185 ---------- >8 --------------------------------------------------
188 $ tpwd <$temp/foobar/qux
194 $ tpwd 5 ... 1 <.../qux
198 $ tpwd -n <$temp/foobar/qux> 0
199 $ tpwd -n 5 <...ux> 0
200 $ tpwd -n 5 { <{/qux> 0
201 $ tpwd -n 5 ... 1 <.../qux> 0
202 $ tpwd -n 5 1 </qux> 0
203 $ tpwd -L <$temp/foobar/qux
209 $ tpwd -L 5 ... 1 <.../qux
213 $ tpwd -L -n <$temp/foobar/qux> 0
214 $ tpwd -L -n 5 <...ux> 0
215 $ tpwd -L -n 5 { <{/qux> 0
216 $ tpwd -L -n 5 ... 1 <.../qux> 0
217 $ tpwd -L -n 5 1 </qux> 0
218 $ tpwd -P <$temp/foobar/baz
224 $ tpwd -P 5 ... 1 <.../baz
228 $ tpwd -P -n <$temp/foobar/baz> 0
229 $ tpwd -P -n 5 <...az> 0
230 $ tpwd -P -n 5 { <{/baz> 0
231 $ tpwd -P -n 5 ... 1 <.../baz> 0
232 $ tpwd -P -n 5 1 </baz> 0
233 ---------- >8 --------------------------------------------------
234 TPWD_VARS=long_variable_name_which_is_hopefully_longer_than_length_of_temp:~
242 $ tpwd 5 ... 1 <.../qux
246 $ tpwd -n <~/foobar/qux> 0
247 $ tpwd -n 5 <...ux> 0
248 $ tpwd -n 5 { <{/qux> 0
249 $ tpwd -n 5 ... 1 <.../qux> 0
250 $ tpwd -n 5 1 </qux> 0
251 $ tpwd -L <~/foobar/qux
257 $ tpwd -L 5 ... 1 <.../qux
261 $ tpwd -L -n <~/foobar/qux> 0
262 $ tpwd -L -n 5 <...ux> 0
263 $ tpwd -L -n 5 { <{/qux> 0
264 $ tpwd -L -n 5 ... 1 <.../qux> 0
265 $ tpwd -L -n 5 1 </qux> 0
266 $ tpwd -P <~/foobar/baz
272 $ tpwd -P 5 ... 1 <.../baz
276 $ tpwd -P -n <~/foobar/baz> 0
277 $ tpwd -P -n 5 <...az> 0
278 $ tpwd -P -n 5 { <{/baz> 0
279 $ tpwd -P -n 5 ... 1 <.../baz> 0
280 $ tpwd -P -n 5 1 </baz> 0'
287 HOME
=$temp "$tpwd" "$@" || ec
=$?
291 long_variable_name_which_is_hopefully_longer_than_length_of_temp
=$temp
292 export long_variable_name_which_is_hopefully_longer_than_length_of_temp
294 for vars
in unset HOME
'~' temp long_variable_name_which_is_hopefully_longer_than_length_of_temp
:\~
; do
295 echo '---------- >8 --------------------------------------------------'
296 echo "TPWD_VARS=$vars"
298 if [ x
"$vars" = xunset
]; then
305 for lp in '' -L -P; do
317 if cmp -s "$temp/expected" "$temp/got"; then
320 tput setf
4; tput bold
; echo 'FAILED; got difference:'
321 diff -u "$temp/expected" "$temp/got"