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_prepend_line`
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 --- alpha
651 +++ eta
652 @@ -0,0 +0,0 @@
653 EOF
655 echo 'D alpha' > $testroot/stdout.expected
656 echo 'A eta' >> $testroot/stdout.expected
658 (cd $testroot/wt && got patch patch) > $testroot/stdout
659 ret=$?
660 if [ $ret -ne 0 ]; then
661 test_done $testroot $ret
662 return 1
663 fi
665 cmp -s $testroot/stdout.expected $testroot/stdout
666 ret=$?
667 if [ $ret -ne 0 ]; then
668 diff -u $testroot/stdout.expected $testroot/stdout
669 test_done $testroot $ret
670 return 1
671 fi
673 if [ -f $testroot/wt/alpha ]; then
674 echo "alpha was not removed" >&2
675 test_done $testroot 1
676 return 1
677 fi
678 if [ ! -f $testroot/wt/eta ]; then
679 echo "eta was not created" >&2
680 test_done $testroot 1
681 return 1
682 fi
684 echo alpha > $testroot/wt/eta.expected
685 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
686 ret=$?
687 if [ $ret -ne 0 ]; then
688 diff -u $testroot/wt/eta.expected $testroot/wt/eta
689 test_done $testroot $ret
690 return 1
691 fi
693 # revert the changes and try again with a rename + edit
694 (cd $testroot/wt && got revert alpha eta) > /dev/null
695 ret=$?
696 if [ $ret -ne 0 ]; then
697 test_done $testroot $ret
698 return 1
699 fi
700 rm $testroot/wt/eta
702 cat <<EOF > $testroot/wt/patch
703 --- alpha
704 +++ eta
705 @@ -1 +1,2 @@
706 alpha
707 +but now is eta
708 EOF
710 (cd $testroot/wt && got patch patch) > $testroot/stdout
711 ret=$?
712 if [ $ret -ne 0 ]; then
713 test_done $testroot $ret
714 return 1
715 fi
717 cmp -s $testroot/stdout.expected $testroot/stdout
718 ret=$?
719 if [ $ret -ne 0 ]; then
720 diff -u $testroot/stdout.expected $testroot/stdout
721 test_done $testroot $ret
722 return 1
723 fi
725 if [ -f $testroot/wt/alpha ]; then
726 echo "alpha was not removed" >&2
727 test_done $testroot 1
728 return 1
729 fi
730 if [ ! -f $testroot/wt/eta ]; then
731 echo "eta was not created" >&2
732 test_done $testroot 1
733 return 1
734 fi
736 echo alpha > $testroot/wt/eta.expected
737 echo 'but now is eta' >> $testroot/wt/eta.expected
738 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
739 ret=$?
740 if [ $ret -ne 0 ]; then
741 diff -u $testroot/wt/eta.expected $testroot/wt/eta
742 fi
743 test_done $testroot $ret
746 test_patch_illegal_status() {
747 local testroot=`test_init patch_illegal_status`
749 got checkout $testroot/repo $testroot/wt > /dev/null
750 ret=$?
751 if [ $ret -ne 0 ]; then
752 test_done $testroot $ret
753 return 1
754 fi
756 # try to patch an obstructed file, add a versioned one, edit a
757 # non existent file and an unversioned one, and remove a
758 # non existent file.
759 cat <<EOF > $testroot/wt/patch
760 --- alpha
761 +++ alpha
762 @@ -1 +1,2 @@
763 alpha
764 +was edited
765 --- /dev/null
766 +++ beta
767 @@ -0,0 +1 @@
768 +beta
769 --- iota
770 +++ iota
771 @@ -1 +1 @@
772 -iota
773 +IOTA
774 --- kappa
775 +++ kappa
776 @@ -1 +1 @@
777 -kappa
778 +KAPPA
779 --- lambda
780 +++ /dev/null
781 @@ -1 +0,0 @@
782 -lambda
783 EOF
785 echo kappa > $testroot/wt/kappa
786 rm $testroot/wt/alpha
787 mkdir $testroot/wt/alpha
789 (cd $testroot/wt && got patch patch) > $testroot/stdout \
790 2> $testroot/stderr
791 ret=$?
792 if [ $ret -eq 0 ]; then
793 echo "edited a missing file" >&2
794 test_done $testroot $ret
795 return 1
796 fi
798 cat <<EOF > $testroot/stdout.expected
799 # alpha
800 # beta
801 # iota
802 # kappa
803 # lambda
804 EOF
806 cat <<EOF > $testroot/stderr.expected
807 got: alpha: file has unexpected status
808 got: beta: file has unexpected status
809 got: iota: No such file or directory
810 got: kappa: file has unexpected status
811 got: lambda: No such file or directory
812 got: patch failed to apply
813 EOF
815 cmp -s $testroot/stdout.expected $testroot/stdout
816 ret=$?
817 if [ $ret -ne 0 ]; then
818 diff -u $testroot/stdout.expected $testroot/stdout
819 test_done $testroot $ret
820 return 1
821 fi
823 cmp -s $testroot/stderr.expected $testroot/stderr
824 ret=$?
825 if [ $ret -ne 0 ]; then
826 diff -u $testroot/stderr.expected $testroot/stderr
827 fi
828 test_done $testroot $ret
831 test_patch_nop() {
832 local testroot=`test_init patch_nop`
834 got checkout $testroot/repo $testroot/wt > /dev/null
835 ret=$?
836 if [ $ret -ne 0 ]; then
837 test_done $testroot $ret
838 return 1
839 fi
841 cat <<EOF > $testroot/wt/patch
842 --- alpha
843 +++ alpha
844 @@ -1 +1 @@
845 -alpha
846 +cafe alpha
847 --- beta
848 +++ /dev/null
849 @@ -1 +0,0 @@
850 -beta
851 --- gamma/delta
852 +++ gamma/delta.new
853 @@ -1 +1 @@
854 -delta
855 +delta updated and renamed!
856 EOF
858 (cd $testroot/wt && got patch -n patch)
859 ret=$?
860 if [ $ret -ne 0 ]; then
861 test_done $testroot $ret
862 return 1
863 fi
865 # remove the patch to avoid the ? entry
866 rm $testroot/wt/patch
868 (cd $testroot/wt && got status) > $testroot/stdout
869 ret=$?
870 if [ $ret -ne 0 ]; then
871 test_done $testroot $ret
872 return 1
873 fi
875 echo -n > $testroot/stdout.expected
876 cmp -s $testroot/stdout.expected $testroot/stdout
877 ret=$?
878 if [ $ret -ne 0 ]; then
879 diff -u $testroot/stdout.expected $testroot/stdout
880 fi
881 test_done $testroot $ret
884 test_patch_preserve_perm() {
885 local testroot=`test_init patch_preserve_perm`
887 got checkout $testroot/repo $testroot/wt > /dev/null
888 ret=$?
889 if [ $ret -ne 0 ]; then
890 test_done $testroot $ret
891 return 1
892 fi
894 chmod +x $testroot/wt/alpha
895 (cd $testroot/wt && got commit -m 'alpha executable') > /dev/null
896 ret=$?
897 if [ $ret -ne 0 ]; then
898 test_done $testroot $ret
899 return 1
900 fi
902 cat <<EOF > $testroot/wt/patch
903 --- alpha
904 +++ alpha
905 @@ -1 +1,2 @@
906 alpha
907 +was edited
908 EOF
910 (cd $testroot/wt && got patch patch) > /dev/null
911 ret=$?
912 if [ $ret -ne 0 ]; then
913 test_done $testroot $ret
914 return 1
915 fi
917 if [ ! -x $testroot/wt/alpha ]; then
918 echo "alpha is no more executable!" >&2
919 test_done $testroot 1
920 return 1
921 fi
922 test_done $testroot 0
925 test_patch_create_dirs() {
926 local testroot=`test_init patch_create_dirs`
928 got checkout $testroot/repo $testroot/wt > /dev/null
929 ret=$?
930 if [ $ret -ne 0 ]; then
931 test_done $testroot $ret
932 return 1
933 fi
935 cat <<EOF > $testroot/wt/patch
936 --- /dev/null
937 +++ iota/kappa/lambda
938 @@ -0,0 +1 @@
939 +lambda
940 EOF
942 (cd $testroot/wt && got patch patch) > $testroot/stdout
943 ret=$?
944 if [ $ret -ne 0 ]; then
945 test_done $testroot $ret
946 return 1
947 fi
949 echo 'A iota/kappa/lambda' >> $testroot/stdout.expected
950 cmp -s $testroot/stdout.expected $testroot/stdout
951 ret=$?
952 if [ $ret -ne 0 ]; then
953 diff -u $testroot/stdout.expected $testroot/stdout
954 test_done $testroot $ret
955 return 1
956 fi
958 if [ ! -f $testroot/wt/iota/kappa/lambda ]; then
959 echo "file not created!" >&2
960 test_done $testroot $ret
961 return 1
962 fi
963 test_done $testroot 0
966 test_patch_with_offset() {
967 local testroot=`test_init patch_with_offset`
969 got checkout $testroot/repo $testroot/wt > /dev/null
970 ret=$?
971 if [ $ret -ne 0 ]; then
972 test_done $testroot $ret
973 return 1
974 fi
976 cat <<EOF > $testroot/wt/patch
977 --- numbers
978 +++ numbers
979 @@ -47,7 +47,7 @@
980 47
981 48
982 49
983 -50
984 +midway tru it!
985 51
986 52
987 53
988 @@ -87,7 +87,7 @@
989 87
990 88
991 89
992 -90
993 +almost there!
994 91
995 92
996 93
997 EOF
999 jot 100 > $testroot/wt/numbers
1000 ed $testroot/wt/numbers <<EOF > /dev/null 2> /dev/null
1001 1,10d
1002 50r !jot 20
1005 EOF
1007 (cd $testroot/wt && got add numbers && got commit -m '+numbers') \
1008 > /dev/null
1009 ret=$?
1010 if [ $ret -ne 0 ]; then
1011 test_done $testroot $ret
1012 return 1
1015 (cd $testroot/wt && got patch patch) > $testroot/stdout
1016 ret=$?
1017 if [ $ret -ne 0 ]; then
1018 test_done $testroot/wt $ret
1019 return 1
1022 cat <<EOF > $testroot/stdout.expected
1023 M numbers
1024 @@ -47,7 +47,7 @@ applied with offset -10
1025 @@ -87,7 +87,7 @@ applied with offset 10
1026 EOF
1028 cmp -s $testroot/stdout.expected $testroot/stdout
1029 ret=$?
1030 if [ $ret -ne 0 ]; then
1031 diff -u $testroot/stdout.expected $testroot/stdout
1033 test_done $testroot $ret
1036 test_parseargs "$@"
1037 run_test test_patch_simple_add_file
1038 run_test test_patch_simple_rm_file
1039 run_test test_patch_simple_edit_file
1040 run_test test_patch_prepend_line
1041 run_test test_patch_replace_line
1042 run_test test_patch_multiple_hunks
1043 run_test test_patch_multiple_files
1044 run_test test_patch_dont_apply
1045 run_test test_patch_malformed
1046 run_test test_patch_no_patch
1047 run_test test_patch_equals_for_context
1048 run_test test_patch_rename
1049 run_test test_patch_illegal_status
1050 run_test test_patch_nop
1051 run_test test_patch_preserve_perm
1052 run_test test_patch_create_dirs
1053 run_test test_patch_with_offset