3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 function test_rm_basic {
20 local testroot=`test_init rm_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
29 echo 'D alpha' > $testroot/stdout.expected
30 echo 'D beta' >> $testroot/stdout.expected
31 (cd $testroot/wt && got rm alpha beta > $testroot/stdout)
33 cmp -s $testroot/stdout.expected $testroot/stdout
35 if [ "$ret" != "0" ]; then
36 diff -u $testroot/stdout.expected $testroot/stdout
37 test_done "$testroot" "$ret"
41 (cd $testroot/wt && got status > $testroot/stdout)
43 cmp -s $testroot/stdout.expected $testroot/stdout
45 if [ "$ret" != "0" ]; then
46 diff -u $testroot/stdout.expected $testroot/stdout
47 test_done "$testroot" "$ret"
51 for f in alpha beta; do
52 if [ -e $testroot/wt/$f ]; then
53 echo "removed file $f still exists on disk" >&2
54 test_done "$testroot" "1"
59 test_done "$testroot" "0"
62 function test_rm_with_local_mods {
63 local testroot=`test_init rm_with_local_mods`
65 got checkout $testroot/repo $testroot/wt > /dev/null
67 if [ "$ret" != "0" ]; then
68 test_done "$testroot" "$ret"
72 echo "modified beta" > $testroot/wt/beta
73 echo 'got: beta: file contains modifications' \
74 > $testroot/stderr.expected
75 (cd $testroot/wt && got rm beta 2>$testroot/stderr)
77 cmp -s $testroot/stderr.expected $testroot/stderr
79 if [ "$ret" != "0" ]; then
80 diff -u $testroot/stderr.expected $testroot/stderr
81 test_done "$testroot" "$ret"
85 echo 'D beta' > $testroot/stdout.expected
86 (cd $testroot/wt && got rm -f beta > $testroot/stdout)
88 cmp -s $testroot/stdout.expected $testroot/stdout
90 if [ "$ret" != "0" ]; then
91 diff -u $testroot/stdout.expected $testroot/stdout
94 if [ -e $testroot/wt/beta ]; then
95 echo "removed file beta still exists on disk" >&2
96 test_done "$testroot" "1"
100 test_done "$testroot" "$ret"
103 function test_double_rm {
104 local testroot=`test_init double_rm`
106 got checkout $testroot/repo $testroot/wt > /dev/null
108 if [ "$ret" != "0" ]; then
109 test_done "$testroot" "$ret"
113 (cd $testroot/wt && got rm beta > /dev/null)
115 for fflag in "" "-f"; do
116 echo -n > $testroot/stderr.expected
117 (cd $testroot/wt && got rm $fflag beta > $testroot/stdout \
120 if [ "$ret" != "0" ]; then
121 echo "got rm command failed unexpectedly" >&2
122 diff -u $testroot/stderr.expected $testroot/stderr
123 test_done "$testroot" "$ret"
126 echo -n > $testroot/stdout.expected
127 cmp -s $testroot/stdout.expected $testroot/stdout
129 if [ "$ret" != "0" ]; then
130 diff -u $testroot/stdout.expected $testroot/stdout
131 test_done "$testroot" "$ret"
135 test_done "$testroot" "0"
138 function test_rm_and_add_elsewhere {
139 local testroot=`test_init rm_and_add_elsewhere`
141 got checkout $testroot/repo $testroot/wt > /dev/null
143 if [ "$ret" != "0" ]; then
144 test_done "$testroot" "$ret"
148 (cd $testroot/wt && mv alpha epsilon/)
150 (cd $testroot/wt && got status > $testroot/stdout)
152 echo '! alpha' > $testroot/stdout.expected
153 echo '? epsilon/alpha' >> $testroot/stdout.expected
154 cmp -s $testroot/stdout.expected $testroot/stdout
156 if [ "$ret" != "0" ]; then
157 diff -u $testroot/stdout.expected $testroot/stdout
158 test_done "$testroot" "$ret"
162 echo 'D alpha' > $testroot/stdout.expected
163 (cd $testroot/wt && got rm alpha > $testroot/stdout)
165 cmp -s $testroot/stdout.expected $testroot/stdout
167 if [ "$ret" != "0" ]; then
168 diff -u $testroot/stdout.expected $testroot/stdout
169 test_done "$testroot" "$ret"
173 echo 'A epsilon/alpha' > $testroot/stdout.expected
174 (cd $testroot/wt && got add epsilon/alpha > $testroot/stdout)
176 cmp -s $testroot/stdout.expected $testroot/stdout
178 if [ "$ret" != "0" ]; then
179 diff -u $testroot/stdout.expected $testroot/stdout
180 test_done "$testroot" "$ret"
184 (cd $testroot/wt && got status > $testroot/stdout)
186 echo 'D alpha' > $testroot/stdout.expected
187 echo 'A epsilon/alpha' >> $testroot/stdout.expected
188 cmp -s $testroot/stdout.expected $testroot/stdout
190 if [ "$ret" != "0" ]; then
191 diff -u $testroot/stdout.expected $testroot/stdout
193 test_done "$testroot" "$ret"
196 function test_rm_directory {
197 local testroot=`test_init rm_directory`
199 got checkout $testroot/repo $testroot/wt > /dev/null
201 if [ "$ret" != "0" ]; then
202 test_done "$testroot" "$ret"
206 (cd $testroot/wt && got rm . > $testroot/stdout 2> $testroot/stderr)
208 echo "got: removing directories requires -R option" \
209 > $testroot/stderr.expected
210 cmp -s $testroot/stderr.expected $testroot/stderr
212 if [ "$ret" != "0" ]; then
213 diff -u $testroot/stderr.expected $testroot/stderr
214 test_done "$testroot" "$ret"
218 echo -n > $testroot/stdout.expected
219 cmp -s $testroot/stdout.expected $testroot/stdout
221 if [ "$ret" != "0" ]; then
222 diff -u $testroot/stdout.expected $testroot/stdout
223 test_done "$testroot" "$ret"
227 (cd $testroot/wt && got rm -R . > $testroot/stdout)
229 echo 'D alpha' > $testroot/stdout.expected
230 echo 'D beta' >> $testroot/stdout.expected
231 echo 'D epsilon/zeta' >> $testroot/stdout.expected
232 echo 'D gamma/delta' >> $testroot/stdout.expected
234 cmp -s $testroot/stdout.expected $testroot/stdout
236 if [ "$ret" != "0" ]; then
237 diff -u $testroot/stdout.expected $testroot/stdout
238 test_done "$testroot" "$ret"
242 test_done "$testroot" "$ret"
245 function test_rm_directory_keep_files {
246 local testroot=`test_init rm_directory`
248 got checkout $testroot/repo $testroot/wt > /dev/null
250 if [ "$ret" != "0" ]; then
251 test_done "$testroot" "$ret"
255 (cd $testroot/wt && got rm . > $testroot/stdout 2> $testroot/stderr)
257 echo "got: removing directories requires -R option" \
258 > $testroot/stderr.expected
259 cmp -s $testroot/stderr.expected $testroot/stderr
261 if [ "$ret" != "0" ]; then
262 diff -u $testroot/stderr.expected $testroot/stderr
263 test_done "$testroot" "$ret"
267 echo -n > $testroot/stdout.expected
268 cmp -s $testroot/stdout.expected $testroot/stdout
270 if [ "$ret" != "0" ]; then
271 diff -u $testroot/stdout.expected $testroot/stdout
272 test_done "$testroot" "$ret"
276 (cd $testroot/wt && got rm -k -R . > $testroot/stdout)
278 echo 'D alpha' > $testroot/stdout.expected
279 echo 'D beta' >> $testroot/stdout.expected
280 echo 'D epsilon/zeta' >> $testroot/stdout.expected
281 echo 'D gamma/delta' >> $testroot/stdout.expected
283 cmp -s $testroot/stdout.expected $testroot/stdout
285 if [ "$ret" != "0" ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done "$testroot" "$ret"
291 (cd $testroot/wt && got st . > $testroot/stdout)
293 echo 'D alpha' > $testroot/stdout.expected
294 echo 'D beta' >> $testroot/stdout.expected
295 echo 'D epsilon/zeta' >> $testroot/stdout.expected
296 echo 'D gamma/delta' >> $testroot/stdout.expected
298 cmp -s $testroot/stdout.expected $testroot/stdout
300 if [ "$ret" != "0" ]; then
301 diff -u $testroot/stdout.expected $testroot/stdout
302 test_done "$testroot" "$ret"
306 (cd $testroot/wt && got commit -m "keep" > /dev/null)
307 (cd $testroot/wt && got st . > $testroot/stdout)
309 echo '? alpha' > $testroot/stdout.expected
310 echo '? beta' >> $testroot/stdout.expected
311 echo '? epsilon/zeta' >> $testroot/stdout.expected
312 echo '? gamma/delta' >> $testroot/stdout.expected
314 cmp -s $testroot/stdout.expected $testroot/stdout
316 if [ "$ret" != "0" ]; then
317 diff -u $testroot/stdout.expected $testroot/stdout
318 test_done "$testroot" "$ret"
322 test_done "$testroot" "$ret"
325 run_test test_rm_basic
326 run_test test_rm_with_local_mods
327 run_test test_double_rm
328 run_test test_rm_and_add_elsewhere
329 run_test test_rm_directory
330 run_test test_rm_directory_keep_files