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 beta' > $testroot/stdout.expected
30 (cd $testroot/wt && got rm beta > $testroot/stdout)
32 cmp -s $testroot/stdout.expected $testroot/stdout
34 if [ "$ret" != "0" ]; then
35 diff -u $testroot/stdout.expected $testroot/stdout
38 if [ -e $testroot/wt/beta ]; then
39 echo "removed file beta still exists on disk" >&2
40 test_done "$testroot" "1"
44 test_done "$testroot" "$ret"
47 function test_rm_with_local_mods {
48 local testroot=`test_init rm_with_local_mods`
50 got checkout $testroot/repo $testroot/wt > /dev/null
52 if [ "$ret" != "0" ]; then
53 test_done "$testroot" "$ret"
57 echo "modified beta" > $testroot/wt/beta
58 echo 'got: file contains modifications' > $testroot/stderr.expected
59 (cd $testroot/wt && got rm beta 2>$testroot/stderr)
61 cmp -s $testroot/stderr.expected $testroot/stderr
63 if [ "$ret" != "0" ]; then
64 diff -u $testroot/stderr.expected $testroot/stderr
65 test_done "$testroot" "$ret"
69 echo 'D beta' > $testroot/stdout.expected
70 (cd $testroot/wt && got rm -f beta > $testroot/stdout)
72 cmp -s $testroot/stdout.expected $testroot/stdout
74 if [ "$ret" != "0" ]; then
75 diff -u $testroot/stdout.expected $testroot/stdout
78 if [ -e $testroot/wt/beta ]; then
79 echo "removed file beta still exists on disk" >&2
80 test_done "$testroot" "1"
84 test_done "$testroot" "$ret"
87 function test_double_rm {
88 local testroot=`test_init double_rm`
90 got checkout $testroot/repo $testroot/wt > /dev/null
92 if [ "$ret" != "0" ]; then
93 test_done "$testroot" "$ret"
97 (cd $testroot/wt && got rm beta > /dev/null)
99 for fflag in "" "-f"; do
100 (cd $testroot/wt && got rm $fflag beta 2> $testroot/stderr)
102 if [ "$ret" == "0" ]; then
103 echo "got rm command succeeded unexpectedly" >&2
104 test_done "$testroot" 1
107 grep "No such file or directory" $testroot/stderr > \
108 $testroot/stderr.actual
110 if [ "$ret" != "0" ]; then
112 test_done "$testroot" "$ret"
115 test_done "$testroot" "0"
118 run_test test_rm_basic
119 run_test test_rm_with_local_mods
120 run_test test_double_rm