3 # Copyright (c) 2022 Omar Polo <op@openbsd.org>
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.
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.
19 test_patch_simple_add_file() {
20 local testroot=`test_init patch_simple_add_file`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ $ret -ne 0 ]; then
25 test_done $testroot $ret
29 cat <<EOF > $testroot/wt/patch
36 (cd $testroot/wt && got patch patch) > $testroot/stdout
38 if [ $ret -ne 0 ]; then
39 test_done $testroot $ret
43 echo "A eta" > $testroot/stdout.expected
44 cmp -s $testroot/stdout.expected $testroot/stdout
46 if [ $ret -ne 0 ]; then
47 diff -u $testroot/stdout.expected $testroot/stdout
48 test_done $testroot $ret
52 echo eta > $testroot/wt/eta.expected
53 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
55 if [ $ret -ne 0 ]; then
56 diff -u $testroot/wt/eta.expected $testroot/wt/eta
58 test_done $testroot $ret
61 test_patch_simple_rm_file() {
62 local testroot=`test_init patch_simple_rm_file`
64 got checkout $testroot/repo $testroot/wt > /dev/null
66 if [ $ret -ne 0 ]; then
67 test_done $testroot $ret
71 cat <<EOF > $testroot/wt/patch
78 echo "D alpha" > $testroot/stdout.expected
80 (cd $testroot/wt && got patch patch) > $testroot/stdout
82 if [ $ret -ne 0 ]; then
83 test_done $testroot $ret
87 cmp -s $testroot/stdout.expected $testroot/stdout
89 if [ $ret -ne 0 ]; then
90 diff -u $testroot/stdout.expected $testroot/stdout
91 test_done $testroot $ret
95 if [ -f $testroot/wt/alpha ]; then
97 echo "alpha still exists!"
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
107 if [ $ret -ne 0 ]; then
108 test_done $testroot $ret
112 cat <<EOF > $testroot/wt/patch
117 +alpha is my favourite character
120 echo "M alpha" > $testroot/stdout.expected
122 (cd $testroot/wt && got patch patch) > $testroot/stdout
124 if [ $ret -ne 0 ]; then
125 test_done $testroot $ret
129 cmp -s $testroot/stdout.expected $testroot/stdout
131 if [ $ret -ne 0 ]; then
132 diff -u $testroot/stdout.expected $testroot/stdout
133 test_done $testroot $ret
137 echo 'alpha is my favourite character' > $testroot/wt/alpha.expected
138 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
140 if [ $ret -ne 0 ]; then
141 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
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
151 if [ $ret -ne 0 ]; then
152 test_done $testroot $ret
156 cat <<EOF > $testroot/wt/patch
164 echo "M alpha" > $testroot/stdout.expected
166 (cd $testroot/wt && got patch patch) > $testroot/stdout
168 if [ $ret -ne 0 ]; then
169 test_done $testroot $ret
173 cmp -s $testroot/stdout.expected $testroot/stdout
175 if [ $ret -ne 0 ]; then
176 diff -u $testroot/stdout.expected $testroot/stdout
177 test_done $testroot $ret
181 echo hatsuseno > $testroot/wt/alpha.expected
182 echo alpha >> $testroot/wt/alpha.expected
183 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
185 if [ $ret -ne 0 ]; then
186 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
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
196 if [ $ret -ne 0 ]; then
197 test_done $testroot $ret
201 jot 10 > $testroot/wt/numbers
202 (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
205 if [ $ret -ne 0 ]; then
206 test_done $testroot $ret
210 cat <<EOF > $testroot/wt/patch
224 echo "M numbers" > $testroot/stdout.expected
226 (cd $testroot/wt && got patch patch) > $testroot/stdout
228 if [ $ret -ne 0 ]; then
229 test_done $testroot $ret
233 cmp -s $testroot/stdout.expected $testroot/stdout
235 if [ $ret -ne 0 ]; then
236 diff -u $testroot/stdout.expected $testroot/stdout
237 test_done $testroot $ret
241 jot 10 | sed 's/6/foo/' > $testroot/wt/numbers.expected
242 cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
244 if [ $ret -ne 0 ]; then
245 diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
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
255 if [ $ret -ne 0 ]; then
256 test_done $testroot $ret
260 jot 100 > $testroot/wt/numbers
261 (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
264 if [ $ret -ne 0 ]; then
265 test_done $testroot $ret
269 cat <<EOF > $testroot/wt/patch
299 echo "M numbers" > $testroot/stdout.expected
301 (cd $testroot/wt && got patch patch) > $testroot/stdout
303 if [ $ret -ne 0 ]; then
304 test_done $testroot $ret
308 cmp -s $testroot/stdout.expected $testroot/stdout
310 if [ $ret -ne 0 ]; then
311 diff -u $testroot/stdout.expected $testroot/stdout
312 test_done $testroot $ret
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
324 if [ $ret -ne 0 ]; then
325 diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
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
335 if [ $ret -ne 0 ]; then
336 test_done $testroot $ret
340 cat <<EOF > $testroot/wt/patch
341 --- alpha Mon Mar 7 19:02:07 2022
342 +++ alpha Mon Mar 7 19:01:53 2022
347 --- beta Mon Mar 7 19:02:11 2022
348 +++ beta Mon Mar 7 19:01:46 2022
353 --- gamma/delta Mon Mar 7 19:02:17 2022
354 +++ gamma/delta Mon Mar 7 19:01:37 2022
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
366 if [ $ret -ne 0 ]; then
367 test_done $testroot $ret
371 cmp -s $testroot/stdout.expected $testroot/stdout
373 if [ $ret -ne 0 ]; then
374 diff -u $testroot/stdout.expected $testroot/stdout
375 test_done $testroot $ret
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
386 if [ $ret -ne 0 ]; then
387 diff -u $testroot/wt/$f.expected $testroot/wt/$f
388 test_done $testroot $ret
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
401 if [ $ret -ne 0 ]; then
402 test_done $testroot $ret
406 jot 100 > $testroot/wt/numbers
407 (cd $testroot/wt && got add numbers && got commit -m 'add numbers') \
410 if [ $ret -ne 0 ]; then
411 test_done $testroot $ret
415 cat <<EOF > $testroot/wt/patch
435 (cd $testroot/wt && got patch patch) > $testroot/stdout 2> /dev/null
437 if [ $ret -eq 0 ]; then # should fail
438 test_done $testroot 1
442 cat <<EOF > $testroot/stdout.expected
444 @@ -1,1 +1,2 @@ hunk failed to apply
446 @@ -1,9 +0,0 @@ hunk failed to apply
449 cmp -s $testroot/stdout.expected $testroot/stdout
451 if [ $ret -ne 0 ]; then
452 diff -u $testroot/stdout.expected $testroot/stdout
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
462 if [ $ret -ne 0 ]; then
463 test_done $testroot $ret
468 cat <<EOF > $testroot/wt/patch
476 echo -n > $testroot/stdout.expected
477 echo "got: malformed patch" > $testroot/stderr.expected
479 (cd $testroot/wt && got patch patch) \
483 if [ $ret -eq 0 ]; then
484 echo "got managed to apply an invalid patch"
485 test_done $testroot 1
489 cmp -s $testroot/stdout.expected $testroot/stdout
491 if [ $ret -ne 0 ]; then
492 diff -u $testroot/stdout.expected $testroot/stdout
493 test_done $testroot $ret
497 cmp -s $testroot/stderr.expected $testroot/stderr
499 if [ $ret -ne 0 ]; then
500 diff -u $testroot/stderr.expected $testroot/stderr
501 test_done $testroot $ret
505 # wrong first character
506 cat <<EOF > $testroot/wt/patch
514 (cd $testroot/wt && got patch patch) \
518 if [ $ret -eq 0 ]; then
519 echo "got managed to apply an invalid patch"
520 test_done $testroot 1
524 cmp -s $testroot/stdout.expected $testroot/stdout
526 if [ $ret -ne 0 ]; then
527 diff -u $testroot/stdout.expected $testroot/stdout
528 test_done $testroot $ret
532 cmp -s $testroot/stderr.expected $testroot/stderr
534 if [ $ret -ne 0 ]; then
535 diff -u $testroot/stderr.expected $testroot/stderr
536 test_done $testroot $ret
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
548 if [ $ret -ne 0 ]; then
549 test_done $testroot $ret
553 cat <<EOF > $testroot/wt/patch
560 there's no patch in here!
563 echo -n > $testroot/stdout.expected
564 echo "got: no patch found" > $testroot/stderr.expected
566 (cd $testroot/wt && got patch patch) \
570 if [ $ret -eq 0 ]; then # should fail
571 test_done $testroot 1
575 cmp -s $testroot/stdout.expected $testroot/stdout
577 if [ $ret -ne 0 ]; then
578 diff -u $testroot/stdout.expected $testroot/stdout
579 test_done $testroot $ret
583 cmp -s $testroot/stderr.expected $testroot/stderr
585 if [ $ret -ne 0 ]; then
586 diff -u $testroot/stderr.expected $testroot/stderr
587 test_done $testroot $ret
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
599 if [ $ret -ne 0 ]; then
600 test_done $testroot $ret
604 cat <<EOF > $testroot/wt/patch
612 echo "M alpha" > $testroot/stdout.expected
614 (cd $testroot/wt && got patch patch) > $testroot/stdout
616 if [ $ret -ne 0 ]; then
617 test_done $testroot $ret
621 cmp -s $testroot/stdout.expected $testroot/stdout
623 if [ $ret -ne 0 ]; then
624 diff -u $testroot/stdout.expected $testroot/stdout
625 test_done $testroot $ret
629 echo hatsuseno > $testroot/wt/alpha.expected
630 echo alpha >> $testroot/wt/alpha.expected
631 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
633 if [ $ret -ne 0 ]; then
634 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
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
644 if [ $ret -ne 0 ]; then
645 test_done $testroot $ret
649 cat <<EOF > $testroot/wt/patch
650 diff --git a/alpha b/eta
656 echo 'D alpha' > $testroot/stdout.expected
657 echo 'A eta' >> $testroot/stdout.expected
659 (cd $testroot/wt && got patch patch) > $testroot/stdout
661 if [ $ret -ne 0 ]; then
662 test_done $testroot $ret
666 cmp -s $testroot/stdout.expected $testroot/stdout
668 if [ $ret -ne 0 ]; then
669 diff -u $testroot/stdout.expected $testroot/stdout
670 test_done $testroot $ret
674 if [ -f $testroot/wt/alpha ]; then
675 echo "alpha was not removed" >&2
676 test_done $testroot 1
679 if [ ! -f $testroot/wt/eta ]; then
680 echo "eta was not created" >&2
681 test_done $testroot 1
685 echo alpha > $testroot/wt/eta.expected
686 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
688 if [ $ret -ne 0 ]; then
689 diff -u $testroot/wt/eta.expected $testroot/wt/eta
690 test_done $testroot $ret
694 # revert the changes and try again with a rename + edit
695 (cd $testroot/wt && got revert alpha eta) > /dev/null
697 if [ $ret -ne 0 ]; then
698 test_done $testroot $ret
703 cat <<EOF > $testroot/wt/patch
704 diff --git a/alpha b/eta
712 (cd $testroot/wt && got patch patch) > $testroot/stdout
714 if [ $ret -ne 0 ]; then
715 test_done $testroot $ret
719 cmp -s $testroot/stdout.expected $testroot/stdout
721 if [ $ret -ne 0 ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
723 test_done $testroot $ret
727 if [ -f $testroot/wt/alpha ]; then
728 echo "alpha was not removed" >&2
729 test_done $testroot 1
732 if [ ! -f $testroot/wt/eta ]; then
733 echo "eta was not created" >&2
734 test_done $testroot 1
738 echo alpha > $testroot/wt/eta.expected
739 echo 'but now is eta' >> $testroot/wt/eta.expected
740 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
742 if [ $ret -ne 0 ]; then
743 diff -u $testroot/wt/eta.expected $testroot/wt/eta
745 test_done $testroot $ret
748 test_patch_illegal_status() {
749 local testroot=`test_init patch_illegal_status`
751 got checkout $testroot/repo $testroot/wt > /dev/null
753 if [ $ret -ne 0 ]; then
754 test_done $testroot $ret
758 # try to patch an obstructed file, add a versioned one, edit a
759 # non existent file and an unversioned one, and remove a
761 cat <<EOF > $testroot/wt/patch
787 echo kappa > $testroot/wt/kappa
788 rm $testroot/wt/alpha
789 mkdir $testroot/wt/alpha
791 (cd $testroot/wt && got patch patch) > $testroot/stdout \
794 if [ $ret -eq 0 ]; then
795 echo "edited a missing file" >&2
796 test_done $testroot $ret
800 cat <<EOF > $testroot/stdout.expected
808 cat <<EOF > $testroot/stderr.expected
809 got: alpha: file has unexpected status
810 got: beta: file has unexpected status
811 got: iota: No such file or directory
812 got: kappa: file has unexpected status
813 got: lambda: No such file or directory
814 got: patch failed to apply
817 cmp -s $testroot/stdout.expected $testroot/stdout
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
821 test_done $testroot $ret
825 cmp -s $testroot/stderr.expected $testroot/stderr
827 if [ $ret -ne 0 ]; then
828 diff -u $testroot/stderr.expected $testroot/stderr
829 test_done $testroot $ret
833 (cd $testroot/wt && got status) > $testroot/stdout
834 cat <<EOF > $testroot/stdout.expected
840 cmp -s $testroot/stdout.expected $testroot/stdout
842 if [ $ret -ne 0 ]; then
843 diff -u $testroot/stdout.expected $testroot/stdout
845 test_done $testroot $ret
849 local testroot=`test_init patch_nop`
851 got checkout $testroot/repo $testroot/wt > /dev/null
853 if [ $ret -ne 0 ]; then
854 test_done $testroot $ret
858 cat <<EOF > $testroot/wt/patch
868 diff --git a/gamma/delta b/gamma/delta.new
873 +delta updated and renamed!
876 (cd $testroot/wt && got patch -n patch)
878 if [ $ret -ne 0 ]; then
879 test_done $testroot $ret
883 # remove the patch to avoid the ? entry
884 rm $testroot/wt/patch
886 (cd $testroot/wt && got status) > $testroot/stdout
888 if [ $ret -ne 0 ]; then
889 test_done $testroot $ret
893 echo -n > $testroot/stdout.expected
894 cmp -s $testroot/stdout.expected $testroot/stdout
896 if [ $ret -ne 0 ]; then
897 diff -u $testroot/stdout.expected $testroot/stdout
899 test_done $testroot $ret
902 test_patch_preserve_perm() {
903 local testroot=`test_init patch_preserve_perm`
905 got checkout $testroot/repo $testroot/wt > /dev/null
907 if [ $ret -ne 0 ]; then
908 test_done $testroot $ret
912 chmod +x $testroot/wt/alpha
913 (cd $testroot/wt && got commit -m 'alpha executable') > /dev/null
915 if [ $ret -ne 0 ]; then
916 test_done $testroot $ret
920 cat <<EOF > $testroot/wt/patch
928 (cd $testroot/wt && got patch patch) > /dev/null
930 if [ $ret -ne 0 ]; then
931 test_done $testroot $ret
935 if [ ! -x $testroot/wt/alpha ]; then
936 echo "alpha is no more executable!" >&2
937 test_done $testroot 1
940 test_done $testroot 0
943 test_patch_create_dirs() {
944 local testroot=`test_init patch_create_dirs`
946 got checkout $testroot/repo $testroot/wt > /dev/null
948 if [ $ret -ne 0 ]; then
949 test_done $testroot $ret
953 cat <<EOF > $testroot/wt/patch
955 +++ iota/kappa/lambda
960 (cd $testroot/wt && got patch patch) > $testroot/stdout
962 if [ $ret -ne 0 ]; then
963 test_done $testroot $ret
967 echo 'A iota/kappa/lambda' >> $testroot/stdout.expected
968 cmp -s $testroot/stdout.expected $testroot/stdout
970 if [ $ret -ne 0 ]; then
971 diff -u $testroot/stdout.expected $testroot/stdout
972 test_done $testroot $ret
976 if [ ! -f $testroot/wt/iota/kappa/lambda ]; then
977 echo "file not created!" >&2
978 test_done $testroot $ret
981 test_done $testroot 0
984 test_patch_with_offset() {
985 local testroot=`test_init patch_with_offset`
987 got checkout $testroot/repo $testroot/wt > /dev/null
989 if [ $ret -ne 0 ]; then
990 test_done $testroot $ret
994 cat <<EOF > $testroot/wt/patch
1017 jot 100 > $testroot/wt/numbers
1018 ed $testroot/wt/numbers <<EOF > /dev/null 2> /dev/null
1025 (cd $testroot/wt && got add numbers && got commit -m '+numbers') \
1028 if [ $ret -ne 0 ]; then
1029 test_done $testroot $ret
1033 (cd $testroot/wt && got patch patch) > $testroot/stdout
1035 if [ $ret -ne 0 ]; then
1036 test_done $testroot/wt $ret
1040 cat <<EOF > $testroot/stdout.expected
1042 @@ -47,7 +47,7 @@ applied with offset -10
1043 @@ -87,7 +87,7 @@ applied with offset 10
1046 cmp -s $testroot/stdout.expected $testroot/stdout
1048 if [ $ret -ne 0 ]; then
1049 diff -u $testroot/stdout.expected $testroot/stdout
1051 test_done $testroot $ret
1054 test_patch_prefer_new_path() {
1055 local testroot=`test_init patch_orig`
1057 got checkout $testroot/repo $testroot/wt > /dev/null
1059 if [ $ret -ne 0 ]; then
1060 test_done $testroot $ret
1064 cat <<EOF > $testroot/wt/patch
1072 (cd $testroot/wt && got patch patch) > $testroot/stdout
1074 if [ $ret -ne 0 ]; then
1075 test_done $testroot $ret
1079 echo 'M alpha' > $testroot/stdout.expected
1080 cmp -s $testroot/stdout.expected $testroot/stdout
1082 if [ $ret -ne 0 ]; then
1083 diff -u $testroot/stdout.expected $testroot/stdout
1085 test_done $testroot $ret
1088 test_patch_no_newline() {
1089 local testroot=`test_init patch_no_newline`
1091 got checkout $testroot/repo $testroot/wt > /dev/null
1093 if [ $ret -ne 0 ]; then
1094 test_done $testroot $ret
1098 cat <<EOF > $testroot/wt/patch
1103 \ No newline at end of file
1106 (cd $testroot/wt && got patch patch) > $testroot/stdout
1108 if [ $ret -ne 0 ]; then
1109 test_done $testroot $ret
1113 echo "A eta" > $testroot/stdout.expected
1114 cmp -s $testroot/stdout.expected $testroot/stdout
1116 if [ $ret -ne 0 ]; then
1117 diff -u $testroot/stdout.expected $testroot/stdout
1118 test_done $testroot $ret
1122 echo -n eta > $testroot/wt/eta.expected
1123 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1125 if [ $ret -ne 0 ]; then
1126 diff -u $testroot/wt/eta.expected $testroot/wt/eta
1127 test_done $testroot $ret
1131 (cd $testroot/wt && got commit -m 'add eta') > /dev/null
1133 if [ $ret -ne 0 ]; then
1134 test_done $testroot $ret
1138 cat <<EOF > $testroot/wt/patch
1143 \ No newline at end of file
1145 \ No newline at end of file
1148 (cd $testroot/wt && got patch patch) > $testroot/stdout
1150 if [ $ret -ne 0 ]; then
1151 test_done $testroot $ret
1155 echo "M eta" > $testroot/stdout.expected
1156 cmp -s $testroot/stdout.expected $testroot/stdout
1158 if [ $ret -ne 0 ]; then
1159 diff -u $testroot/stdout.expected $testroot/stdout
1160 test_done $testroot $ret
1164 echo -n ETA > $testroot/wt/eta.expected
1165 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1167 if [ $ret -ne 0 ]; then
1168 diff -u $testroot/wt/eta.expected $testroot/wt/eta
1169 test_done $testroot $ret
1173 (cd $testroot/wt && got commit -m 'edit eta') > /dev/null
1175 if [ $ret -ne 0 ]; then
1176 test_done $testroot $ret
1180 cat <<EOF > $testroot/wt/patch
1185 \ No newline at end of file
1189 (cd $testroot/wt && got patch patch) > $testroot/stdout
1191 if [ $ret -ne 0 ]; then
1192 test_done $testroot $ret
1196 echo "M eta" > $testroot/stdout.expected
1197 cmp -s $testroot/stdout.expected $testroot/stdout
1199 if [ $ret -ne 0 ]; then
1200 diff -u $testroot/stdout.expected $testroot/stdout
1201 test_done $testroot $ret
1205 echo eta > $testroot/wt/eta.expected
1206 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1208 if [ $ret -ne 0 ]; then
1209 diff -u $testroot/wt/eta.expected $testroot/wt/eta
1211 test_done $testroot $ret
1214 test_patch_strip() {
1215 local testroot=`test_init patch_strip`
1217 got checkout $testroot/repo $testroot/wt > /dev/null
1219 if [ $ret -ne 0 ]; then
1220 test_done $testroot $ret
1224 cat <<EOF > $testroot/wt/patch
1225 --- foo/bar/alpha.orig
1232 (cd $testroot/wt && got patch -p2 patch) > $testroot/stdout
1234 if [ $ret -ne 0 ]; then
1235 test_done $testroot $ret
1239 echo "M alpha" >> $testroot/stdout.expected
1240 cmp -s $testroot/stdout.expected $testroot/stdout
1242 if [ $ret -ne 0 ]; then
1243 diff -u $testroot/stdout.expected $testroot/stdout
1244 test_done $testroot $ret
1248 (cd $testroot/wt && got revert alpha) > /dev/null 2>&1
1250 if [ $ret -ne 0 ]; then
1251 test_done $testroot $ret
1255 (cd $testroot/wt && got patch -p3 patch) \
1258 if [ $ret -eq 0 ]; then
1259 echo "stripped more components than available!"
1260 test_done $testroot 1
1264 cat <<EOF > $testroot/stderr.expected
1265 got: can't strip 1 path-components from foo/bar/alpha: bad path
1268 cmp -s $testroot/stderr.expected $testroot/stderr
1270 if [ $ret -ne 0 ]; then
1271 diff -u $testroot/stderr.expected $testroot/stderr
1273 test_done $testroot 0
1277 run_test test_patch_simple_add_file
1278 run_test test_patch_simple_rm_file
1279 run_test test_patch_simple_edit_file
1280 run_test test_patch_prepend_line
1281 run_test test_patch_replace_line
1282 run_test test_patch_multiple_hunks
1283 run_test test_patch_multiple_files
1284 run_test test_patch_dont_apply
1285 run_test test_patch_malformed
1286 run_test test_patch_no_patch
1287 run_test test_patch_equals_for_context
1288 run_test test_patch_rename
1289 run_test test_patch_illegal_status
1290 run_test test_patch_nop
1291 run_test test_patch_preserve_perm
1292 run_test test_patch_create_dirs
1293 run_test test_patch_with_offset
1294 run_test test_patch_prefer_new_path
1295 run_test test_patch_no_newline
1296 run_test test_patch_strip