Blame


1 2ec1f75b 2019-03-26 stsp #!/bin/sh
2 2ec1f75b 2019-03-26 stsp #
3 2ec1f75b 2019-03-26 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 2ec1f75b 2019-03-26 stsp #
5 2ec1f75b 2019-03-26 stsp # Permission to use, copy, modify, and distribute this software for any
6 2ec1f75b 2019-03-26 stsp # purpose with or without fee is hereby granted, provided that the above
7 2ec1f75b 2019-03-26 stsp # copyright notice and this permission notice appear in all copies.
8 2ec1f75b 2019-03-26 stsp #
9 2ec1f75b 2019-03-26 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 2ec1f75b 2019-03-26 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 2ec1f75b 2019-03-26 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 2ec1f75b 2019-03-26 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 2ec1f75b 2019-03-26 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 2ec1f75b 2019-03-26 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 2ec1f75b 2019-03-26 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 2ec1f75b 2019-03-26 stsp
17 2ec1f75b 2019-03-26 stsp . ./common.sh
18 2ec1f75b 2019-03-26 stsp
19 2ec1f75b 2019-03-26 stsp function test_rm_basic {
20 2ec1f75b 2019-03-26 stsp local testroot=`test_init rm_basic`
21 2ec1f75b 2019-03-26 stsp
22 2ec1f75b 2019-03-26 stsp got checkout $testroot/repo $testroot/wt > /dev/null
23 2ec1f75b 2019-03-26 stsp ret="$?"
24 2ec1f75b 2019-03-26 stsp if [ "$ret" != "0" ]; then
25 2ec1f75b 2019-03-26 stsp test_done "$testroot" "$ret"
26 2ec1f75b 2019-03-26 stsp return 1
27 2ec1f75b 2019-03-26 stsp fi
28 2ec1f75b 2019-03-26 stsp
29 17ed4618 2019-06-02 stsp echo 'D alpha' > $testroot/stdout.expected
30 17ed4618 2019-06-02 stsp echo 'D beta' >> $testroot/stdout.expected
31 17ed4618 2019-06-02 stsp (cd $testroot/wt && got rm alpha beta > $testroot/stdout)
32 2ec1f75b 2019-03-26 stsp
33 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
34 2ec1f75b 2019-03-26 stsp ret="$?"
35 2ec1f75b 2019-03-26 stsp if [ "$ret" != "0" ]; then
36 2ec1f75b 2019-03-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
37 17ed4618 2019-06-02 stsp test_done "$testroot" "$ret"
38 17ed4618 2019-06-02 stsp return 1
39 2ec1f75b 2019-03-26 stsp fi
40 2ec1f75b 2019-03-26 stsp
41 17ed4618 2019-06-02 stsp (cd $testroot/wt && got status > $testroot/stdout)
42 17ed4618 2019-06-02 stsp
43 17ed4618 2019-06-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
44 17ed4618 2019-06-02 stsp ret="$?"
45 17ed4618 2019-06-02 stsp if [ "$ret" != "0" ]; then
46 17ed4618 2019-06-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
47 17ed4618 2019-06-02 stsp test_done "$testroot" "$ret"
48 2ec1f75b 2019-03-26 stsp return 1
49 2ec1f75b 2019-03-26 stsp fi
50 2ec1f75b 2019-03-26 stsp
51 17ed4618 2019-06-02 stsp for f in alpha beta; do
52 17ed4618 2019-06-02 stsp if [ -e $testroot/wt/$f ]; then
53 17ed4618 2019-06-02 stsp echo "removed file $f still exists on disk" >&2
54 17ed4618 2019-06-02 stsp test_done "$testroot" "1"
55 17ed4618 2019-06-02 stsp return 1
56 17ed4618 2019-06-02 stsp fi
57 17ed4618 2019-06-02 stsp done
58 17ed4618 2019-06-02 stsp
59 17ed4618 2019-06-02 stsp test_done "$testroot" "0"
60 2ec1f75b 2019-03-26 stsp }
61 2ec1f75b 2019-03-26 stsp
62 2ec1f75b 2019-03-26 stsp function test_rm_with_local_mods {
63 2ec1f75b 2019-03-26 stsp local testroot=`test_init rm_with_local_mods`
64 2ec1f75b 2019-03-26 stsp
65 2ec1f75b 2019-03-26 stsp got checkout $testroot/repo $testroot/wt > /dev/null
66 2ec1f75b 2019-03-26 stsp ret="$?"
67 2ec1f75b 2019-03-26 stsp if [ "$ret" != "0" ]; then
68 2ec1f75b 2019-03-26 stsp test_done "$testroot" "$ret"
69 2ec1f75b 2019-03-26 stsp return 1
70 2ec1f75b 2019-03-26 stsp fi
71 2ec1f75b 2019-03-26 stsp
72 2ec1f75b 2019-03-26 stsp echo "modified beta" > $testroot/wt/beta
73 f0b0c0ce 2019-08-04 stsp echo 'got: beta: file contains modifications' \
74 f0b0c0ce 2019-08-04 stsp > $testroot/stderr.expected
75 2ec1f75b 2019-03-26 stsp (cd $testroot/wt && got rm beta 2>$testroot/stderr)
76 2ec1f75b 2019-03-26 stsp
77 8d301dd9 2019-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
78 2ec1f75b 2019-03-26 stsp ret="$?"
79 2ec1f75b 2019-03-26 stsp if [ "$ret" != "0" ]; then
80 2ec1f75b 2019-03-26 stsp diff -u $testroot/stderr.expected $testroot/stderr
81 2ec1f75b 2019-03-26 stsp test_done "$testroot" "$ret"
82 2ec1f75b 2019-03-26 stsp return 1
83 2ec1f75b 2019-03-26 stsp fi
84 2ec1f75b 2019-03-26 stsp
85 2ec1f75b 2019-03-26 stsp echo 'D beta' > $testroot/stdout.expected
86 2ec1f75b 2019-03-26 stsp (cd $testroot/wt && got rm -f beta > $testroot/stdout)
87 2ec1f75b 2019-03-26 stsp
88 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
89 2ec1f75b 2019-03-26 stsp ret="$?"
90 2ec1f75b 2019-03-26 stsp if [ "$ret" != "0" ]; then
91 2ec1f75b 2019-03-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
92 2ec1f75b 2019-03-26 stsp fi
93 2ec1f75b 2019-03-26 stsp
94 2ec1f75b 2019-03-26 stsp if [ -e $testroot/wt/beta ]; then
95 2ec1f75b 2019-03-26 stsp echo "removed file beta still exists on disk" >&2
96 2ec1f75b 2019-03-26 stsp test_done "$testroot" "1"
97 2ec1f75b 2019-03-26 stsp return 1
98 2ec1f75b 2019-03-26 stsp fi
99 2ec1f75b 2019-03-26 stsp
100 2ec1f75b 2019-03-26 stsp test_done "$testroot" "$ret"
101 2ec1f75b 2019-03-26 stsp }
102 2ec1f75b 2019-03-26 stsp
103 71a29355 2019-03-27 stsp function test_double_rm {
104 71a29355 2019-03-27 stsp local testroot=`test_init double_rm`
105 71a29355 2019-03-27 stsp
106 71a29355 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
107 71a29355 2019-03-27 stsp ret="$?"
108 71a29355 2019-03-27 stsp if [ "$ret" != "0" ]; then
109 71a29355 2019-03-27 stsp test_done "$testroot" "$ret"
110 71a29355 2019-03-27 stsp return 1
111 71a29355 2019-03-27 stsp fi
112 71a29355 2019-03-27 stsp
113 71a29355 2019-03-27 stsp (cd $testroot/wt && got rm beta > /dev/null)
114 71a29355 2019-03-27 stsp
115 71a29355 2019-03-27 stsp for fflag in "" "-f"; do
116 6d022e97 2019-08-04 stsp echo -n > $testroot/stderr.expected
117 6d022e97 2019-08-04 stsp (cd $testroot/wt && got rm $fflag beta > $testroot/stdout \
118 6d022e97 2019-08-04 stsp 2> $testroot/stderr)
119 71a29355 2019-03-27 stsp ret="$?"
120 6d022e97 2019-08-04 stsp if [ "$ret" != "0" ]; then
121 6d022e97 2019-08-04 stsp echo "got rm command failed unexpectedly" >&2
122 6d022e97 2019-08-04 stsp diff -u $testroot/stderr.expected $testroot/stderr
123 6d022e97 2019-08-04 stsp test_done "$testroot" "$ret"
124 6d022e97 2019-08-04 stsp return 1
125 71a29355 2019-03-27 stsp fi
126 6d022e97 2019-08-04 stsp echo -n > $testroot/stdout.expected
127 6d022e97 2019-08-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
128 71a29355 2019-03-27 stsp ret="$?"
129 71a29355 2019-03-27 stsp if [ "$ret" != "0" ]; then
130 6d022e97 2019-08-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
131 71a29355 2019-03-27 stsp test_done "$testroot" "$ret"
132 6d022e97 2019-08-04 stsp return 1
133 71a29355 2019-03-27 stsp fi
134 71a29355 2019-03-27 stsp done
135 71a29355 2019-03-27 stsp test_done "$testroot" "0"
136 71a29355 2019-03-27 stsp }
137 71a29355 2019-03-27 stsp
138 f0b0c0ce 2019-08-04 stsp function test_rm_and_add_elsewhere {
139 f0b0c0ce 2019-08-04 stsp local testroot=`test_init rm_and_add_elsewhere`
140 f0b0c0ce 2019-08-04 stsp
141 f0b0c0ce 2019-08-04 stsp got checkout $testroot/repo $testroot/wt > /dev/null
142 f0b0c0ce 2019-08-04 stsp ret="$?"
143 f0b0c0ce 2019-08-04 stsp if [ "$ret" != "0" ]; then
144 f0b0c0ce 2019-08-04 stsp test_done "$testroot" "$ret"
145 f0b0c0ce 2019-08-04 stsp return 1
146 f0b0c0ce 2019-08-04 stsp fi
147 f0b0c0ce 2019-08-04 stsp
148 f0b0c0ce 2019-08-04 stsp (cd $testroot/wt && mv alpha epsilon/)
149 f0b0c0ce 2019-08-04 stsp
150 f0b0c0ce 2019-08-04 stsp (cd $testroot/wt && got status > $testroot/stdout)
151 f0b0c0ce 2019-08-04 stsp
152 f0b0c0ce 2019-08-04 stsp echo '! alpha' > $testroot/stdout.expected
153 f0b0c0ce 2019-08-04 stsp echo '? epsilon/alpha' >> $testroot/stdout.expected
154 f0b0c0ce 2019-08-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
155 f0b0c0ce 2019-08-04 stsp ret="$?"
156 f0b0c0ce 2019-08-04 stsp if [ "$ret" != "0" ]; then
157 f0b0c0ce 2019-08-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
158 f0b0c0ce 2019-08-04 stsp test_done "$testroot" "$ret"
159 f0b0c0ce 2019-08-04 stsp return 1
160 f0b0c0ce 2019-08-04 stsp fi
161 f0b0c0ce 2019-08-04 stsp
162 f0b0c0ce 2019-08-04 stsp echo 'D alpha' > $testroot/stdout.expected
163 f0b0c0ce 2019-08-04 stsp (cd $testroot/wt && got rm alpha > $testroot/stdout)
164 f0b0c0ce 2019-08-04 stsp
165 f0b0c0ce 2019-08-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
166 f0b0c0ce 2019-08-04 stsp ret="$?"
167 f0b0c0ce 2019-08-04 stsp if [ "$ret" != "0" ]; then
168 f0b0c0ce 2019-08-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
169 f0b0c0ce 2019-08-04 stsp test_done "$testroot" "$ret"
170 f0b0c0ce 2019-08-04 stsp return 1
171 f0b0c0ce 2019-08-04 stsp fi
172 f0b0c0ce 2019-08-04 stsp
173 f0b0c0ce 2019-08-04 stsp echo 'A epsilon/alpha' > $testroot/stdout.expected
174 f0b0c0ce 2019-08-04 stsp (cd $testroot/wt && got add epsilon/alpha > $testroot/stdout)
175 f0b0c0ce 2019-08-04 stsp
176 f0b0c0ce 2019-08-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
177 f0b0c0ce 2019-08-04 stsp ret="$?"
178 f0b0c0ce 2019-08-04 stsp if [ "$ret" != "0" ]; then
179 f0b0c0ce 2019-08-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
180 f0b0c0ce 2019-08-04 stsp test_done "$testroot" "$ret"
181 f0b0c0ce 2019-08-04 stsp return 1
182 f0b0c0ce 2019-08-04 stsp fi
183 f0b0c0ce 2019-08-04 stsp
184 f0b0c0ce 2019-08-04 stsp (cd $testroot/wt && got status > $testroot/stdout)
185 f0b0c0ce 2019-08-04 stsp
186 f0b0c0ce 2019-08-04 stsp echo 'D alpha' > $testroot/stdout.expected
187 f0b0c0ce 2019-08-04 stsp echo 'A epsilon/alpha' >> $testroot/stdout.expected
188 f0b0c0ce 2019-08-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
189 f0b0c0ce 2019-08-04 stsp ret="$?"
190 f0b0c0ce 2019-08-04 stsp if [ "$ret" != "0" ]; then
191 f0b0c0ce 2019-08-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
192 f0b0c0ce 2019-08-04 stsp fi
193 f0b0c0ce 2019-08-04 stsp test_done "$testroot" "$ret"
194 f0b0c0ce 2019-08-04 stsp }
195 f0b0c0ce 2019-08-04 stsp
196 2ec1f75b 2019-03-26 stsp run_test test_rm_basic
197 2ec1f75b 2019-03-26 stsp run_test test_rm_with_local_mods
198 71a29355 2019-03-27 stsp run_test test_double_rm
199 f0b0c0ce 2019-08-04 stsp run_test test_rm_and_add_elsewhere