Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2022 Omar Polo <op@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 test_patch_simple_add_file() {
20 local testroot=`test_init patch_simple_add_file`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret=$?
24 if [ $ret -ne 0 ]; then
25 test_done $testroot $ret
26 return 1
27 fi
29 cat <<EOF > $testroot/wt/patch
30 --- /dev/null
31 +++ eta
32 @@ -0,0 +1 @@
33 +eta
34 EOF
36 (cd $testroot/wt && got patch patch) > $testroot/stdout
37 ret=$?
38 if [ $ret -ne 0 ]; then
39 test_done $testroot $ret
40 return 1
41 fi
43 echo "A eta" > $testroot/stdout.expected
44 cmp -s $testroot/stdout.expected $testroot/stdout
45 ret=$?
46 if [ $ret -ne 0 ]; then
47 diff -u $testroot/stdout.expected $testroot/stdout
48 test_done $testroot $ret
49 return 1
50 fi
52 echo eta > $testroot/wt/eta.expected
53 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
54 ret=$?
55 if [ $ret -ne 0 ]; then
56 diff -u $testroot/wt/eta.expected $testroot/wt/eta
57 fi
58 test_done $testroot $ret
59 }
61 test_patch_simple_rm_file() {
62 local testroot=`test_init patch_simple_rm_file`
64 got checkout $testroot/repo $testroot/wt > /dev/null
65 ret=$?
66 if [ $ret -ne 0 ]; then
67 test_done $testroot $ret
68 return 1
69 fi
71 cat <<EOF > $testroot/wt/patch
72 --- alpha
73 +++ /dev/null
74 @@ -1 +0,0 @@
75 -alpha
76 EOF
78 echo "D alpha" > $testroot/stdout.expected
80 (cd $testroot/wt && got patch patch) > $testroot/stdout
81 ret=$?
82 if [ $ret -ne 0 ]; then
83 test_done $testroot $ret
84 return 1
85 fi
87 cmp -s $testroot/stdout.expected $testroot/stdout
88 ret=$?
89 if [ $ret -ne 0 ]; then
90 diff -u $testroot/stdout.expected $testroot/stdout
91 test_done $testroot $ret
92 return 1
93 fi
95 if [ -f $testroot/wt/alpha ]; then
96 ret=1
97 echo "alpha still exists!"
98 fi
99 test_done $testroot $ret
102 test_patch_simple_edit_file() {
103 local testroot=`test_init patch_simple_edit_file`
105 got checkout $testroot/repo $testroot/wt > /dev/null
106 ret=$?
107 if [ $ret -ne 0 ]; then
108 test_done $testroot $ret
109 return 1
110 fi
112 cat <<EOF > $testroot/wt/patch
113 --- alpha
114 +++ alpha
115 @@ -1 +1 @@
116 -alpha
117 +alpha is my favourite character
118 EOF
120 echo "M alpha" > $testroot/stdout.expected
122 (cd $testroot/wt && got patch patch) > $testroot/stdout
123 ret=$?
124 if [ $ret -ne 0 ]; then
125 test_done $testroot $ret
126 return 1
127 fi
129 cmp -s $testroot/stdout.expected $testroot/stdout
130 ret=$?
131 if [ $ret -ne 0 ]; then
132 diff -u $testroot/stdout.expected $testroot/stdout
133 test_done $testroot $ret
134 return 1
135 fi
137 echo 'alpha is my favourite character' > $testroot/wt/alpha.expected
138 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
139 ret=$?
140 if [ $ret -ne 0 ]; then
141 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
142 fi
143 test_done $testroot $ret
146 test_patch_prepend_line() {
147 local testroot=`test_init patch_prepend_line`
149 got checkout $testroot/repo $testroot/wt > /dev/null
150 ret=$?
151 if [ $ret -ne 0 ]; then
152 test_done $testroot $ret
153 return 1
154 fi
156 cat <<EOF > $testroot/wt/patch
157 --- alpha
158 +++ alpha
159 @@ -1 +1,2 @@
160 +hatsuseno
161 alpha
162 EOF
164 echo "M alpha" > $testroot/stdout.expected
166 (cd $testroot/wt && got patch patch) > $testroot/stdout
167 ret=$?
168 if [ $ret -ne 0 ]; then
169 test_done $testroot $ret
170 return 1
171 fi
173 cmp -s $testroot/stdout.expected $testroot/stdout
174 ret=$?
175 if [ $ret -ne 0 ]; then
176 diff -u $testroot/stdout.expected $testroot/stdout
177 test_done $testroot $ret
178 return 1
179 fi
181 echo hatsuseno > $testroot/wt/alpha.expected
182 echo alpha >> $testroot/wt/alpha.expected
183 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
184 ret=$?
185 if [ $ret -ne 0 ]; then
186 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
187 fi
188 test_done $testroot $ret
191 test_patch_replace_line() {
192 local testroot=`test_init patch_replace_line`
194 got checkout $testroot/repo $testroot/wt > /dev/null
195 ret=$?
196 if [ $ret -ne 0 ]; then
197 test_done $testroot $ret
198 return 1
199 fi
201 jot 10 > $testroot/wt/numbers
202 (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
203 >/dev/null
204 ret=$?
205 if [ $ret -ne 0 ]; then
206 test_done $testroot $ret
207 return 1
208 fi
210 cat <<EOF > $testroot/wt/patch
211 --- numbers
212 +++ numbers
213 @@ -3,7 +3,7 @@
217 -6
218 +foo
222 EOF
224 echo "M numbers" > $testroot/stdout.expected
226 (cd $testroot/wt && got patch patch) > $testroot/stdout
227 ret=$?
228 if [ $ret -ne 0 ]; then
229 test_done $testroot $ret
230 return 1
231 fi
233 cmp -s $testroot/stdout.expected $testroot/stdout
234 ret=$?
235 if [ $ret -ne 0 ]; then
236 diff -u $testroot/stdout.expected $testroot/stdout
237 test_done $testroot $ret
238 return 1
239 fi
241 jot 10 | sed 's/6/foo/' > $testroot/wt/numbers.expected
242 cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
243 ret=$?
244 if [ $ret -ne 0 ]; then
245 diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
246 fi
247 test_done $testroot $ret
250 test_patch_multiple_hunks() {
251 local testroot=`test_init patch_replace_multiple_hunks`
253 got checkout $testroot/repo $testroot/wt > /dev/null
254 ret=$?
255 if [ $ret -ne 0 ]; then
256 test_done $testroot $ret
257 return 1
258 fi
260 jot 100 > $testroot/wt/numbers
261 (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
262 >/dev/null
263 ret=$?
264 if [ $ret -ne 0 ]; then
265 test_done $testroot $ret
266 return 1
267 fi
269 cat <<EOF > $testroot/wt/patch
270 --- numbers
271 +++ numbers
272 @@ -3,7 +3,7 @@
276 -6
277 +foo
281 @@ -57,7 +57,7 @@
282 57
283 58
284 59
285 -60
286 +foo foo
287 61
288 62
289 63
290 @@ -98,3 +98,6 @@
291 98
292 99
293 100
294 +101
295 +102
296 +...
297 EOF
299 echo "M numbers" > $testroot/stdout.expected
301 (cd $testroot/wt && got patch patch) > $testroot/stdout
302 ret=$?
303 if [ $ret -ne 0 ]; then
304 test_done $testroot $ret
305 return 1
306 fi
308 cmp -s $testroot/stdout.expected $testroot/stdout
309 ret=$?
310 if [ $ret -ne 0 ]; then
311 diff -u $testroot/stdout.expected $testroot/stdout
312 test_done $testroot $ret
313 return 1
314 fi
316 jot 100 | sed -e 's/^6$/foo/' -e 's/^60$/foo foo/' \
317 > $testroot/wt/numbers.expected
318 echo "101" >> $testroot/wt/numbers.expected
319 echo "102" >> $testroot/wt/numbers.expected
320 echo "..." >> $testroot/wt/numbers.expected
322 cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
323 ret=$?
324 if [ $ret -ne 0 ]; then
325 diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
326 fi
327 test_done $testroot $ret
330 test_patch_multiple_files() {
331 local testroot=`test_init patch_multiple_files`
333 got checkout $testroot/repo $testroot/wt > /dev/null
334 ret=$?
335 if [ $ret -ne 0 ]; then
336 test_done $testroot $ret
337 return 1
338 fi
340 cat <<EOF > $testroot/wt/patch
341 --- alpha Mon Mar 7 19:02:07 2022
342 +++ alpha Mon Mar 7 19:01:53 2022
343 @@ -1 +1,3 @@
344 +new
345 alpha
346 +available
347 --- beta Mon Mar 7 19:02:11 2022
348 +++ beta Mon Mar 7 19:01:46 2022
349 @@ -1 +1,3 @@
350 beta
351 +was
352 +improved
353 --- gamma/delta Mon Mar 7 19:02:17 2022
354 +++ gamma/delta Mon Mar 7 19:01:37 2022
355 @@ -1 +1 @@
356 -delta
357 +delta new
358 EOF
360 echo "M alpha" > $testroot/stdout.expected
361 echo "M beta" >> $testroot/stdout.expected
362 echo "M gamma/delta" >> $testroot/stdout.expected
364 (cd $testroot/wt && got patch patch) > $testroot/stdout
365 ret=$?
366 if [ $ret -ne 0 ]; then
367 test_done $testroot $ret
368 return 1
369 fi
371 cmp -s $testroot/stdout.expected $testroot/stdout
372 ret=$?
373 if [ $ret -ne 0 ]; then
374 diff -u $testroot/stdout.expected $testroot/stdout
375 test_done $testroot $ret
376 return 1
377 fi
379 printf 'new\nalpha\navailable\n' > $testroot/wt/alpha.expected
380 printf 'beta\nwas\nimproved\n' > $testroot/wt/beta.expected
381 printf 'delta new\n' > $testroot/wt/gamma/delta.expected
383 for f in alpha beta gamma/delta; do
384 cmp -s $testroot/wt/$f.expected $testroot/wt/$f
385 ret=$?
386 if [ $ret -ne 0 ]; then
387 diff -u $testroot/wt/$f.expected $testroot/wt/$f
388 test_done $testroot $ret
389 return 1
390 fi
391 done
393 test_done $testroot 0
396 test_patch_dont_apply() {
397 local testroot=`test_init patch_dont_apply`
399 got checkout $testroot/repo $testroot/wt > /dev/null
400 ret=$?
401 if [ $ret -ne 0 ]; then
402 test_done $testroot $ret
403 return 1
404 fi
406 jot 100 > $testroot/wt/numbers
407 (cd $testroot/wt && got add numbers && got commit -m 'add numbers') \
408 >/dev/null
409 ret=$?
410 if [ $ret -ne 0 ]; then
411 test_done $testroot $ret
412 return 1
413 fi
415 cat <<EOF > $testroot/wt/patch
416 --- alpha
417 +++ alpha
418 @@ -1 +1,2 @@
419 +hatsuseno
420 alpha something
421 --- numbers
422 +++ /dev/null
423 @@ -1,9 +0,0 @@
424 -1
425 -2
426 -3
427 -4
428 -5
429 -6
430 -7
431 -8
432 -9
433 EOF
435 (cd $testroot/wt && got patch patch) > $testroot/stdout 2> /dev/null
436 ret=$?
437 if [ $ret -eq 0 ]; then # should fail
438 test_done $testroot 1
439 return 1
440 fi
442 cat <<EOF > $testroot/stdout.expected
443 # alpha
444 @@ -1,1 +1,2 @@ hunk failed to apply
445 # numbers
446 @@ -1,9 +0,0 @@ hunk failed to apply
447 EOF
449 cmp -s $testroot/stdout.expected $testroot/stdout
450 ret=$?
451 if [ $ret -ne 0 ]; then
452 diff -u $testroot/stdout.expected $testroot/stdout
453 fi
454 test_done $testroot $ret
457 test_patch_malformed() {
458 local testroot=`test_init patch_malformed`
460 got checkout $testroot/repo $testroot/wt > /dev/null
461 ret=$?
462 if [ $ret -ne 0 ]; then
463 test_done $testroot $ret
464 return 1
465 fi
467 # missing "@@"
468 cat <<EOF > $testroot/wt/patch
469 --- alpha
470 +++ alpha
471 @@ -1 +1,2
472 +hatsuseno
473 alpha
474 EOF
476 echo -n > $testroot/stdout.expected
477 echo "got: malformed patch" > $testroot/stderr.expected
479 (cd $testroot/wt && got patch patch) \
480 > $testroot/stdout \
481 2> $testroot/stderr
482 ret=$?
483 if [ $ret -eq 0 ]; then
484 echo "got managed to apply an invalid patch"
485 test_done $testroot 1
486 return 1
487 fi
489 cmp -s $testroot/stdout.expected $testroot/stdout
490 ret=$?
491 if [ $ret -ne 0 ]; then
492 diff -u $testroot/stdout.expected $testroot/stdout
493 test_done $testroot $ret
494 return 1
495 fi
497 cmp -s $testroot/stderr.expected $testroot/stderr
498 ret=$?
499 if [ $ret -ne 0 ]; then
500 diff -u $testroot/stderr.expected $testroot/stderr
501 test_done $testroot $ret
502 return 1
503 fi
505 # wrong first character
506 cat <<EOF > $testroot/wt/patch
507 --- alpha
508 +++ alpha
509 @@ -1 +1,2 @@
510 +hatsuseno
511 alpha
512 EOF
514 (cd $testroot/wt && got patch patch) \
515 > $testroot/stdout \
516 2> $testroot/stderr
517 ret=$?
518 if [ $ret -eq 0 ]; then
519 echo "got managed to apply an invalid patch"
520 test_done $testroot 1
521 return 1
522 fi
524 cmp -s $testroot/stdout.expected $testroot/stdout
525 ret=$?
526 if [ $ret -ne 0 ]; then
527 diff -u $testroot/stdout.expected $testroot/stdout
528 test_done $testroot $ret
529 return 1
530 fi
532 cmp -s $testroot/stderr.expected $testroot/stderr
533 ret=$?
534 if [ $ret -ne 0 ]; then
535 diff -u $testroot/stderr.expected $testroot/stderr
536 test_done $testroot $ret
537 return 1
538 fi
540 test_done $testroot $ret
543 test_patch_no_patch() {
544 local testroot=`test_init patch_no_patch`
546 got checkout $testroot/repo $testroot/wt > /dev/null
547 ret=$?
548 if [ $ret -ne 0 ]; then
549 test_done $testroot $ret
550 return 1
551 fi
553 cat <<EOF > $testroot/wt/patch
554 hello world!
555 ...
557 some other nonsense
558 ...
560 there's no patch in here!
561 EOF
563 echo -n > $testroot/stdout.expected
564 echo "got: no patch found" > $testroot/stderr.expected
566 (cd $testroot/wt && got patch patch) \
567 > $testroot/stdout \
568 2> $testroot/stderr
569 ret=$?
570 if [ $ret -eq 0 ]; then # should fail
571 test_done $testroot 1
572 return 1
573 fi
575 cmp -s $testroot/stdout.expected $testroot/stdout
576 ret=$?
577 if [ $ret -ne 0 ]; then
578 diff -u $testroot/stdout.expected $testroot/stdout
579 test_done $testroot $ret
580 return 1
581 fi
583 cmp -s $testroot/stderr.expected $testroot/stderr
584 ret=$?
585 if [ $ret -ne 0 ]; then
586 diff -u $testroot/stderr.expected $testroot/stderr
587 test_done $testroot $ret
588 return 1
589 fi
591 test_done $testroot $ret
594 test_patch_equals_for_context() {
595 local testroot=`test_init patch_equals_for_context`
597 got checkout $testroot/repo $testroot/wt > /dev/null
598 ret=$?
599 if [ $ret -ne 0 ]; then
600 test_done $testroot $ret
601 return 1
602 fi
604 cat <<EOF > $testroot/wt/patch
605 --- alpha
606 +++ alpha
607 @@ -1 +1,2 @@
608 +hatsuseno
609 =alpha
610 EOF
612 echo "M alpha" > $testroot/stdout.expected
614 (cd $testroot/wt && got patch patch) > $testroot/stdout
615 ret=$?
616 if [ $ret -ne 0 ]; then
617 test_done $testroot $ret
618 return 1
619 fi
621 cmp -s $testroot/stdout.expected $testroot/stdout
622 ret=$?
623 if [ $ret -ne 0 ]; then
624 diff -u $testroot/stdout.expected $testroot/stdout
625 test_done $testroot $ret
626 return 1
627 fi
629 echo hatsuseno > $testroot/wt/alpha.expected
630 echo alpha >> $testroot/wt/alpha.expected
631 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
632 ret=$?
633 if [ $ret -ne 0 ]; then
634 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
635 fi
636 test_done $testroot $ret
639 test_patch_rename() {
640 local testroot=`test_init patch_rename`
642 got checkout $testroot/repo $testroot/wt > /dev/null
643 ret=$?
644 if [ $ret -ne 0 ]; then
645 test_done $testroot $ret
646 return 1
647 fi
649 cat <<EOF > $testroot/wt/patch
650 diff --git a/beta b/iota
651 similarity index 100%
652 rename from beta
653 rename to iota
654 diff --git a/alpha b/eta
655 --- a/alpha
656 +++ b/eta
657 @@ -1 +1 @@
658 -alpha
659 +eta
660 EOF
662 echo 'D beta' > $testroot/stdout.expected
663 echo 'A iota' >> $testroot/stdout.expected
664 echo 'D alpha' >> $testroot/stdout.expected
665 echo 'A eta' >> $testroot/stdout.expected
667 (cd $testroot/wt && got patch patch) > $testroot/stdout
668 ret=$?
669 if [ $ret -ne 0 ]; then
670 test_done $testroot $ret
671 return 1
672 fi
674 cmp -s $testroot/stdout.expected $testroot/stdout
675 ret=$?
676 if [ $ret -ne 0 ]; then
677 diff -u $testroot/stdout.expected $testroot/stdout
678 test_done $testroot $ret
679 return 1
680 fi
682 if [ -f $testroot/wt/alpha -o -f $testroot/wt/beta ]; then
683 echo "alpha or beta were not removed" >&2
684 test_done $testroot 1
685 return 1
686 fi
687 if [ ! -f $testroot/wt/iota -o ! -f $testroot/wt/eta ]; then
688 echo "iota or eta were not created" >&2
689 test_done $testroot 1
690 return 1
691 fi
693 echo beta > $testroot/wt/iota.expected
694 cmp -s $testroot/wt/iota.expected $testroot/wt/iota
695 ret=$?
696 if [ $ret -ne 0 ]; then
697 diff -u $testroot/wt/iota.expected $testroot/wt/iota
698 test_done $testroot $ret
699 return 1
700 fi
702 echo eta > $testroot/wt/eta.expected
703 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
704 ret=$?
705 if [ $ret -ne 0 ]; then
706 diff -u $testroot/wt/eta.expected $testroot/wt/eta
707 test_done $testroot $ret
708 return 1
709 fi
711 test_done $testroot $ret
714 test_patch_illegal_status() {
715 local testroot=`test_init patch_illegal_status`
717 got checkout $testroot/repo $testroot/wt > /dev/null
718 ret=$?
719 if [ $ret -ne 0 ]; then
720 test_done $testroot $ret
721 return 1
722 fi
724 # try to patch an obstructed file, add a versioned one, edit a
725 # non existent file and an unversioned one, and remove a
726 # non existent file.
727 cat <<EOF > $testroot/wt/patch
728 --- alpha
729 +++ alpha
730 @@ -1 +1,2 @@
731 alpha
732 +was edited
733 --- /dev/null
734 +++ beta
735 @@ -0,0 +1 @@
736 +beta
737 --- iota
738 +++ iota
739 @@ -1 +1 @@
740 -iota
741 +IOTA
742 --- kappa
743 +++ kappa
744 @@ -1 +1 @@
745 -kappa
746 +KAPPA
747 --- lambda
748 +++ /dev/null
749 @@ -1 +0,0 @@
750 -lambda
751 EOF
753 echo kappa > $testroot/wt/kappa
754 rm $testroot/wt/alpha
755 mkdir $testroot/wt/alpha
757 (cd $testroot/wt && got patch patch) > $testroot/stdout \
758 2> $testroot/stderr
759 ret=$?
760 if [ $ret -eq 0 ]; then
761 echo "edited a missing file" >&2
762 test_done $testroot $ret
763 return 1
764 fi
766 cat <<EOF > $testroot/stdout.expected
767 # alpha
768 # beta
769 # iota
770 # kappa
771 # lambda
772 EOF
774 cat <<EOF > $testroot/stderr.expected
775 got: alpha: file has unexpected status
776 got: beta: file has unexpected status
777 got: iota: No such file or directory
778 got: kappa: file has unexpected status
779 got: lambda: No such file or directory
780 got: patch failed to apply
781 EOF
783 cmp -s $testroot/stdout.expected $testroot/stdout
784 ret=$?
785 if [ $ret -ne 0 ]; then
786 diff -u $testroot/stdout.expected $testroot/stdout
787 test_done $testroot $ret
788 return 1
789 fi
791 cmp -s $testroot/stderr.expected $testroot/stderr
792 ret=$?
793 if [ $ret -ne 0 ]; then
794 diff -u $testroot/stderr.expected $testroot/stderr
795 test_done $testroot $ret
796 return 1
797 fi
799 (cd $testroot/wt && got status) > $testroot/stdout
800 cat <<EOF > $testroot/stdout.expected
801 ~ alpha
802 ? kappa
803 ? patch
804 EOF
806 cmp -s $testroot/stdout.expected $testroot/stdout
807 ret=$?
808 if [ $ret -ne 0 ]; then
809 diff -u $testroot/stdout.expected $testroot/stdout
810 fi
811 test_done $testroot $ret
814 test_patch_nop() {
815 local testroot=`test_init patch_nop`
817 got checkout $testroot/repo $testroot/wt > /dev/null
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 test_done $testroot $ret
821 return 1
822 fi
824 cat <<EOF > $testroot/wt/patch
825 --- alpha
826 +++ alpha
827 @@ -1 +1 @@
828 -alpha
829 +cafe alpha
830 --- beta
831 +++ /dev/null
832 @@ -1 +0,0 @@
833 -beta
834 diff --git a/gamma/delta b/gamma/delta.new
835 --- gamma/delta
836 +++ gamma/delta.new
837 @@ -1 +1 @@
838 -delta
839 +delta updated and renamed!
840 EOF
842 (cd $testroot/wt && got patch -n patch)
843 ret=$?
844 if [ $ret -ne 0 ]; then
845 test_done $testroot $ret
846 return 1
847 fi
849 # remove the patch to avoid the ? entry
850 rm $testroot/wt/patch
852 (cd $testroot/wt && got status) > $testroot/stdout
853 ret=$?
854 if [ $ret -ne 0 ]; then
855 test_done $testroot $ret
856 return 1
857 fi
859 echo -n > $testroot/stdout.expected
860 cmp -s $testroot/stdout.expected $testroot/stdout
861 ret=$?
862 if [ $ret -ne 0 ]; then
863 diff -u $testroot/stdout.expected $testroot/stdout
864 fi
865 test_done $testroot $ret
868 test_patch_preserve_perm() {
869 local testroot=`test_init patch_preserve_perm`
871 got checkout $testroot/repo $testroot/wt > /dev/null
872 ret=$?
873 if [ $ret -ne 0 ]; then
874 test_done $testroot $ret
875 return 1
876 fi
878 chmod +x $testroot/wt/alpha
879 (cd $testroot/wt && got commit -m 'alpha executable') > /dev/null
880 ret=$?
881 if [ $ret -ne 0 ]; then
882 test_done $testroot $ret
883 return 1
884 fi
886 cat <<EOF > $testroot/wt/patch
887 --- alpha
888 +++ alpha
889 @@ -1 +1,2 @@
890 alpha
891 +was edited
892 EOF
894 (cd $testroot/wt && got patch patch) > /dev/null
895 ret=$?
896 if [ $ret -ne 0 ]; then
897 test_done $testroot $ret
898 return 1
899 fi
901 if [ ! -x $testroot/wt/alpha ]; then
902 echo "alpha is no more executable!" >&2
903 test_done $testroot 1
904 return 1
905 fi
906 test_done $testroot 0
909 test_patch_create_dirs() {
910 local testroot=`test_init patch_create_dirs`
912 got checkout $testroot/repo $testroot/wt > /dev/null
913 ret=$?
914 if [ $ret -ne 0 ]; then
915 test_done $testroot $ret
916 return 1
917 fi
919 cat <<EOF > $testroot/wt/patch
920 --- /dev/null
921 +++ iota/kappa/lambda
922 @@ -0,0 +1 @@
923 +lambda
924 EOF
926 (cd $testroot/wt && got patch patch) > $testroot/stdout
927 ret=$?
928 if [ $ret -ne 0 ]; then
929 test_done $testroot $ret
930 return 1
931 fi
933 echo 'A iota/kappa/lambda' >> $testroot/stdout.expected
934 cmp -s $testroot/stdout.expected $testroot/stdout
935 ret=$?
936 if [ $ret -ne 0 ]; then
937 diff -u $testroot/stdout.expected $testroot/stdout
938 test_done $testroot $ret
939 return 1
940 fi
942 if [ ! -f $testroot/wt/iota/kappa/lambda ]; then
943 echo "file not created!" >&2
944 test_done $testroot $ret
945 return 1
946 fi
947 test_done $testroot 0
950 test_patch_with_offset() {
951 local testroot=`test_init patch_with_offset`
953 got checkout $testroot/repo $testroot/wt > /dev/null
954 ret=$?
955 if [ $ret -ne 0 ]; then
956 test_done $testroot $ret
957 return 1
958 fi
960 cat <<EOF > $testroot/wt/patch
961 --- numbers
962 +++ numbers
963 @@ -47,7 +47,7 @@
964 47
965 48
966 49
967 -50
968 +midway tru it!
969 51
970 52
971 53
972 @@ -87,7 +87,7 @@
973 87
974 88
975 89
976 -90
977 +almost there!
978 91
979 92
980 93
981 EOF
983 jot 100 > $testroot/wt/numbers
984 ed $testroot/wt/numbers <<EOF > /dev/null 2> /dev/null
985 1,10d
986 50r !jot 20
989 EOF
991 (cd $testroot/wt && got add numbers && got commit -m '+numbers') \
992 > /dev/null
993 ret=$?
994 if [ $ret -ne 0 ]; then
995 test_done $testroot $ret
996 return 1
997 fi
999 (cd $testroot/wt && got patch patch) > $testroot/stdout
1000 ret=$?
1001 if [ $ret -ne 0 ]; then
1002 test_done $testroot/wt $ret
1003 return 1
1006 cat <<EOF > $testroot/stdout.expected
1007 M numbers
1008 @@ -47,7 +47,7 @@ applied with offset -10
1009 @@ -87,7 +87,7 @@ applied with offset 10
1010 EOF
1012 cmp -s $testroot/stdout.expected $testroot/stdout
1013 ret=$?
1014 if [ $ret -ne 0 ]; then
1015 diff -u $testroot/stdout.expected $testroot/stdout
1017 test_done $testroot $ret
1020 test_patch_prefer_new_path() {
1021 local testroot=`test_init patch_orig`
1023 got checkout $testroot/repo $testroot/wt > /dev/null
1024 ret=$?
1025 if [ $ret -ne 0 ]; then
1026 test_done $testroot $ret
1027 return 1
1030 cat <<EOF > $testroot/wt/patch
1031 --- alpha.orig
1032 +++ alpha
1033 @@ -1 +1,2 @@
1034 alpha
1035 +was edited
1036 EOF
1038 (cd $testroot/wt && got patch patch) > $testroot/stdout
1039 ret=$?
1040 if [ $ret -ne 0 ]; then
1041 test_done $testroot $ret
1042 return 1
1045 echo 'M alpha' > $testroot/stdout.expected
1046 cmp -s $testroot/stdout.expected $testroot/stdout
1047 ret=$?
1048 if [ $ret -ne 0 ]; then
1049 diff -u $testroot/stdout.expected $testroot/stdout
1051 test_done $testroot $ret
1054 test_patch_no_newline() {
1055 local testroot=`test_init patch_no_newline`
1057 got checkout $testroot/repo $testroot/wt > /dev/null
1058 ret=$?
1059 if [ $ret -ne 0 ]; then
1060 test_done $testroot $ret
1061 return 1
1064 cat <<EOF > $testroot/wt/patch
1065 --- /dev/null
1066 +++ eta
1067 @@ -0,0 +1 @@
1068 +eta
1069 \ No newline at end of file
1070 EOF
1072 (cd $testroot/wt && got patch patch) > $testroot/stdout
1073 ret=$?
1074 if [ $ret -ne 0 ]; then
1075 test_done $testroot $ret
1076 return 1
1079 echo "A eta" > $testroot/stdout.expected
1080 cmp -s $testroot/stdout.expected $testroot/stdout
1081 ret=$?
1082 if [ $ret -ne 0 ]; then
1083 diff -u $testroot/stdout.expected $testroot/stdout
1084 test_done $testroot $ret
1085 return 1
1088 echo -n eta > $testroot/wt/eta.expected
1089 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1090 ret=$?
1091 if [ $ret -ne 0 ]; then
1092 diff -u $testroot/wt/eta.expected $testroot/wt/eta
1093 test_done $testroot $ret
1094 return 1
1097 (cd $testroot/wt && got commit -m 'add eta') > /dev/null
1098 ret=$?
1099 if [ $ret -ne 0 ]; then
1100 test_done $testroot $ret
1101 return 1
1104 cat <<EOF > $testroot/wt/patch
1105 --- eta
1106 +++ eta
1107 @@ -1 +1 @@
1108 -eta
1109 \ No newline at end of file
1110 +ETA
1111 \ No newline at end of file
1112 EOF
1114 (cd $testroot/wt && got patch patch) > $testroot/stdout
1115 ret=$?
1116 if [ $ret -ne 0 ]; then
1117 test_done $testroot $ret
1118 return 1
1121 echo "M eta" > $testroot/stdout.expected
1122 cmp -s $testroot/stdout.expected $testroot/stdout
1123 ret=$?
1124 if [ $ret -ne 0 ]; then
1125 diff -u $testroot/stdout.expected $testroot/stdout
1126 test_done $testroot $ret
1127 return 1
1130 echo -n ETA > $testroot/wt/eta.expected
1131 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1132 ret=$?
1133 if [ $ret -ne 0 ]; then
1134 diff -u $testroot/wt/eta.expected $testroot/wt/eta
1135 test_done $testroot $ret
1136 return 1
1139 (cd $testroot/wt && got commit -m 'edit eta') > /dev/null
1140 ret=$?
1141 if [ $ret -ne 0 ]; then
1142 test_done $testroot $ret
1143 return 1
1146 cat <<EOF > $testroot/wt/patch
1147 --- eta
1148 +++ eta
1149 @@ -1 +1 @@
1150 -ETA
1151 \ No newline at end of file
1152 +eta
1153 EOF
1155 (cd $testroot/wt && got patch patch) > $testroot/stdout
1156 ret=$?
1157 if [ $ret -ne 0 ]; then
1158 test_done $testroot $ret
1159 return 1
1162 echo "M eta" > $testroot/stdout.expected
1163 cmp -s $testroot/stdout.expected $testroot/stdout
1164 ret=$?
1165 if [ $ret -ne 0 ]; then
1166 diff -u $testroot/stdout.expected $testroot/stdout
1167 test_done $testroot $ret
1168 return 1
1171 echo eta > $testroot/wt/eta.expected
1172 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1173 ret=$?
1174 if [ $ret -ne 0 ]; then
1175 diff -u $testroot/wt/eta.expected $testroot/wt/eta
1177 test_done $testroot $ret
1180 test_patch_strip() {
1181 local testroot=`test_init patch_strip`
1183 got checkout $testroot/repo $testroot/wt > /dev/null
1184 ret=$?
1185 if [ $ret -ne 0 ]; then
1186 test_done $testroot $ret
1187 return 1
1190 cat <<EOF > $testroot/wt/patch
1191 --- foo/bar/alpha.orig
1192 +++ foo/bar/alpha
1193 @@ -1 +1 @@
1194 -alpha
1195 +ALPHA
1196 EOF
1198 (cd $testroot/wt && got patch -p2 patch) > $testroot/stdout
1199 ret=$?
1200 if [ $ret -ne 0 ]; then
1201 test_done $testroot $ret
1202 return 1
1205 echo "M alpha" >> $testroot/stdout.expected
1206 cmp -s $testroot/stdout.expected $testroot/stdout
1207 ret=$?
1208 if [ $ret -ne 0 ]; then
1209 diff -u $testroot/stdout.expected $testroot/stdout
1210 test_done $testroot $ret
1211 return 1
1214 (cd $testroot/wt && got revert alpha) > /dev/null 2>&1
1215 ret=$?
1216 if [ $ret -ne 0 ]; then
1217 test_done $testroot $ret
1218 return 1
1221 (cd $testroot/wt && got patch -p3 patch) \
1222 2> $testroot/stderr
1223 ret=$?
1224 if [ $ret -eq 0 ]; then
1225 echo "stripped more components than available!"
1226 test_done $testroot 1
1227 return 1
1230 cat <<EOF > $testroot/stderr.expected
1231 got: can't strip 1 path-components from foo/bar/alpha: bad path
1232 EOF
1234 cmp -s $testroot/stderr.expected $testroot/stderr
1235 ret=$?
1236 if [ $ret -ne 0 ]; then
1237 diff -u $testroot/stderr.expected $testroot/stderr
1239 test_done $testroot 0
1242 test_patch_relative_paths() {
1243 local testroot=`test_init patch_relative_paths`
1245 got checkout $testroot/repo $testroot/wt > /dev/null
1246 ret=$?
1247 if [ $ret -ne 0 ]; then
1248 test_done $testroot $ret
1249 return 1
1252 cat <<EOF > $testroot/wt/gamma/patch
1253 --- delta
1254 +++ delta
1255 @@ -1 +1 @@
1256 -delta
1257 +DELTA
1258 --- /dev/null
1259 +++ eta
1260 @@ -0,0 +1 @@
1261 +eta
1262 EOF
1264 (cd $testroot/wt/gamma && got patch patch) > $testroot/stdout
1265 ret=$?
1266 if [ $ret -ne 0 ]; then
1267 test_done $testroot $ret
1268 return 1
1271 echo 'M gamma/delta' > $testroot/stdout.expected
1272 echo 'A gamma/eta' >> $testroot/stdout.expected
1274 cmp -s $testroot/stdout.expected $testroot/stdout
1275 ret=$?
1276 if [ $ret -ne 0 ]; then
1277 diff -u $testroot/stdout.expected $testroot/stdout
1279 test_done $testroot $ret
1282 test_patch_with_path_prefix() {
1283 local testroot=`test_init patch_with_path_prefix`
1285 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1286 ret=$?
1287 if [ $ret -ne 0 ]; then
1288 test_done $testroot $ret
1289 return 1
1292 cat <<EOF > $testroot/wt/patch
1293 --- delta
1294 +++ delta
1295 @@ -1 +1 @@
1296 -delta
1297 +DELTA
1298 --- /dev/null
1299 +++ eta
1300 @@ -0,0 +1 @@
1301 +eta
1302 EOF
1304 (cd $testroot/wt && got patch patch) > $testroot/stdout
1305 ret=$?
1306 if [ $ret -ne 0 ]; then
1307 test_done $testroot $ret
1308 return 1
1311 echo 'M delta' > $testroot/stdout.expected
1312 echo 'A eta' >> $testroot/stdout.expected
1314 cmp -s $testroot/stdout.expected $testroot/stdout
1315 ret=$?
1316 if [ $ret -ne 0 ]; then
1317 diff -u $testroot/stdout.expected $testroot/stdout
1319 test_done $testroot $ret
1322 test_patch_relpath_with_path_prefix() {
1323 local testroot=`test_init patch_relpaths_with_path_prefix`
1325 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1326 ret=$?
1327 if [ $ret -ne 0 ]; then
1328 test_done $testroot $ret
1329 return 1
1332 mkdir -p $testroot/wt/epsilon/zeta/
1334 cat <<EOF > $testroot/wt/patch
1335 --- /dev/null
1336 +++ zeta/theta
1337 @@ -0,0 +1 @@
1338 +theta
1339 EOF
1341 (cd $testroot/wt/epsilon/zeta && got patch -p1 $testroot/wt/patch) \
1342 > $testroot/stdout
1343 ret=$?
1344 if [ $ret -ne 0 ]; then
1345 test_done $testroot $ret
1346 return 1
1349 echo 'A epsilon/zeta/theta' >> $testroot/stdout.expected
1351 cmp -s $testroot/stdout.expected $testroot/stdout
1352 ret=$?
1353 if [ $ret -ne 0 ]; then
1354 diff -u $testroot/stdout.expected $testroot/stdout
1355 test_done $testroot $ret
1356 return 1
1359 echo 'theta' > $testroot/theta.expected
1360 cmp -s $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1361 ret=$?
1362 if [ $ret -ne 0 ]; then
1363 diff -u $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1365 test_done $testroot $ret
1368 test_patch_reverse() {
1369 local testroot=`test_init patch_reverse`
1371 got checkout $testroot/repo $testroot/wt > /dev/null
1372 ret=$?
1373 if [ $ret -ne 0 ]; then
1374 test_done $testroot $ret
1375 return 1
1378 cat <<EOF > $testroot/wt/patch
1379 --- alpha
1380 +++ alpha
1381 @@ -1 +1 @@
1382 -ALPHA
1383 \ No newline at end of file
1384 +alpha
1385 EOF
1387 (cd $testroot/wt && got patch -R patch) > $testroot/stdout
1388 ret=$?
1389 if [ $ret -ne 0 ]; then
1390 test_done $testroot $ret
1391 return 1
1394 echo "M alpha" > $testroot/stdout.expected
1395 cmp -s $testroot/stdout.expected $testroot/stdout
1396 ret=$?
1397 if [ $ret -ne 0 ]; then
1398 diff -u $testroot/stdout.expected $testroot/stdout
1399 test_done $testroot $ret
1400 return 1
1403 echo -n ALPHA > $testroot/wt/alpha.expected
1404 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
1405 ret=$?
1406 if [ $ret -ne 0 ]; then
1407 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
1409 test_done $testroot $ret
1412 test_parseargs "$@"
1413 run_test test_patch_simple_add_file
1414 run_test test_patch_simple_rm_file
1415 run_test test_patch_simple_edit_file
1416 run_test test_patch_prepend_line
1417 run_test test_patch_replace_line
1418 run_test test_patch_multiple_hunks
1419 run_test test_patch_multiple_files
1420 run_test test_patch_dont_apply
1421 run_test test_patch_malformed
1422 run_test test_patch_no_patch
1423 run_test test_patch_equals_for_context
1424 run_test test_patch_rename
1425 run_test test_patch_illegal_status
1426 run_test test_patch_nop
1427 run_test test_patch_preserve_perm
1428 run_test test_patch_create_dirs
1429 run_test test_patch_with_offset
1430 run_test test_patch_prefer_new_path
1431 run_test test_patch_no_newline
1432 run_test test_patch_strip
1433 run_test test_patch_relative_paths
1434 run_test test_patch_with_path_prefix
1435 run_test test_patch_relpath_with_path_prefix
1436 run_test test_patch_reverse