Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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.
17 . ./common.sh
19 function test_rm_basic {
20 local testroot=`test_init rm_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
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
34 ret="$?"
35 if [ "$ret" != "0" ]; then
36 diff -u $testroot/stdout.expected $testroot/stdout
37 test_done "$testroot" "$ret"
38 return 1
39 fi
41 (cd $testroot/wt && got status > $testroot/stdout)
43 cmp -s $testroot/stdout.expected $testroot/stdout
44 ret="$?"
45 if [ "$ret" != "0" ]; then
46 diff -u $testroot/stdout.expected $testroot/stdout
47 test_done "$testroot" "$ret"
48 return 1
49 fi
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"
55 return 1
56 fi
57 done
59 test_done "$testroot" "0"
60 }
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
66 ret="$?"
67 if [ "$ret" != "0" ]; then
68 test_done "$testroot" "$ret"
69 return 1
70 fi
72 echo "modified beta" > $testroot/wt/beta
73 echo 'got: file contains modifications' > $testroot/stderr.expected
74 (cd $testroot/wt && got rm beta 2>$testroot/stderr)
76 cmp -s $testroot/stderr.expected $testroot/stderr
77 ret="$?"
78 if [ "$ret" != "0" ]; then
79 diff -u $testroot/stderr.expected $testroot/stderr
80 test_done "$testroot" "$ret"
81 return 1
82 fi
84 echo 'D beta' > $testroot/stdout.expected
85 (cd $testroot/wt && got rm -f beta > $testroot/stdout)
87 cmp -s $testroot/stdout.expected $testroot/stdout
88 ret="$?"
89 if [ "$ret" != "0" ]; then
90 diff -u $testroot/stdout.expected $testroot/stdout
91 fi
93 if [ -e $testroot/wt/beta ]; then
94 echo "removed file beta still exists on disk" >&2
95 test_done "$testroot" "1"
96 return 1
97 fi
99 test_done "$testroot" "$ret"
102 function test_double_rm {
103 local testroot=`test_init double_rm`
105 got checkout $testroot/repo $testroot/wt > /dev/null
106 ret="$?"
107 if [ "$ret" != "0" ]; then
108 test_done "$testroot" "$ret"
109 return 1
110 fi
112 (cd $testroot/wt && got rm beta > /dev/null)
114 for fflag in "" "-f"; do
115 (cd $testroot/wt && got rm $fflag beta 2> $testroot/stderr)
116 ret="$?"
117 if [ "$ret" == "0" ]; then
118 echo "got rm command succeeded unexpectedly" >&2
119 test_done "$testroot" 1
120 fi
122 grep "No such file or directory" $testroot/stderr > \
123 $testroot/stderr.actual
124 ret="$?"
125 if [ "$ret" != "0" ]; then
126 cat $testroot/stderr
127 test_done "$testroot" "$ret"
128 fi
129 done
130 test_done "$testroot" "0"
133 run_test test_rm_basic
134 run_test test_rm_with_local_mods
135 run_test test_double_rm