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 beta' > $testroot/stdout.expected
30 (cd $testroot/wt && got rm beta > $testroot/stdout)
32 cmp $testroot/stdout.expected $testroot/stdout
33 ret="$?"
34 if [ "$ret" != "0" ]; then
35 diff -u $testroot/stdout.expected $testroot/stdout
36 fi
38 if [ -e $testroot/wt/beta ]; then
39 echo "removed file beta still exists on disk" >&2
40 test_done "$testroot" "1"
41 return 1
42 fi
44 test_done "$testroot" "$ret"
45 }
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
51 ret="$?"
52 if [ "$ret" != "0" ]; then
53 test_done "$testroot" "$ret"
54 return 1
55 fi
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 $testroot/stderr.expected $testroot/stderr
62 ret="$?"
63 if [ "$ret" != "0" ]; then
64 diff -u $testroot/stderr.expected $testroot/stderr
65 test_done "$testroot" "$ret"
66 return 1
67 fi
69 echo 'D beta' > $testroot/stdout.expected
70 (cd $testroot/wt && got rm -f beta > $testroot/stdout)
72 cmp $testroot/stdout.expected $testroot/stdout
73 ret="$?"
74 if [ "$ret" != "0" ]; then
75 diff -u $testroot/stdout.expected $testroot/stdout
76 fi
78 if [ -e $testroot/wt/beta ]; then
79 echo "removed file beta still exists on disk" >&2
80 test_done "$testroot" "1"
81 return 1
82 fi
84 test_done "$testroot" "$ret"
85 }
87 function test_double_rm {
88 local testroot=`test_init double_rm`
90 got checkout $testroot/repo $testroot/wt > /dev/null
91 ret="$?"
92 if [ "$ret" != "0" ]; then
93 test_done "$testroot" "$ret"
94 return 1
95 fi
97 (cd $testroot/wt && got rm beta > /dev/null)
99 for fflag in "" "-f"; do
100 echo "got: No such file or directory" > $testroot/stderr.expected
101 (cd $testroot/wt && got rm $fflag beta 2> $testroot/stderr)
102 ret="$?"
103 if [ "$ret" == "0" ]; then
104 echo "got rm command succeeded unexpectedly" >&2
105 test_done "$testroot" 1
106 fi
108 cmp $testroot/stderr.expected $testroot/stderr
109 ret="$?"
110 if [ "$ret" != "0" ]; then
111 diff -u $testroot/stderr.expected $testroot/stderr
112 test_done "$testroot" "$ret"
113 fi
114 done
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