Blame


1 069bbb86 2022-03-07 thomas #!/bin/sh
2 069bbb86 2022-03-07 thomas #
3 069bbb86 2022-03-07 thomas # Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 069bbb86 2022-03-07 thomas #
5 069bbb86 2022-03-07 thomas # Permission to use, copy, modify, and distribute this software for any
6 069bbb86 2022-03-07 thomas # purpose with or without fee is hereby granted, provided that the above
7 069bbb86 2022-03-07 thomas # copyright notice and this permission notice appear in all copies.
8 069bbb86 2022-03-07 thomas #
9 069bbb86 2022-03-07 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 069bbb86 2022-03-07 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 069bbb86 2022-03-07 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 069bbb86 2022-03-07 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 069bbb86 2022-03-07 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 069bbb86 2022-03-07 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 069bbb86 2022-03-07 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 069bbb86 2022-03-07 thomas
17 069bbb86 2022-03-07 thomas . ./common.sh
18 069bbb86 2022-03-07 thomas
19 069bbb86 2022-03-07 thomas test_patch_simple_add_file() {
20 069bbb86 2022-03-07 thomas local testroot=`test_init patch_simple_add_file`
21 069bbb86 2022-03-07 thomas
22 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
23 069bbb86 2022-03-07 thomas ret=$?
24 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
25 069bbb86 2022-03-07 thomas test_done $testroot $ret
26 069bbb86 2022-03-07 thomas return 1
27 069bbb86 2022-03-07 thomas fi
28 069bbb86 2022-03-07 thomas
29 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
30 069bbb86 2022-03-07 thomas --- /dev/null
31 069bbb86 2022-03-07 thomas +++ eta
32 069bbb86 2022-03-07 thomas @@ -0,0 +1 @@
33 069bbb86 2022-03-07 thomas +eta
34 069bbb86 2022-03-07 thomas EOF
35 069bbb86 2022-03-07 thomas
36 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
37 069bbb86 2022-03-07 thomas ret=$?
38 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
39 069bbb86 2022-03-07 thomas test_done $testroot $ret
40 069bbb86 2022-03-07 thomas return 1
41 069bbb86 2022-03-07 thomas fi
42 069bbb86 2022-03-07 thomas
43 069bbb86 2022-03-07 thomas echo "A eta" > $testroot/stdout.expected
44 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
45 069bbb86 2022-03-07 thomas ret=$?
46 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
47 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
48 069bbb86 2022-03-07 thomas test_done $testroot $ret
49 069bbb86 2022-03-07 thomas return 1
50 069bbb86 2022-03-07 thomas fi
51 069bbb86 2022-03-07 thomas
52 069bbb86 2022-03-07 thomas echo eta > $testroot/wt/eta.expected
53 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/eta.expected $testroot/wt/eta
54 069bbb86 2022-03-07 thomas ret=$?
55 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
56 069bbb86 2022-03-07 thomas diff -u $testroot/wt/eta.expected $testroot/wt/eta
57 069bbb86 2022-03-07 thomas fi
58 069bbb86 2022-03-07 thomas test_done $testroot $ret
59 069bbb86 2022-03-07 thomas }
60 069bbb86 2022-03-07 thomas
61 069bbb86 2022-03-07 thomas test_patch_simple_rm_file() {
62 069bbb86 2022-03-07 thomas local testroot=`test_init patch_simple_rm_file`
63 069bbb86 2022-03-07 thomas
64 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
65 069bbb86 2022-03-07 thomas ret=$?
66 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
67 069bbb86 2022-03-07 thomas test_done $testroot $ret
68 069bbb86 2022-03-07 thomas return 1
69 069bbb86 2022-03-07 thomas fi
70 069bbb86 2022-03-07 thomas
71 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
72 069bbb86 2022-03-07 thomas --- alpha
73 069bbb86 2022-03-07 thomas +++ /dev/null
74 069bbb86 2022-03-07 thomas @@ -1 +0,0 @@
75 069bbb86 2022-03-07 thomas -alpha
76 069bbb86 2022-03-07 thomas EOF
77 069bbb86 2022-03-07 thomas
78 069bbb86 2022-03-07 thomas echo "D alpha" > $testroot/stdout.expected
79 069bbb86 2022-03-07 thomas
80 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
81 069bbb86 2022-03-07 thomas ret=$?
82 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
83 069bbb86 2022-03-07 thomas test_done $testroot $ret
84 069bbb86 2022-03-07 thomas return 1
85 069bbb86 2022-03-07 thomas fi
86 069bbb86 2022-03-07 thomas
87 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
88 069bbb86 2022-03-07 thomas ret=$?
89 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
90 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
91 069bbb86 2022-03-07 thomas test_done $testroot $ret
92 069bbb86 2022-03-07 thomas return 1
93 069bbb86 2022-03-07 thomas fi
94 069bbb86 2022-03-07 thomas
95 069bbb86 2022-03-07 thomas if [ -f $testroot/wt/alpha ]; then
96 069bbb86 2022-03-07 thomas ret=1
97 069bbb86 2022-03-07 thomas echo "alpha still exists!"
98 069bbb86 2022-03-07 thomas fi
99 069bbb86 2022-03-07 thomas test_done $testroot $ret
100 069bbb86 2022-03-07 thomas }
101 069bbb86 2022-03-07 thomas
102 069bbb86 2022-03-07 thomas test_patch_simple_edit_file() {
103 069bbb86 2022-03-07 thomas local testroot=`test_init patch_simple_edit_file`
104 069bbb86 2022-03-07 thomas
105 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
106 069bbb86 2022-03-07 thomas ret=$?
107 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
108 069bbb86 2022-03-07 thomas test_done $testroot $ret
109 069bbb86 2022-03-07 thomas return 1
110 069bbb86 2022-03-07 thomas fi
111 069bbb86 2022-03-07 thomas
112 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
113 069bbb86 2022-03-07 thomas --- alpha
114 069bbb86 2022-03-07 thomas +++ alpha
115 069bbb86 2022-03-07 thomas @@ -1 +1 @@
116 069bbb86 2022-03-07 thomas -alpha
117 069bbb86 2022-03-07 thomas +alpha is my favourite character
118 069bbb86 2022-03-07 thomas EOF
119 069bbb86 2022-03-07 thomas
120 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
121 069bbb86 2022-03-07 thomas
122 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
123 069bbb86 2022-03-07 thomas ret=$?
124 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
125 069bbb86 2022-03-07 thomas test_done $testroot $ret
126 069bbb86 2022-03-07 thomas return 1
127 069bbb86 2022-03-07 thomas fi
128 069bbb86 2022-03-07 thomas
129 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
130 069bbb86 2022-03-07 thomas ret=$?
131 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
132 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
133 069bbb86 2022-03-07 thomas test_done $testroot $ret
134 069bbb86 2022-03-07 thomas return 1
135 069bbb86 2022-03-07 thomas fi
136 069bbb86 2022-03-07 thomas
137 069bbb86 2022-03-07 thomas echo 'alpha is my favourite character' > $testroot/wt/alpha.expected
138 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
139 069bbb86 2022-03-07 thomas ret=$?
140 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
141 069bbb86 2022-03-07 thomas diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
142 069bbb86 2022-03-07 thomas fi
143 069bbb86 2022-03-07 thomas test_done $testroot $ret
144 069bbb86 2022-03-07 thomas }
145 069bbb86 2022-03-07 thomas
146 069bbb86 2022-03-07 thomas test_patch_prepend_line() {
147 069bbb86 2022-03-07 thomas local testroot=`test_init patch_prepend_line`
148 069bbb86 2022-03-07 thomas
149 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
150 069bbb86 2022-03-07 thomas ret=$?
151 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
152 069bbb86 2022-03-07 thomas test_done $testroot $ret
153 069bbb86 2022-03-07 thomas return 1
154 069bbb86 2022-03-07 thomas fi
155 069bbb86 2022-03-07 thomas
156 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
157 069bbb86 2022-03-07 thomas --- alpha
158 069bbb86 2022-03-07 thomas +++ alpha
159 069bbb86 2022-03-07 thomas @@ -1 +1,2 @@
160 069bbb86 2022-03-07 thomas +hatsuseno
161 069bbb86 2022-03-07 thomas alpha
162 069bbb86 2022-03-07 thomas EOF
163 069bbb86 2022-03-07 thomas
164 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
165 069bbb86 2022-03-07 thomas
166 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
167 069bbb86 2022-03-07 thomas ret=$?
168 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
169 069bbb86 2022-03-07 thomas test_done $testroot $ret
170 069bbb86 2022-03-07 thomas return 1
171 069bbb86 2022-03-07 thomas fi
172 069bbb86 2022-03-07 thomas
173 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
174 069bbb86 2022-03-07 thomas ret=$?
175 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
176 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
177 069bbb86 2022-03-07 thomas test_done $testroot $ret
178 069bbb86 2022-03-07 thomas return 1
179 069bbb86 2022-03-07 thomas fi
180 069bbb86 2022-03-07 thomas
181 069bbb86 2022-03-07 thomas echo hatsuseno > $testroot/wt/alpha.expected
182 069bbb86 2022-03-07 thomas echo alpha >> $testroot/wt/alpha.expected
183 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
184 069bbb86 2022-03-07 thomas ret=$?
185 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
186 069bbb86 2022-03-07 thomas diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
187 069bbb86 2022-03-07 thomas fi
188 069bbb86 2022-03-07 thomas test_done $testroot $ret
189 069bbb86 2022-03-07 thomas }
190 069bbb86 2022-03-07 thomas
191 069bbb86 2022-03-07 thomas test_patch_replace_line() {
192 069bbb86 2022-03-07 thomas local testroot=`test_init patch_replace_line`
193 069bbb86 2022-03-07 thomas
194 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
195 069bbb86 2022-03-07 thomas ret=$?
196 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
197 069bbb86 2022-03-07 thomas test_done $testroot $ret
198 069bbb86 2022-03-07 thomas return 1
199 069bbb86 2022-03-07 thomas fi
200 069bbb86 2022-03-07 thomas
201 069bbb86 2022-03-07 thomas jot 10 > $testroot/wt/numbers
202 069bbb86 2022-03-07 thomas (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
203 069bbb86 2022-03-07 thomas >/dev/null
204 069bbb86 2022-03-07 thomas ret=$?
205 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
206 069bbb86 2022-03-07 thomas test_done $testroot $ret
207 069bbb86 2022-03-07 thomas return 1
208 069bbb86 2022-03-07 thomas fi
209 069bbb86 2022-03-07 thomas
210 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
211 069bbb86 2022-03-07 thomas --- numbers
212 069bbb86 2022-03-07 thomas +++ numbers
213 069bbb86 2022-03-07 thomas @@ -3,7 +3,7 @@
214 069bbb86 2022-03-07 thomas 3
215 069bbb86 2022-03-07 thomas 4
216 069bbb86 2022-03-07 thomas 5
217 069bbb86 2022-03-07 thomas -6
218 069bbb86 2022-03-07 thomas +foo
219 069bbb86 2022-03-07 thomas 7
220 069bbb86 2022-03-07 thomas 8
221 069bbb86 2022-03-07 thomas 9
222 069bbb86 2022-03-07 thomas EOF
223 069bbb86 2022-03-07 thomas
224 069bbb86 2022-03-07 thomas echo "M numbers" > $testroot/stdout.expected
225 069bbb86 2022-03-07 thomas
226 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
227 069bbb86 2022-03-07 thomas ret=$?
228 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
229 069bbb86 2022-03-07 thomas test_done $testroot $ret
230 069bbb86 2022-03-07 thomas return 1
231 069bbb86 2022-03-07 thomas fi
232 069bbb86 2022-03-07 thomas
233 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
234 069bbb86 2022-03-07 thomas ret=$?
235 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
236 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
237 069bbb86 2022-03-07 thomas test_done $testroot $ret
238 069bbb86 2022-03-07 thomas return 1
239 069bbb86 2022-03-07 thomas fi
240 069bbb86 2022-03-07 thomas
241 069bbb86 2022-03-07 thomas jot 10 | sed 's/6/foo/' > $testroot/wt/numbers.expected
242 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
243 069bbb86 2022-03-07 thomas ret=$?
244 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
245 069bbb86 2022-03-07 thomas diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
246 069bbb86 2022-03-07 thomas fi
247 069bbb86 2022-03-07 thomas test_done $testroot $ret
248 069bbb86 2022-03-07 thomas }
249 069bbb86 2022-03-07 thomas
250 069bbb86 2022-03-07 thomas test_patch_multiple_hunks() {
251 02e4f0d8 2022-03-08 thomas local testroot=`test_init patch_replace_multiple_hunks`
252 069bbb86 2022-03-07 thomas
253 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
254 069bbb86 2022-03-07 thomas ret=$?
255 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
256 069bbb86 2022-03-07 thomas test_done $testroot $ret
257 069bbb86 2022-03-07 thomas return 1
258 069bbb86 2022-03-07 thomas fi
259 069bbb86 2022-03-07 thomas
260 069bbb86 2022-03-07 thomas jot 100 > $testroot/wt/numbers
261 069bbb86 2022-03-07 thomas (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
262 069bbb86 2022-03-07 thomas >/dev/null
263 069bbb86 2022-03-07 thomas ret=$?
264 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
265 069bbb86 2022-03-07 thomas test_done $testroot $ret
266 069bbb86 2022-03-07 thomas return 1
267 069bbb86 2022-03-07 thomas fi
268 069bbb86 2022-03-07 thomas
269 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
270 069bbb86 2022-03-07 thomas --- numbers
271 069bbb86 2022-03-07 thomas +++ numbers
272 069bbb86 2022-03-07 thomas @@ -3,7 +3,7 @@
273 069bbb86 2022-03-07 thomas 3
274 069bbb86 2022-03-07 thomas 4
275 069bbb86 2022-03-07 thomas 5
276 069bbb86 2022-03-07 thomas -6
277 069bbb86 2022-03-07 thomas +foo
278 069bbb86 2022-03-07 thomas 7
279 069bbb86 2022-03-07 thomas 8
280 069bbb86 2022-03-07 thomas 9
281 069bbb86 2022-03-07 thomas @@ -57,7 +57,7 @@
282 069bbb86 2022-03-07 thomas 57
283 069bbb86 2022-03-07 thomas 58
284 069bbb86 2022-03-07 thomas 59
285 069bbb86 2022-03-07 thomas -60
286 069bbb86 2022-03-07 thomas +foo foo
287 069bbb86 2022-03-07 thomas 61
288 069bbb86 2022-03-07 thomas 62
289 069bbb86 2022-03-07 thomas 63
290 069bbb86 2022-03-07 thomas @@ -98,3 +98,6 @@
291 069bbb86 2022-03-07 thomas 98
292 069bbb86 2022-03-07 thomas 99
293 069bbb86 2022-03-07 thomas 100
294 069bbb86 2022-03-07 thomas +101
295 069bbb86 2022-03-07 thomas +102
296 069bbb86 2022-03-07 thomas +...
297 069bbb86 2022-03-07 thomas EOF
298 069bbb86 2022-03-07 thomas
299 069bbb86 2022-03-07 thomas echo "M numbers" > $testroot/stdout.expected
300 069bbb86 2022-03-07 thomas
301 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
302 069bbb86 2022-03-07 thomas ret=$?
303 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
304 069bbb86 2022-03-07 thomas test_done $testroot $ret
305 069bbb86 2022-03-07 thomas return 1
306 069bbb86 2022-03-07 thomas fi
307 069bbb86 2022-03-07 thomas
308 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
309 069bbb86 2022-03-07 thomas ret=$?
310 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
311 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
312 069bbb86 2022-03-07 thomas test_done $testroot $ret
313 069bbb86 2022-03-07 thomas return 1
314 069bbb86 2022-03-07 thomas fi
315 069bbb86 2022-03-07 thomas
316 069bbb86 2022-03-07 thomas jot 100 | sed -e 's/^6$/foo/' -e 's/^60$/foo foo/' \
317 069bbb86 2022-03-07 thomas > $testroot/wt/numbers.expected
318 069bbb86 2022-03-07 thomas echo "101" >> $testroot/wt/numbers.expected
319 069bbb86 2022-03-07 thomas echo "102" >> $testroot/wt/numbers.expected
320 069bbb86 2022-03-07 thomas echo "..." >> $testroot/wt/numbers.expected
321 069bbb86 2022-03-07 thomas
322 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
323 069bbb86 2022-03-07 thomas ret=$?
324 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
325 069bbb86 2022-03-07 thomas diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
326 069bbb86 2022-03-07 thomas fi
327 069bbb86 2022-03-07 thomas test_done $testroot $ret
328 069bbb86 2022-03-07 thomas }
329 069bbb86 2022-03-07 thomas
330 069bbb86 2022-03-07 thomas test_patch_multiple_files() {
331 069bbb86 2022-03-07 thomas local testroot=`test_init patch_multiple_files`
332 069bbb86 2022-03-07 thomas
333 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
334 069bbb86 2022-03-07 thomas ret=$?
335 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
336 069bbb86 2022-03-07 thomas test_done $testroot $ret
337 069bbb86 2022-03-07 thomas return 1
338 069bbb86 2022-03-07 thomas fi
339 069bbb86 2022-03-07 thomas
340 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
341 069bbb86 2022-03-07 thomas --- alpha Mon Mar 7 19:02:07 2022
342 069bbb86 2022-03-07 thomas +++ alpha Mon Mar 7 19:01:53 2022
343 069bbb86 2022-03-07 thomas @@ -1 +1,3 @@
344 069bbb86 2022-03-07 thomas +new
345 069bbb86 2022-03-07 thomas alpha
346 069bbb86 2022-03-07 thomas +available
347 069bbb86 2022-03-07 thomas --- beta Mon Mar 7 19:02:11 2022
348 069bbb86 2022-03-07 thomas +++ beta Mon Mar 7 19:01:46 2022
349 069bbb86 2022-03-07 thomas @@ -1 +1,3 @@
350 069bbb86 2022-03-07 thomas beta
351 069bbb86 2022-03-07 thomas +was
352 069bbb86 2022-03-07 thomas +improved
353 069bbb86 2022-03-07 thomas --- gamma/delta Mon Mar 7 19:02:17 2022
354 069bbb86 2022-03-07 thomas +++ gamma/delta Mon Mar 7 19:01:37 2022
355 069bbb86 2022-03-07 thomas @@ -1 +1 @@
356 069bbb86 2022-03-07 thomas -delta
357 069bbb86 2022-03-07 thomas +delta new
358 069bbb86 2022-03-07 thomas EOF
359 069bbb86 2022-03-07 thomas
360 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
361 069bbb86 2022-03-07 thomas echo "M beta" >> $testroot/stdout.expected
362 069bbb86 2022-03-07 thomas echo "M gamma/delta" >> $testroot/stdout.expected
363 069bbb86 2022-03-07 thomas
364 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
365 069bbb86 2022-03-07 thomas ret=$?
366 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
367 02e4f0d8 2022-03-08 thomas test_done $testroot $ret
368 069bbb86 2022-03-07 thomas return 1
369 069bbb86 2022-03-07 thomas fi
370 069bbb86 2022-03-07 thomas
371 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
372 069bbb86 2022-03-07 thomas ret=$?
373 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
374 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
375 069bbb86 2022-03-07 thomas test_done $testroot $ret
376 069bbb86 2022-03-07 thomas return 1
377 069bbb86 2022-03-07 thomas fi
378 069bbb86 2022-03-07 thomas
379 069bbb86 2022-03-07 thomas printf 'new\nalpha\navailable\n' > $testroot/wt/alpha.expected
380 069bbb86 2022-03-07 thomas printf 'beta\nwas\nimproved\n' > $testroot/wt/beta.expected
381 069bbb86 2022-03-07 thomas printf 'delta new\n' > $testroot/wt/gamma/delta.expected
382 069bbb86 2022-03-07 thomas
383 069bbb86 2022-03-07 thomas for f in alpha beta gamma/delta; do
384 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/$f.expected $testroot/wt/$f
385 069bbb86 2022-03-07 thomas ret=$?
386 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
387 069bbb86 2022-03-07 thomas diff -u $testroot/wt/$f.expected $testroot/wt/$f
388 069bbb86 2022-03-07 thomas test_done $testroot $ret
389 069bbb86 2022-03-07 thomas return 1
390 069bbb86 2022-03-07 thomas fi
391 069bbb86 2022-03-07 thomas done
392 069bbb86 2022-03-07 thomas
393 069bbb86 2022-03-07 thomas test_done $testroot 0
394 069bbb86 2022-03-07 thomas }
395 069bbb86 2022-03-07 thomas
396 069bbb86 2022-03-07 thomas test_patch_dont_apply() {
397 069bbb86 2022-03-07 thomas local testroot=`test_init patch_dont_apply`
398 069bbb86 2022-03-07 thomas
399 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
400 069bbb86 2022-03-07 thomas ret=$?
401 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
402 069bbb86 2022-03-07 thomas test_done $testroot $ret
403 069bbb86 2022-03-07 thomas return 1
404 069bbb86 2022-03-07 thomas fi
405 069bbb86 2022-03-07 thomas
406 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
407 069bbb86 2022-03-07 thomas --- alpha
408 069bbb86 2022-03-07 thomas +++ alpha
409 069bbb86 2022-03-07 thomas @@ -1 +1,2 @@
410 069bbb86 2022-03-07 thomas +hatsuseno
411 069bbb86 2022-03-07 thomas alpha something
412 069bbb86 2022-03-07 thomas EOF
413 069bbb86 2022-03-07 thomas
414 069bbb86 2022-03-07 thomas echo -n > $testroot/stdout.expected
415 069bbb86 2022-03-07 thomas echo "got: patch doesn't apply" > $testroot/stderr.expected
416 069bbb86 2022-03-07 thomas
417 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) \
418 069bbb86 2022-03-07 thomas > $testroot/stdout \
419 069bbb86 2022-03-07 thomas 2> $testroot/stderr
420 069bbb86 2022-03-07 thomas ret=$?
421 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then # should fail
422 069bbb86 2022-03-07 thomas test_done $testroot 1
423 069bbb86 2022-03-07 thomas return 1
424 069bbb86 2022-03-07 thomas fi
425 069bbb86 2022-03-07 thomas
426 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
427 069bbb86 2022-03-07 thomas ret=$?
428 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
429 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
430 069bbb86 2022-03-07 thomas test_done $testroot $ret
431 069bbb86 2022-03-07 thomas return 1
432 069bbb86 2022-03-07 thomas fi
433 069bbb86 2022-03-07 thomas
434 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
435 069bbb86 2022-03-07 thomas ret=$?
436 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
437 069bbb86 2022-03-07 thomas diff -u $testroot/stderr.expected $testroot/stderr
438 069bbb86 2022-03-07 thomas test_done $testroot $ret
439 7dd42450 2022-03-13 thomas return 1
440 7dd42450 2022-03-13 thomas fi
441 7dd42450 2022-03-13 thomas
442 7dd42450 2022-03-13 thomas # try to delete a file with a patch that doesn't match
443 7dd42450 2022-03-13 thomas jot 100 > $testroot/wt/numbers
444 7dd42450 2022-03-13 thomas (cd $testroot/wt && got add numbers && got commit -m 'add numbers') \
445 7dd42450 2022-03-13 thomas >/dev/null
446 7dd42450 2022-03-13 thomas ret=$?
447 7dd42450 2022-03-13 thomas if [ $ret -ne 0 ]; then
448 7dd42450 2022-03-13 thomas test_done $testroot $ret
449 7dd42450 2022-03-13 thomas return 1
450 7dd42450 2022-03-13 thomas fi
451 7dd42450 2022-03-13 thomas
452 7dd42450 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
453 7dd42450 2022-03-13 thomas --- numbers
454 7dd42450 2022-03-13 thomas +++ /dev/null
455 7dd42450 2022-03-13 thomas @@ -1,9 +0,0 @@
456 7dd42450 2022-03-13 thomas -1
457 7dd42450 2022-03-13 thomas -2
458 7dd42450 2022-03-13 thomas -3
459 7dd42450 2022-03-13 thomas -4
460 7dd42450 2022-03-13 thomas -5
461 7dd42450 2022-03-13 thomas -6
462 7dd42450 2022-03-13 thomas -7
463 7dd42450 2022-03-13 thomas -8
464 7dd42450 2022-03-13 thomas -9
465 7dd42450 2022-03-13 thomas EOF
466 7dd42450 2022-03-13 thomas
467 7dd42450 2022-03-13 thomas (cd $testroot/wt && got patch patch) > /dev/null 2> $testroot/stderr
468 7dd42450 2022-03-13 thomas ret=$?
469 7dd42450 2022-03-13 thomas if [ $ret -eq 0 ]; then # should fail
470 7dd42450 2022-03-13 thomas test_done $testroot 1
471 069bbb86 2022-03-07 thomas return 1
472 069bbb86 2022-03-07 thomas fi
473 069bbb86 2022-03-07 thomas
474 7dd42450 2022-03-13 thomas echo "got: patch doesn't apply" > $testroot/stderr.expected
475 7dd42450 2022-03-13 thomas cmp -s $testroot/stderr.expected $testroot/stderr
476 7dd42450 2022-03-13 thomas ret=$?
477 7dd42450 2022-03-13 thomas if [ $ret -ne 0 ]; then
478 7dd42450 2022-03-13 thomas diff -u $testroot/stderr.expected $testroot/stderr
479 7dd42450 2022-03-13 thomas fi
480 069bbb86 2022-03-07 thomas test_done $testroot $ret
481 069bbb86 2022-03-07 thomas }
482 069bbb86 2022-03-07 thomas
483 069bbb86 2022-03-07 thomas test_patch_malformed() {
484 069bbb86 2022-03-07 thomas local testroot=`test_init patch_malformed`
485 069bbb86 2022-03-07 thomas
486 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
487 069bbb86 2022-03-07 thomas ret=$?
488 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
489 069bbb86 2022-03-07 thomas test_done $testroot $ret
490 069bbb86 2022-03-07 thomas return 1
491 069bbb86 2022-03-07 thomas fi
492 069bbb86 2022-03-07 thomas
493 069bbb86 2022-03-07 thomas # missing "@@"
494 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
495 069bbb86 2022-03-07 thomas --- alpha
496 069bbb86 2022-03-07 thomas +++ alpha
497 069bbb86 2022-03-07 thomas @@ -1 +1,2
498 069bbb86 2022-03-07 thomas +hatsuseno
499 069bbb86 2022-03-07 thomas alpha
500 069bbb86 2022-03-07 thomas EOF
501 069bbb86 2022-03-07 thomas
502 069bbb86 2022-03-07 thomas echo -n > $testroot/stdout.expected
503 069bbb86 2022-03-07 thomas echo "got: malformed patch" > $testroot/stderr.expected
504 069bbb86 2022-03-07 thomas
505 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) \
506 069bbb86 2022-03-07 thomas > $testroot/stdout \
507 069bbb86 2022-03-07 thomas 2> $testroot/stderr
508 069bbb86 2022-03-07 thomas ret=$?
509 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then
510 069bbb86 2022-03-07 thomas echo "got managed to apply an invalid patch"
511 069bbb86 2022-03-07 thomas test_done $testroot 1
512 069bbb86 2022-03-07 thomas return 1
513 069bbb86 2022-03-07 thomas fi
514 069bbb86 2022-03-07 thomas
515 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
516 069bbb86 2022-03-07 thomas ret=$?
517 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
518 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
519 069bbb86 2022-03-07 thomas test_done $testroot $ret
520 069bbb86 2022-03-07 thomas return 1
521 069bbb86 2022-03-07 thomas fi
522 069bbb86 2022-03-07 thomas
523 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
524 069bbb86 2022-03-07 thomas ret=$?
525 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
526 069bbb86 2022-03-07 thomas diff -u $testroot/stderr.expected $testroot/stderr
527 069bbb86 2022-03-07 thomas test_done $testroot $ret
528 069bbb86 2022-03-07 thomas return 1
529 069bbb86 2022-03-07 thomas fi
530 069bbb86 2022-03-07 thomas
531 069bbb86 2022-03-07 thomas # wrong first character
532 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
533 069bbb86 2022-03-07 thomas --- alpha
534 069bbb86 2022-03-07 thomas +++ alpha
535 069bbb86 2022-03-07 thomas @@ -1 +1,2 @@
536 069bbb86 2022-03-07 thomas +hatsuseno
537 069bbb86 2022-03-07 thomas alpha
538 069bbb86 2022-03-07 thomas EOF
539 069bbb86 2022-03-07 thomas
540 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) \
541 069bbb86 2022-03-07 thomas > $testroot/stdout \
542 069bbb86 2022-03-07 thomas 2> $testroot/stderr
543 069bbb86 2022-03-07 thomas ret=$?
544 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then
545 069bbb86 2022-03-07 thomas echo "got managed to apply an invalid patch"
546 069bbb86 2022-03-07 thomas test_done $testroot 1
547 069bbb86 2022-03-07 thomas return 1
548 069bbb86 2022-03-07 thomas fi
549 069bbb86 2022-03-07 thomas
550 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
551 069bbb86 2022-03-07 thomas ret=$?
552 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
553 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
554 069bbb86 2022-03-07 thomas test_done $testroot $ret
555 069bbb86 2022-03-07 thomas return 1
556 069bbb86 2022-03-07 thomas fi
557 069bbb86 2022-03-07 thomas
558 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
559 069bbb86 2022-03-07 thomas ret=$?
560 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
561 069bbb86 2022-03-07 thomas diff -u $testroot/stderr.expected $testroot/stderr
562 069bbb86 2022-03-07 thomas test_done $testroot $ret
563 069bbb86 2022-03-07 thomas return 1
564 069bbb86 2022-03-07 thomas fi
565 069bbb86 2022-03-07 thomas
566 069bbb86 2022-03-07 thomas test_done $testroot $ret
567 069bbb86 2022-03-07 thomas }
568 069bbb86 2022-03-07 thomas
569 069bbb86 2022-03-07 thomas test_patch_no_patch() {
570 069bbb86 2022-03-07 thomas local testroot=`test_init patch_no_patch`
571 069bbb86 2022-03-07 thomas
572 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
573 069bbb86 2022-03-07 thomas ret=$?
574 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
575 069bbb86 2022-03-07 thomas test_done $testroot $ret
576 069bbb86 2022-03-07 thomas return 1
577 069bbb86 2022-03-07 thomas fi
578 069bbb86 2022-03-07 thomas
579 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
580 069bbb86 2022-03-07 thomas hello world!
581 069bbb86 2022-03-07 thomas ...
582 069bbb86 2022-03-07 thomas
583 069bbb86 2022-03-07 thomas some other nonsense
584 069bbb86 2022-03-07 thomas ...
585 069bbb86 2022-03-07 thomas
586 069bbb86 2022-03-07 thomas there's no patch in here!
587 069bbb86 2022-03-07 thomas EOF
588 069bbb86 2022-03-07 thomas
589 069bbb86 2022-03-07 thomas echo -n > $testroot/stdout.expected
590 069bbb86 2022-03-07 thomas echo "got: no patch found" > $testroot/stderr.expected
591 069bbb86 2022-03-07 thomas
592 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) \
593 069bbb86 2022-03-07 thomas > $testroot/stdout \
594 069bbb86 2022-03-07 thomas 2> $testroot/stderr
595 069bbb86 2022-03-07 thomas ret=$?
596 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then # should fail
597 069bbb86 2022-03-07 thomas test_done $testroot 1
598 069bbb86 2022-03-07 thomas return 1
599 069bbb86 2022-03-07 thomas fi
600 069bbb86 2022-03-07 thomas
601 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
602 069bbb86 2022-03-07 thomas ret=$?
603 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
604 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
605 069bbb86 2022-03-07 thomas test_done $testroot $ret
606 069bbb86 2022-03-07 thomas return 1
607 069bbb86 2022-03-07 thomas fi
608 069bbb86 2022-03-07 thomas
609 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
610 069bbb86 2022-03-07 thomas ret=$?
611 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
612 069bbb86 2022-03-07 thomas diff -u $testroot/stderr.expected $testroot/stderr
613 069bbb86 2022-03-07 thomas test_done $testroot $ret
614 069bbb86 2022-03-07 thomas return 1
615 069bbb86 2022-03-07 thomas fi
616 069bbb86 2022-03-07 thomas
617 069bbb86 2022-03-07 thomas test_done $testroot $ret
618 069bbb86 2022-03-07 thomas }
619 069bbb86 2022-03-07 thomas
620 069bbb86 2022-03-07 thomas test_patch_equals_for_context() {
621 069bbb86 2022-03-07 thomas local testroot=`test_init patch_prepend_line`
622 069bbb86 2022-03-07 thomas
623 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
624 069bbb86 2022-03-07 thomas ret=$?
625 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
626 069bbb86 2022-03-07 thomas test_done $testroot $ret
627 069bbb86 2022-03-07 thomas return 1
628 069bbb86 2022-03-07 thomas fi
629 069bbb86 2022-03-07 thomas
630 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
631 069bbb86 2022-03-07 thomas --- alpha
632 069bbb86 2022-03-07 thomas +++ alpha
633 069bbb86 2022-03-07 thomas @@ -1 +1,2 @@
634 069bbb86 2022-03-07 thomas +hatsuseno
635 069bbb86 2022-03-07 thomas =alpha
636 069bbb86 2022-03-07 thomas EOF
637 069bbb86 2022-03-07 thomas
638 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
639 069bbb86 2022-03-07 thomas
640 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
641 069bbb86 2022-03-07 thomas ret=$?
642 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
643 069bbb86 2022-03-07 thomas test_done $testroot $ret
644 069bbb86 2022-03-07 thomas return 1
645 069bbb86 2022-03-07 thomas fi
646 069bbb86 2022-03-07 thomas
647 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
648 069bbb86 2022-03-07 thomas ret=$?
649 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
650 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
651 069bbb86 2022-03-07 thomas test_done $testroot $ret
652 069bbb86 2022-03-07 thomas return 1
653 069bbb86 2022-03-07 thomas fi
654 069bbb86 2022-03-07 thomas
655 069bbb86 2022-03-07 thomas echo hatsuseno > $testroot/wt/alpha.expected
656 069bbb86 2022-03-07 thomas echo alpha >> $testroot/wt/alpha.expected
657 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
658 069bbb86 2022-03-07 thomas ret=$?
659 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
660 069bbb86 2022-03-07 thomas diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
661 069bbb86 2022-03-07 thomas fi
662 069bbb86 2022-03-07 thomas test_done $testroot $ret
663 069bbb86 2022-03-07 thomas }
664 bb2ad8ff 2022-03-13 thomas
665 bb2ad8ff 2022-03-13 thomas test_patch_rename() {
666 bb2ad8ff 2022-03-13 thomas local testroot=`test_init patch_rename`
667 bb2ad8ff 2022-03-13 thomas
668 bb2ad8ff 2022-03-13 thomas got checkout $testroot/repo $testroot/wt > /dev/null
669 bb2ad8ff 2022-03-13 thomas ret=$?
670 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
671 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
672 bb2ad8ff 2022-03-13 thomas return 1
673 bb2ad8ff 2022-03-13 thomas fi
674 bb2ad8ff 2022-03-13 thomas
675 bb2ad8ff 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
676 bb2ad8ff 2022-03-13 thomas --- alpha
677 bb2ad8ff 2022-03-13 thomas +++ eta
678 bb2ad8ff 2022-03-13 thomas @@ -0,0 +0,0 @@
679 bb2ad8ff 2022-03-13 thomas EOF
680 069bbb86 2022-03-07 thomas
681 bb2ad8ff 2022-03-13 thomas echo 'D alpha' > $testroot/stdout.expected
682 bb2ad8ff 2022-03-13 thomas echo 'A eta' >> $testroot/stdout.expected
683 bb2ad8ff 2022-03-13 thomas
684 bb2ad8ff 2022-03-13 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
685 bb2ad8ff 2022-03-13 thomas ret=$?
686 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
687 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
688 bb2ad8ff 2022-03-13 thomas return 1
689 bb2ad8ff 2022-03-13 thomas fi
690 bb2ad8ff 2022-03-13 thomas
691 bb2ad8ff 2022-03-13 thomas cmp -s $testroot/stdout.expected $testroot/stdout
692 bb2ad8ff 2022-03-13 thomas ret=$?
693 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
694 bb2ad8ff 2022-03-13 thomas diff -u $testroot/stdout.expected $testroot/stdout
695 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
696 bb2ad8ff 2022-03-13 thomas return 1
697 bb2ad8ff 2022-03-13 thomas fi
698 bb2ad8ff 2022-03-13 thomas
699 bb2ad8ff 2022-03-13 thomas if [ -f $testroot/wt/alpha ]; then
700 bb2ad8ff 2022-03-13 thomas echo "alpha was not removed" >&2
701 bb2ad8ff 2022-03-13 thomas test_done $testroot 1
702 bb2ad8ff 2022-03-13 thomas return 1
703 bb2ad8ff 2022-03-13 thomas fi
704 bb2ad8ff 2022-03-13 thomas if [ ! -f $testroot/wt/eta ]; then
705 bb2ad8ff 2022-03-13 thomas echo "eta was not created" >&2
706 bb2ad8ff 2022-03-13 thomas test_done $testroot 1
707 bb2ad8ff 2022-03-13 thomas return 1
708 bb2ad8ff 2022-03-13 thomas fi
709 bb2ad8ff 2022-03-13 thomas
710 bb2ad8ff 2022-03-13 thomas echo alpha > $testroot/wt/eta.expected
711 bb2ad8ff 2022-03-13 thomas cmp -s $testroot/wt/eta.expected $testroot/wt/eta
712 bb2ad8ff 2022-03-13 thomas ret=$?
713 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
714 bb2ad8ff 2022-03-13 thomas diff -u $testroot/wt/eta.expected $testroot/wt/eta
715 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
716 bb2ad8ff 2022-03-13 thomas return 1
717 bb2ad8ff 2022-03-13 thomas fi
718 bb2ad8ff 2022-03-13 thomas
719 bb2ad8ff 2022-03-13 thomas # revert the changes and try again with a rename + edit
720 bb2ad8ff 2022-03-13 thomas (cd $testroot/wt && got revert alpha eta) > /dev/null
721 bb2ad8ff 2022-03-13 thomas ret=$?
722 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
723 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
724 bb2ad8ff 2022-03-13 thomas return 1
725 bb2ad8ff 2022-03-13 thomas fi
726 42d9d68e 2022-03-13 thomas rm $testroot/wt/eta
727 bb2ad8ff 2022-03-13 thomas
728 bb2ad8ff 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
729 bb2ad8ff 2022-03-13 thomas --- alpha
730 bb2ad8ff 2022-03-13 thomas +++ eta
731 bb2ad8ff 2022-03-13 thomas @@ -1 +1,2 @@
732 bb2ad8ff 2022-03-13 thomas alpha
733 bb2ad8ff 2022-03-13 thomas +but now is eta
734 bb2ad8ff 2022-03-13 thomas EOF
735 bb2ad8ff 2022-03-13 thomas
736 bb2ad8ff 2022-03-13 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
737 bb2ad8ff 2022-03-13 thomas ret=$?
738 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
739 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
740 bb2ad8ff 2022-03-13 thomas return 1
741 bb2ad8ff 2022-03-13 thomas fi
742 bb2ad8ff 2022-03-13 thomas
743 bb2ad8ff 2022-03-13 thomas cmp -s $testroot/stdout.expected $testroot/stdout
744 bb2ad8ff 2022-03-13 thomas ret=$?
745 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
746 bb2ad8ff 2022-03-13 thomas diff -u $testroot/stdout.expected $testroot/stdout
747 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
748 bb2ad8ff 2022-03-13 thomas return 1
749 bb2ad8ff 2022-03-13 thomas fi
750 bb2ad8ff 2022-03-13 thomas
751 bb2ad8ff 2022-03-13 thomas if [ -f $testroot/wt/alpha ]; then
752 bb2ad8ff 2022-03-13 thomas echo "alpha was not removed" >&2
753 bb2ad8ff 2022-03-13 thomas test_done $testroot 1
754 bb2ad8ff 2022-03-13 thomas return 1
755 bb2ad8ff 2022-03-13 thomas fi
756 bb2ad8ff 2022-03-13 thomas if [ ! -f $testroot/wt/eta ]; then
757 bb2ad8ff 2022-03-13 thomas echo "eta was not created" >&2
758 bb2ad8ff 2022-03-13 thomas test_done $testroot 1
759 bb2ad8ff 2022-03-13 thomas return 1
760 bb2ad8ff 2022-03-13 thomas fi
761 bb2ad8ff 2022-03-13 thomas
762 bb2ad8ff 2022-03-13 thomas echo alpha > $testroot/wt/eta.expected
763 bb2ad8ff 2022-03-13 thomas echo 'but now is eta' >> $testroot/wt/eta.expected
764 bb2ad8ff 2022-03-13 thomas cmp -s $testroot/wt/eta.expected $testroot/wt/eta
765 bb2ad8ff 2022-03-13 thomas ret=$?
766 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
767 bb2ad8ff 2022-03-13 thomas diff -u $testroot/wt/eta.expected $testroot/wt/eta
768 bb2ad8ff 2022-03-13 thomas fi
769 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
770 bb2ad8ff 2022-03-13 thomas }
771 42d9d68e 2022-03-13 thomas
772 42d9d68e 2022-03-13 thomas test_patch_illegal_status() {
773 42d9d68e 2022-03-13 thomas local testroot=`test_init patch_illegal_status`
774 42d9d68e 2022-03-13 thomas
775 42d9d68e 2022-03-13 thomas got checkout $testroot/repo $testroot/wt > /dev/null
776 42d9d68e 2022-03-13 thomas ret=$?
777 42d9d68e 2022-03-13 thomas if [ $ret -ne 0 ]; then
778 42d9d68e 2022-03-13 thomas test_done $testroot $ret
779 42d9d68e 2022-03-13 thomas return 1
780 42d9d68e 2022-03-13 thomas fi
781 42d9d68e 2022-03-13 thomas
782 42d9d68e 2022-03-13 thomas # edit an non-existent and unknown file
783 42d9d68e 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
784 42d9d68e 2022-03-13 thomas --- iota
785 42d9d68e 2022-03-13 thomas +++ iota
786 42d9d68e 2022-03-13 thomas @@ -1 +1 @@
787 42d9d68e 2022-03-13 thomas - iota
788 42d9d68e 2022-03-13 thomas + IOTA
789 42d9d68e 2022-03-13 thomas EOF
790 bb2ad8ff 2022-03-13 thomas
791 42d9d68e 2022-03-13 thomas (cd $testroot/wt && got patch patch) > /dev/null \
792 42d9d68e 2022-03-13 thomas 2> $testroot/stderr
793 42d9d68e 2022-03-13 thomas ret=$?
794 42d9d68e 2022-03-13 thomas if [ $ret -eq 0 ]; then
795 42d9d68e 2022-03-13 thomas echo "edited a missing file" >&2
796 42d9d68e 2022-03-13 thomas test_done $testroot $ret
797 42d9d68e 2022-03-13 thomas return 1
798 42d9d68e 2022-03-13 thomas fi
799 42d9d68e 2022-03-13 thomas
800 42d9d68e 2022-03-13 thomas echo "got: iota: No such file or directory" \
801 42d9d68e 2022-03-13 thomas > $testroot/stderr.expected
802 42d9d68e 2022-03-13 thomas cmp -s $testroot/stderr.expected $testroot/stderr
803 42d9d68e 2022-03-13 thomas ret=$?
804 42d9d68e 2022-03-13 thomas if [ $ret -ne 0 ]; then
805 42d9d68e 2022-03-13 thomas diff -u $testroot/stderr.expected $testroot/stderr
806 42d9d68e 2022-03-13 thomas test_done $testroot $ret
807 42d9d68e 2022-03-13 thomas return 1
808 42d9d68e 2022-03-13 thomas fi
809 42d9d68e 2022-03-13 thomas
810 42d9d68e 2022-03-13 thomas # create iota and re-try
811 42d9d68e 2022-03-13 thomas echo iota > $testroot/wt/iota
812 42d9d68e 2022-03-13 thomas
813 42d9d68e 2022-03-13 thomas (cd $testroot/wt && got patch patch) > /dev/null \
814 42d9d68e 2022-03-13 thomas 2> $testroot/stderr
815 42d9d68e 2022-03-13 thomas ret=$?
816 42d9d68e 2022-03-13 thomas if [ $ret -eq 0 ]; then
817 42d9d68e 2022-03-13 thomas echo "patched an unknown file" >&2
818 42d9d68e 2022-03-13 thomas test_done $testroot $ret
819 42d9d68e 2022-03-13 thomas return 1
820 42d9d68e 2022-03-13 thomas fi
821 42d9d68e 2022-03-13 thomas
822 42d9d68e 2022-03-13 thomas echo "got: iota: file has unexpected status" \
823 42d9d68e 2022-03-13 thomas > $testroot/stderr.expected
824 42d9d68e 2022-03-13 thomas cmp -s $testroot/stderr.expected $testroot/stderr
825 42d9d68e 2022-03-13 thomas ret=$?
826 42d9d68e 2022-03-13 thomas if [ $ret -ne 0 ]; then
827 42d9d68e 2022-03-13 thomas diff -u $testroot/stderr.expected $testroot/stderr
828 42d9d68e 2022-03-13 thomas test_done $testroot $ret
829 42d9d68e 2022-03-13 thomas return 1
830 42d9d68e 2022-03-13 thomas fi
831 42d9d68e 2022-03-13 thomas
832 42d9d68e 2022-03-13 thomas rm $testroot/wt/iota
833 42d9d68e 2022-03-13 thomas ret=$?
834 42d9d68e 2022-03-13 thomas if [ $ret -ne 0 ]; then
835 42d9d68e 2022-03-13 thomas test_done $testroot $ret
836 42d9d68e 2022-03-13 thomas return 1
837 42d9d68e 2022-03-13 thomas fi
838 42d9d68e 2022-03-13 thomas
839 42d9d68e 2022-03-13 thomas # edit obstructed file
840 42d9d68e 2022-03-13 thomas rm $testroot/wt/alpha
841 42d9d68e 2022-03-13 thomas mkdir $testroot/wt/alpha
842 42d9d68e 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
843 42d9d68e 2022-03-13 thomas --- alpha
844 42d9d68e 2022-03-13 thomas +++ alpha
845 42d9d68e 2022-03-13 thomas @@ -1 +1,2 @@
846 42d9d68e 2022-03-13 thomas alpha
847 42d9d68e 2022-03-13 thomas +was edited
848 42d9d68e 2022-03-13 thomas EOF
849 42d9d68e 2022-03-13 thomas
850 42d9d68e 2022-03-13 thomas (cd $testroot/wt && got patch patch) > /dev/null \
851 42d9d68e 2022-03-13 thomas 2> $testroot/stderr
852 42d9d68e 2022-03-13 thomas ret=$?
853 42d9d68e 2022-03-13 thomas if [ $ret -eq 0 ]; then
854 42d9d68e 2022-03-13 thomas echo "edited a missing file" >&2
855 42d9d68e 2022-03-13 thomas test_done $testroot $ret
856 42d9d68e 2022-03-13 thomas return 1
857 42d9d68e 2022-03-13 thomas fi
858 42d9d68e 2022-03-13 thomas
859 42d9d68e 2022-03-13 thomas echo "got: alpha: file has unexpected status" \
860 42d9d68e 2022-03-13 thomas > $testroot/stderr.expected
861 42d9d68e 2022-03-13 thomas cmp -s $testroot/stderr.expected $testroot/stderr
862 42d9d68e 2022-03-13 thomas ret=$?
863 42d9d68e 2022-03-13 thomas if [ $ret -ne 0 ]; then
864 42d9d68e 2022-03-13 thomas diff -u $testroot/stderr.expected $testroot/stderr
865 42d9d68e 2022-03-13 thomas test_done $testroot $ret
866 42d9d68e 2022-03-13 thomas return 1
867 42d9d68e 2022-03-13 thomas fi
868 42d9d68e 2022-03-13 thomas
869 42d9d68e 2022-03-13 thomas # delete an unknown file
870 42d9d68e 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
871 42d9d68e 2022-03-13 thomas --- iota
872 42d9d68e 2022-03-13 thomas +++ /dev/null
873 42d9d68e 2022-03-13 thomas @@ -1 +0,0 @@
874 42d9d68e 2022-03-13 thomas -iota
875 42d9d68e 2022-03-13 thomas EOF
876 42d9d68e 2022-03-13 thomas
877 42d9d68e 2022-03-13 thomas (cd $testroot/wt && got patch patch) > /dev/null \
878 42d9d68e 2022-03-13 thomas 2> $testroot/stderr
879 42d9d68e 2022-03-13 thomas ret=$?
880 42d9d68e 2022-03-13 thomas if [ $ret -eq 0 ]; then
881 42d9d68e 2022-03-13 thomas echo "deleted a missing file?" >&2
882 42d9d68e 2022-03-13 thomas test_done $testroot $ret
883 42d9d68e 2022-03-13 thomas return 1
884 42d9d68e 2022-03-13 thomas fi
885 42d9d68e 2022-03-13 thomas
886 42d9d68e 2022-03-13 thomas echo "got: iota: No such file or directory" \
887 42d9d68e 2022-03-13 thomas > $testroot/stderr.expected
888 42d9d68e 2022-03-13 thomas cmp -s $testroot/stderr.expected $testroot/stderr
889 42d9d68e 2022-03-13 thomas ret=$?
890 42d9d68e 2022-03-13 thomas if [ $ret -eq 0 ]; then
891 42d9d68e 2022-03-13 thomas diff -u $testroot/stderr.expected $testroot/stderr
892 42d9d68e 2022-03-13 thomas test_done $testroot $ret
893 42d9d68e 2022-03-13 thomas return 1
894 42d9d68e 2022-03-13 thomas fi
895 42d9d68e 2022-03-13 thomas
896 42d9d68e 2022-03-13 thomas # try again with iota in place but still not registered
897 42d9d68e 2022-03-13 thomas echo iota > $testroot/wt/iota
898 42d9d68e 2022-03-13 thomas (cd $testroot/wt && got patch patch) > /dev/null \
899 42d9d68e 2022-03-13 thomas 2> $testroot/stderr
900 42d9d68e 2022-03-13 thomas ret=$?
901 42d9d68e 2022-03-13 thomas if [ $ret -eq 0 ]; then
902 42d9d68e 2022-03-13 thomas echo "deleted an unversioned file?" >&2
903 42d9d68e 2022-03-13 thomas test_done $testroot $ret
904 42d9d68e 2022-03-13 thomas return 1
905 42d9d68e 2022-03-13 thomas fi
906 42d9d68e 2022-03-13 thomas
907 42d9d68e 2022-03-13 thomas echo "got: iota: file has unexpected status" \
908 42d9d68e 2022-03-13 thomas > $testroot/stderr.expected
909 42d9d68e 2022-03-13 thomas cmp -s $testroot/stderr.expected $testroot/stderr
910 42d9d68e 2022-03-13 thomas ret=$?
911 42d9d68e 2022-03-13 thomas if [ $ret -eq 0 ]; then
912 42d9d68e 2022-03-13 thomas diff -u $testroot/stderr.expected $testroot/stderr
913 42d9d68e 2022-03-13 thomas fi
914 42d9d68e 2022-03-13 thomas test_done $testroot $ret
915 42d9d68e 2022-03-13 thomas }
916 42d9d68e 2022-03-13 thomas
917 069bbb86 2022-03-07 thomas test_parseargs "$@"
918 069bbb86 2022-03-07 thomas run_test test_patch_simple_add_file
919 069bbb86 2022-03-07 thomas run_test test_patch_simple_rm_file
920 069bbb86 2022-03-07 thomas run_test test_patch_simple_edit_file
921 069bbb86 2022-03-07 thomas run_test test_patch_prepend_line
922 069bbb86 2022-03-07 thomas run_test test_patch_replace_line
923 069bbb86 2022-03-07 thomas run_test test_patch_multiple_hunks
924 069bbb86 2022-03-07 thomas run_test test_patch_multiple_files
925 069bbb86 2022-03-07 thomas run_test test_patch_dont_apply
926 069bbb86 2022-03-07 thomas run_test test_patch_malformed
927 069bbb86 2022-03-07 thomas run_test test_patch_no_patch
928 069bbb86 2022-03-07 thomas run_test test_patch_equals_for_context
929 bb2ad8ff 2022-03-13 thomas run_test test_patch_rename
930 42d9d68e 2022-03-13 thomas run_test test_patch_illegal_status