3 069bbb86 2022-03-07 thomas # Copyright (c) 2022 Omar Polo <op@openbsd.org>
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.
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.
17 069bbb86 2022-03-07 thomas . ./common.sh
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`
22 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
24 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
25 069bbb86 2022-03-07 thomas test_done $testroot $ret
29 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
30 069bbb86 2022-03-07 thomas --- /dev/null
32 069bbb86 2022-03-07 thomas @@ -0,0 +1 @@
36 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
38 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
39 069bbb86 2022-03-07 thomas test_done $testroot $ret
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
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
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
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
58 069bbb86 2022-03-07 thomas test_done $testroot $ret
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`
64 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
66 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
67 069bbb86 2022-03-07 thomas test_done $testroot $ret
71 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
73 069bbb86 2022-03-07 thomas +++ /dev/null
74 069bbb86 2022-03-07 thomas @@ -1 +0,0 @@
78 069bbb86 2022-03-07 thomas echo "D alpha" > $testroot/stdout.expected
80 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
82 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
83 069bbb86 2022-03-07 thomas test_done $testroot $ret
87 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
95 069bbb86 2022-03-07 thomas if [ -f $testroot/wt/alpha ]; then
97 069bbb86 2022-03-07 thomas echo "alpha still exists!"
99 069bbb86 2022-03-07 thomas test_done $testroot $ret
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`
105 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
107 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
108 069bbb86 2022-03-07 thomas test_done $testroot $ret
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 @@
117 069bbb86 2022-03-07 thomas +alpha is my favourite character
120 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
122 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
124 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
125 069bbb86 2022-03-07 thomas test_done $testroot $ret
129 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
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
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
143 069bbb86 2022-03-07 thomas test_done $testroot $ret
146 069bbb86 2022-03-07 thomas test_patch_prepend_line() {
147 069bbb86 2022-03-07 thomas local testroot=`test_init patch_prepend_line`
149 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
151 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
152 069bbb86 2022-03-07 thomas test_done $testroot $ret
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
164 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
166 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
168 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
169 069bbb86 2022-03-07 thomas test_done $testroot $ret
173 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
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
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
188 069bbb86 2022-03-07 thomas test_done $testroot $ret
191 069bbb86 2022-03-07 thomas test_patch_replace_line() {
192 069bbb86 2022-03-07 thomas local testroot=`test_init patch_replace_line`
194 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
196 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
197 069bbb86 2022-03-07 thomas test_done $testroot $ret
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
205 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
206 069bbb86 2022-03-07 thomas test_done $testroot $ret
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 @@
224 069bbb86 2022-03-07 thomas echo "M numbers" > $testroot/stdout.expected
226 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
228 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
229 069bbb86 2022-03-07 thomas test_done $testroot $ret
233 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
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
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
247 069bbb86 2022-03-07 thomas test_done $testroot $ret
250 069bbb86 2022-03-07 thomas test_patch_multiple_hunks() {
251 02e4f0d8 2022-03-08 thomas local testroot=`test_init patch_replace_multiple_hunks`
253 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
255 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
256 069bbb86 2022-03-07 thomas test_done $testroot $ret
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
264 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
265 069bbb86 2022-03-07 thomas test_done $testroot $ret
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 @@
281 069bbb86 2022-03-07 thomas @@ -57,7 +57,7 @@
290 069bbb86 2022-03-07 thomas @@ -98,3 +98,6 @@
299 069bbb86 2022-03-07 thomas echo "M numbers" > $testroot/stdout.expected
301 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
303 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
304 069bbb86 2022-03-07 thomas test_done $testroot $ret
308 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
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
322 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
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
327 069bbb86 2022-03-07 thomas test_done $testroot $ret
330 069bbb86 2022-03-07 thomas test_patch_multiple_files() {
331 069bbb86 2022-03-07 thomas local testroot=`test_init patch_multiple_files`
333 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
335 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
336 069bbb86 2022-03-07 thomas test_done $testroot $ret
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 @@
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 @@
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 @@
357 069bbb86 2022-03-07 thomas +delta new
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
364 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
366 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
367 02e4f0d8 2022-03-08 thomas test_done $testroot $ret
371 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
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
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
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
393 069bbb86 2022-03-07 thomas test_done $testroot 0
396 069bbb86 2022-03-07 thomas test_patch_dont_apply() {
397 069bbb86 2022-03-07 thomas local testroot=`test_init patch_dont_apply`
399 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
401 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
402 069bbb86 2022-03-07 thomas test_done $testroot $ret
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
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
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
421 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then # should fail
422 069bbb86 2022-03-07 thomas test_done $testroot 1
426 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
434 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
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
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
447 7dd42450 2022-03-13 thomas if [ $ret -ne 0 ]; then
448 7dd42450 2022-03-13 thomas test_done $testroot $ret
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 @@
467 7dd42450 2022-03-13 thomas (cd $testroot/wt && got patch patch) > /dev/null 2> $testroot/stderr
469 7dd42450 2022-03-13 thomas if [ $ret -eq 0 ]; then # should fail
470 7dd42450 2022-03-13 thomas test_done $testroot 1
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
477 7dd42450 2022-03-13 thomas if [ $ret -ne 0 ]; then
478 7dd42450 2022-03-13 thomas diff -u $testroot/stderr.expected $testroot/stderr
480 069bbb86 2022-03-07 thomas test_done $testroot $ret
483 069bbb86 2022-03-07 thomas test_patch_malformed() {
484 069bbb86 2022-03-07 thomas local testroot=`test_init patch_malformed`
486 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
488 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
489 069bbb86 2022-03-07 thomas test_done $testroot $ret
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
502 069bbb86 2022-03-07 thomas echo -n > $testroot/stdout.expected
503 069bbb86 2022-03-07 thomas echo "got: malformed patch" > $testroot/stderr.expected
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
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
515 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
523 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
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
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
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
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
550 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
558 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
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
566 069bbb86 2022-03-07 thomas test_done $testroot $ret
569 069bbb86 2022-03-07 thomas test_patch_no_patch() {
570 069bbb86 2022-03-07 thomas local testroot=`test_init patch_no_patch`
572 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
574 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
575 069bbb86 2022-03-07 thomas test_done $testroot $ret
579 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
580 069bbb86 2022-03-07 thomas hello world!
583 069bbb86 2022-03-07 thomas some other nonsense
586 069bbb86 2022-03-07 thomas there's no patch in here!
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
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
596 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then # should fail
597 069bbb86 2022-03-07 thomas test_done $testroot 1
601 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
609 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
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
617 069bbb86 2022-03-07 thomas test_done $testroot $ret
620 069bbb86 2022-03-07 thomas test_patch_equals_for_context() {
621 069bbb86 2022-03-07 thomas local testroot=`test_init patch_prepend_line`
623 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
625 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
626 069bbb86 2022-03-07 thomas test_done $testroot $ret
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
638 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
640 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
642 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
643 069bbb86 2022-03-07 thomas test_done $testroot $ret
647 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
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
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
662 069bbb86 2022-03-07 thomas test_done $testroot $ret
665 bb2ad8ff 2022-03-13 thomas test_patch_rename() {
666 bb2ad8ff 2022-03-13 thomas local testroot=`test_init patch_rename`
668 bb2ad8ff 2022-03-13 thomas got checkout $testroot/repo $testroot/wt > /dev/null
670 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
671 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
675 bb2ad8ff 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
676 bb2ad8ff 2022-03-13 thomas --- alpha
678 bb2ad8ff 2022-03-13 thomas @@ -0,0 +0,0 @@
681 bb2ad8ff 2022-03-13 thomas echo 'D alpha' > $testroot/stdout.expected
682 bb2ad8ff 2022-03-13 thomas echo 'A eta' >> $testroot/stdout.expected
684 bb2ad8ff 2022-03-13 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
686 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
687 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
691 bb2ad8ff 2022-03-13 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
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
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
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
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
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
722 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
723 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
726 42d9d68e 2022-03-13 thomas rm $testroot/wt/eta
728 bb2ad8ff 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
729 bb2ad8ff 2022-03-13 thomas --- alpha
731 bb2ad8ff 2022-03-13 thomas @@ -1 +1,2 @@
733 bb2ad8ff 2022-03-13 thomas +but now is eta
736 bb2ad8ff 2022-03-13 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
738 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
739 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
743 bb2ad8ff 2022-03-13 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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
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
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
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
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
769 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
772 42d9d68e 2022-03-13 thomas test_patch_illegal_status() {
773 42d9d68e 2022-03-13 thomas local testroot=`test_init patch_illegal_status`
775 42d9d68e 2022-03-13 thomas got checkout $testroot/repo $testroot/wt > /dev/null
777 42d9d68e 2022-03-13 thomas if [ $ret -ne 0 ]; then
778 42d9d68e 2022-03-13 thomas test_done $testroot $ret
782 42d9d68e 2022-03-13 thomas # edit an non-existent and unknown file
783 42d9d68e 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
786 42d9d68e 2022-03-13 thomas @@ -1 +1 @@
791 42d9d68e 2022-03-13 thomas (cd $testroot/wt && got patch patch) > /dev/null \
792 42d9d68e 2022-03-13 thomas 2> $testroot/stderr
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
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
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
810 42d9d68e 2022-03-13 thomas # create iota and re-try
811 42d9d68e 2022-03-13 thomas echo iota > $testroot/wt/iota
813 42d9d68e 2022-03-13 thomas (cd $testroot/wt && got patch patch) > /dev/null \
814 42d9d68e 2022-03-13 thomas 2> $testroot/stderr
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
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
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
832 42d9d68e 2022-03-13 thomas rm $testroot/wt/iota
834 42d9d68e 2022-03-13 thomas if [ $ret -ne 0 ]; then
835 42d9d68e 2022-03-13 thomas test_done $testroot $ret
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 @@
847 42d9d68e 2022-03-13 thomas +was edited
850 42d9d68e 2022-03-13 thomas (cd $testroot/wt && got patch patch) > /dev/null \
851 42d9d68e 2022-03-13 thomas 2> $testroot/stderr
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
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
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
869 42d9d68e 2022-03-13 thomas # delete an unknown file
870 42d9d68e 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
872 42d9d68e 2022-03-13 thomas +++ /dev/null
873 42d9d68e 2022-03-13 thomas @@ -1 +0,0 @@
877 42d9d68e 2022-03-13 thomas (cd $testroot/wt && got patch patch) > /dev/null \
878 42d9d68e 2022-03-13 thomas 2> $testroot/stderr
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
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
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
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
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
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
911 42d9d68e 2022-03-13 thomas if [ $ret -eq 0 ]; then
912 42d9d68e 2022-03-13 thomas diff -u $testroot/stderr.expected $testroot/stderr
914 42d9d68e 2022-03-13 thomas test_done $testroot $ret
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