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 cat <<EOF > $testroot/wt/patch
407 --- alpha
408 +++ alpha
409 @@ -1 +1,2 @@
410 +hatsuseno
411 alpha something
412 EOF
414 echo -n > $testroot/stdout.expected
415 echo "got: patch doesn't apply" > $testroot/stderr.expected
417 (cd $testroot/wt && got patch patch) \
418 > $testroot/stdout \
419 2> $testroot/stderr
420 ret=$?
421 if [ $ret -eq 0 ]; then # should fail
422 test_done $testroot 1
423 return 1
424 fi
426 cmp -s $testroot/stdout.expected $testroot/stdout
427 ret=$?
428 if [ $ret -ne 0 ]; then
429 diff -u $testroot/stdout.expected $testroot/stdout
430 test_done $testroot $ret
431 return 1
432 fi
434 cmp -s $testroot/stderr.expected $testroot/stderr
435 ret=$?
436 if [ $ret -ne 0 ]; then
437 diff -u $testroot/stderr.expected $testroot/stderr
438 test_done $testroot $ret
439 return 1
440 fi
442 # try to delete a file with a patch that doesn't match
443 jot 100 > $testroot/wt/numbers
444 (cd $testroot/wt && got add numbers && got commit -m 'add numbers') \
445 >/dev/null
446 ret=$?
447 if [ $ret -ne 0 ]; then
448 test_done $testroot $ret
449 return 1
450 fi
452 cat <<EOF > $testroot/wt/patch
453 --- numbers
454 +++ /dev/null
455 @@ -1,9 +0,0 @@
456 -1
457 -2
458 -3
459 -4
460 -5
461 -6
462 -7
463 -8
464 -9
465 EOF
467 (cd $testroot/wt && got patch patch) > /dev/null 2> $testroot/stderr
468 ret=$?
469 if [ $ret -eq 0 ]; then # should fail
470 test_done $testroot 1
471 return 1
472 fi
474 echo "got: patch doesn't apply" > $testroot/stderr.expected
475 cmp -s $testroot/stderr.expected $testroot/stderr
476 ret=$?
477 if [ $ret -ne 0 ]; then
478 diff -u $testroot/stderr.expected $testroot/stderr
479 fi
480 test_done $testroot $ret
483 test_patch_malformed() {
484 local testroot=`test_init patch_malformed`
486 got checkout $testroot/repo $testroot/wt > /dev/null
487 ret=$?
488 if [ $ret -ne 0 ]; then
489 test_done $testroot $ret
490 return 1
491 fi
493 # missing "@@"
494 cat <<EOF > $testroot/wt/patch
495 --- alpha
496 +++ alpha
497 @@ -1 +1,2
498 +hatsuseno
499 alpha
500 EOF
502 echo -n > $testroot/stdout.expected
503 echo "got: malformed patch" > $testroot/stderr.expected
505 (cd $testroot/wt && got patch patch) \
506 > $testroot/stdout \
507 2> $testroot/stderr
508 ret=$?
509 if [ $ret -eq 0 ]; then
510 echo "got managed to apply an invalid patch"
511 test_done $testroot 1
512 return 1
513 fi
515 cmp -s $testroot/stdout.expected $testroot/stdout
516 ret=$?
517 if [ $ret -ne 0 ]; then
518 diff -u $testroot/stdout.expected $testroot/stdout
519 test_done $testroot $ret
520 return 1
521 fi
523 cmp -s $testroot/stderr.expected $testroot/stderr
524 ret=$?
525 if [ $ret -ne 0 ]; then
526 diff -u $testroot/stderr.expected $testroot/stderr
527 test_done $testroot $ret
528 return 1
529 fi
531 # wrong first character
532 cat <<EOF > $testroot/wt/patch
533 --- alpha
534 +++ alpha
535 @@ -1 +1,2 @@
536 +hatsuseno
537 alpha
538 EOF
540 (cd $testroot/wt && got patch patch) \
541 > $testroot/stdout \
542 2> $testroot/stderr
543 ret=$?
544 if [ $ret -eq 0 ]; then
545 echo "got managed to apply an invalid patch"
546 test_done $testroot 1
547 return 1
548 fi
550 cmp -s $testroot/stdout.expected $testroot/stdout
551 ret=$?
552 if [ $ret -ne 0 ]; then
553 diff -u $testroot/stdout.expected $testroot/stdout
554 test_done $testroot $ret
555 return 1
556 fi
558 cmp -s $testroot/stderr.expected $testroot/stderr
559 ret=$?
560 if [ $ret -ne 0 ]; then
561 diff -u $testroot/stderr.expected $testroot/stderr
562 test_done $testroot $ret
563 return 1
564 fi
566 test_done $testroot $ret
569 test_patch_no_patch() {
570 local testroot=`test_init patch_no_patch`
572 got checkout $testroot/repo $testroot/wt > /dev/null
573 ret=$?
574 if [ $ret -ne 0 ]; then
575 test_done $testroot $ret
576 return 1
577 fi
579 cat <<EOF > $testroot/wt/patch
580 hello world!
581 ...
583 some other nonsense
584 ...
586 there's no patch in here!
587 EOF
589 echo -n > $testroot/stdout.expected
590 echo "got: no patch found" > $testroot/stderr.expected
592 (cd $testroot/wt && got patch patch) \
593 > $testroot/stdout \
594 2> $testroot/stderr
595 ret=$?
596 if [ $ret -eq 0 ]; then # should fail
597 test_done $testroot 1
598 return 1
599 fi
601 cmp -s $testroot/stdout.expected $testroot/stdout
602 ret=$?
603 if [ $ret -ne 0 ]; then
604 diff -u $testroot/stdout.expected $testroot/stdout
605 test_done $testroot $ret
606 return 1
607 fi
609 cmp -s $testroot/stderr.expected $testroot/stderr
610 ret=$?
611 if [ $ret -ne 0 ]; then
612 diff -u $testroot/stderr.expected $testroot/stderr
613 test_done $testroot $ret
614 return 1
615 fi
617 test_done $testroot $ret
620 test_patch_equals_for_context() {
621 local testroot=`test_init patch_prepend_line`
623 got checkout $testroot/repo $testroot/wt > /dev/null
624 ret=$?
625 if [ $ret -ne 0 ]; then
626 test_done $testroot $ret
627 return 1
628 fi
630 cat <<EOF > $testroot/wt/patch
631 --- alpha
632 +++ alpha
633 @@ -1 +1,2 @@
634 +hatsuseno
635 =alpha
636 EOF
638 echo "M alpha" > $testroot/stdout.expected
640 (cd $testroot/wt && got patch patch) > $testroot/stdout
641 ret=$?
642 if [ $ret -ne 0 ]; then
643 test_done $testroot $ret
644 return 1
645 fi
647 cmp -s $testroot/stdout.expected $testroot/stdout
648 ret=$?
649 if [ $ret -ne 0 ]; then
650 diff -u $testroot/stdout.expected $testroot/stdout
651 test_done $testroot $ret
652 return 1
653 fi
655 echo hatsuseno > $testroot/wt/alpha.expected
656 echo alpha >> $testroot/wt/alpha.expected
657 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
658 ret=$?
659 if [ $ret -ne 0 ]; then
660 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
661 fi
662 test_done $testroot $ret
665 test_patch_rename() {
666 local testroot=`test_init patch_rename`
668 got checkout $testroot/repo $testroot/wt > /dev/null
669 ret=$?
670 if [ $ret -ne 0 ]; then
671 test_done $testroot $ret
672 return 1
673 fi
675 cat <<EOF > $testroot/wt/patch
676 --- alpha
677 +++ eta
678 @@ -0,0 +0,0 @@
679 EOF
681 echo 'D alpha' > $testroot/stdout.expected
682 echo 'A eta' >> $testroot/stdout.expected
684 (cd $testroot/wt && got patch patch) > $testroot/stdout
685 ret=$?
686 if [ $ret -ne 0 ]; then
687 test_done $testroot $ret
688 return 1
689 fi
691 cmp -s $testroot/stdout.expected $testroot/stdout
692 ret=$?
693 if [ $ret -ne 0 ]; then
694 diff -u $testroot/stdout.expected $testroot/stdout
695 test_done $testroot $ret
696 return 1
697 fi
699 if [ -f $testroot/wt/alpha ]; then
700 echo "alpha was not removed" >&2
701 test_done $testroot 1
702 return 1
703 fi
704 if [ ! -f $testroot/wt/eta ]; then
705 echo "eta was not created" >&2
706 test_done $testroot 1
707 return 1
708 fi
710 echo alpha > $testroot/wt/eta.expected
711 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
712 ret=$?
713 if [ $ret -ne 0 ]; then
714 diff -u $testroot/wt/eta.expected $testroot/wt/eta
715 test_done $testroot $ret
716 return 1
717 fi
719 # revert the changes and try again with a rename + edit
720 (cd $testroot/wt && got revert alpha eta) > /dev/null
721 ret=$?
722 if [ $ret -ne 0 ]; then
723 test_done $testroot $ret
724 return 1
725 fi
726 rm $testroot/wt/eta
728 cat <<EOF > $testroot/wt/patch
729 --- alpha
730 +++ eta
731 @@ -1 +1,2 @@
732 alpha
733 +but now is eta
734 EOF
736 (cd $testroot/wt && got patch patch) > $testroot/stdout
737 ret=$?
738 if [ $ret -ne 0 ]; then
739 test_done $testroot $ret
740 return 1
741 fi
743 cmp -s $testroot/stdout.expected $testroot/stdout
744 ret=$?
745 if [ $ret -ne 0 ]; then
746 diff -u $testroot/stdout.expected $testroot/stdout
747 test_done $testroot $ret
748 return 1
749 fi
751 if [ -f $testroot/wt/alpha ]; then
752 echo "alpha was not removed" >&2
753 test_done $testroot 1
754 return 1
755 fi
756 if [ ! -f $testroot/wt/eta ]; then
757 echo "eta was not created" >&2
758 test_done $testroot 1
759 return 1
760 fi
762 echo alpha > $testroot/wt/eta.expected
763 echo 'but now is eta' >> $testroot/wt/eta.expected
764 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
765 ret=$?
766 if [ $ret -ne 0 ]; then
767 diff -u $testroot/wt/eta.expected $testroot/wt/eta
768 fi
769 test_done $testroot $ret
772 test_patch_illegal_status() {
773 local testroot=`test_init patch_illegal_status`
775 got checkout $testroot/repo $testroot/wt > /dev/null
776 ret=$?
777 if [ $ret -ne 0 ]; then
778 test_done $testroot $ret
779 return 1
780 fi
782 # edit an non-existent and unknown file
783 cat <<EOF > $testroot/wt/patch
784 --- iota
785 +++ iota
786 @@ -1 +1 @@
787 - iota
788 + IOTA
789 EOF
791 (cd $testroot/wt && got patch patch) > /dev/null \
792 2> $testroot/stderr
793 ret=$?
794 if [ $ret -eq 0 ]; then
795 echo "edited a missing file" >&2
796 test_done $testroot $ret
797 return 1
798 fi
800 echo "got: iota: No such file or directory" \
801 > $testroot/stderr.expected
802 cmp -s $testroot/stderr.expected $testroot/stderr
803 ret=$?
804 if [ $ret -ne 0 ]; then
805 diff -u $testroot/stderr.expected $testroot/stderr
806 test_done $testroot $ret
807 return 1
808 fi
810 # create iota and re-try
811 echo iota > $testroot/wt/iota
813 (cd $testroot/wt && got patch patch) > /dev/null \
814 2> $testroot/stderr
815 ret=$?
816 if [ $ret -eq 0 ]; then
817 echo "patched an unknown file" >&2
818 test_done $testroot $ret
819 return 1
820 fi
822 echo "got: iota: file has unexpected status" \
823 > $testroot/stderr.expected
824 cmp -s $testroot/stderr.expected $testroot/stderr
825 ret=$?
826 if [ $ret -ne 0 ]; then
827 diff -u $testroot/stderr.expected $testroot/stderr
828 test_done $testroot $ret
829 return 1
830 fi
832 rm $testroot/wt/iota
833 ret=$?
834 if [ $ret -ne 0 ]; then
835 test_done $testroot $ret
836 return 1
837 fi
839 # edit obstructed file
840 rm $testroot/wt/alpha
841 mkdir $testroot/wt/alpha
842 cat <<EOF > $testroot/wt/patch
843 --- alpha
844 +++ alpha
845 @@ -1 +1,2 @@
846 alpha
847 +was edited
848 EOF
850 (cd $testroot/wt && got patch patch) > /dev/null \
851 2> $testroot/stderr
852 ret=$?
853 if [ $ret -eq 0 ]; then
854 echo "edited a missing file" >&2
855 test_done $testroot $ret
856 return 1
857 fi
859 echo "got: alpha: file has unexpected status" \
860 > $testroot/stderr.expected
861 cmp -s $testroot/stderr.expected $testroot/stderr
862 ret=$?
863 if [ $ret -ne 0 ]; then
864 diff -u $testroot/stderr.expected $testroot/stderr
865 test_done $testroot $ret
866 return 1
867 fi
869 # delete an unknown file
870 cat <<EOF > $testroot/wt/patch
871 --- iota
872 +++ /dev/null
873 @@ -1 +0,0 @@
874 -iota
875 EOF
877 (cd $testroot/wt && got patch patch) > /dev/null \
878 2> $testroot/stderr
879 ret=$?
880 if [ $ret -eq 0 ]; then
881 echo "deleted a missing file?" >&2
882 test_done $testroot $ret
883 return 1
884 fi
886 echo "got: iota: No such file or directory" \
887 > $testroot/stderr.expected
888 cmp -s $testroot/stderr.expected $testroot/stderr
889 ret=$?
890 if [ $ret -eq 0 ]; then
891 diff -u $testroot/stderr.expected $testroot/stderr
892 test_done $testroot $ret
893 return 1
894 fi
896 # try again with iota in place but still not registered
897 echo iota > $testroot/wt/iota
898 (cd $testroot/wt && got patch patch) > /dev/null \
899 2> $testroot/stderr
900 ret=$?
901 if [ $ret -eq 0 ]; then
902 echo "deleted an unversioned file?" >&2
903 test_done $testroot $ret
904 return 1
905 fi
907 echo "got: iota: file has unexpected status" \
908 > $testroot/stderr.expected
909 cmp -s $testroot/stderr.expected $testroot/stderr
910 ret=$?
911 if [ $ret -eq 0 ]; then
912 diff -u $testroot/stderr.expected $testroot/stderr
913 fi
914 test_done $testroot $ret
917 test_patch_nop() {
918 local testroot=`test_init patch_nop`
920 got checkout $testroot/repo $testroot/wt > /dev/null
921 ret=$?
922 if [ $ret -ne 0 ]; then
923 test_done $testroot $ret
924 return 1
925 fi
927 cat <<EOF > $testroot/wt/patch
928 --- alpha
929 +++ alpha
930 @@ -1 +1 @@
931 -alpha
932 +cafe alpha
933 --- beta
934 +++ /dev/null
935 @@ -1 +0,0 @@
936 -beta
937 --- gamma/delta
938 +++ gamma/delta.new
939 @@ -1 +1 @@
940 -delta
941 +delta updated and renamed!
942 EOF
944 (cd $testroot/wt && got patch -n patch)
945 ret=$?
946 if [ $ret -ne 0 ]; then
947 test_done $testroot $ret
948 return 1
949 fi
951 # remove the patch to avoid the ? entry
952 rm $testroot/wt/patch
954 (cd $testroot/wt && got status) > $testroot/stdout
955 ret=$?
956 if [ $ret -ne 0 ]; then
957 test_done $testroot $ret
958 return 1
959 fi
961 echo -n > $testroot/stdout.expected
962 cmp -s $testroot/stdout.expected $testroot/stdout
963 ret=$?
964 if [ $ret -ne 0 ]; then
965 diff -u $testroot/stdout.expected $testroot/stdout
966 fi
967 test_done $testroot $ret
970 test_parseargs "$@"
971 run_test test_patch_simple_add_file
972 run_test test_patch_simple_rm_file
973 run_test test_patch_simple_edit_file
974 run_test test_patch_prepend_line
975 run_test test_patch_replace_line
976 run_test test_patch_multiple_hunks
977 run_test test_patch_multiple_files
978 run_test test_patch_dont_apply
979 run_test test_patch_malformed
980 run_test test_patch_no_patch
981 run_test test_patch_equals_for_context
982 run_test test_patch_rename
983 run_test test_patch_illegal_status
984 run_test test_patch_nop