3 e9ce266e 2022-03-07 op # Copyright (c) 2022 Omar Polo <op@openbsd.org>
5 e9ce266e 2022-03-07 op # Permission to use, copy, modify, and distribute this software for any
6 e9ce266e 2022-03-07 op # purpose with or without fee is hereby granted, provided that the above
7 e9ce266e 2022-03-07 op # copyright notice and this permission notice appear in all copies.
9 e9ce266e 2022-03-07 op # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 e9ce266e 2022-03-07 op # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 e9ce266e 2022-03-07 op # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 e9ce266e 2022-03-07 op # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 e9ce266e 2022-03-07 op # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 e9ce266e 2022-03-07 op # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 e9ce266e 2022-03-07 op # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 e9ce266e 2022-03-07 op test_patch_simple_add_file() {
20 e9ce266e 2022-03-07 op local testroot=`test_init patch_simple_add_file`
22 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
24 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
25 e9ce266e 2022-03-07 op test_done $testroot $ret
29 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
36 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
38 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
39 e9ce266e 2022-03-07 op test_done $testroot $ret
43 e9ce266e 2022-03-07 op echo "A eta" > $testroot/stdout.expected
44 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
46 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
47 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
48 e9ce266e 2022-03-07 op test_done $testroot $ret
52 e9ce266e 2022-03-07 op echo eta > $testroot/wt/eta.expected
53 e9ce266e 2022-03-07 op cmp -s $testroot/wt/eta.expected $testroot/wt/eta
55 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
56 e9ce266e 2022-03-07 op diff -u $testroot/wt/eta.expected $testroot/wt/eta
58 e9ce266e 2022-03-07 op test_done $testroot $ret
61 e9ce266e 2022-03-07 op test_patch_simple_rm_file() {
62 e9ce266e 2022-03-07 op local testroot=`test_init patch_simple_rm_file`
64 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
66 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
67 e9ce266e 2022-03-07 op test_done $testroot $ret
71 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
78 e9ce266e 2022-03-07 op echo "D alpha" > $testroot/stdout.expected
80 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
82 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
83 e9ce266e 2022-03-07 op test_done $testroot $ret
87 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
89 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
90 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
91 e9ce266e 2022-03-07 op test_done $testroot $ret
95 e9ce266e 2022-03-07 op if [ -f $testroot/wt/alpha ]; then
97 e9ce266e 2022-03-07 op echo "alpha still exists!"
99 e9ce266e 2022-03-07 op test_done $testroot $ret
102 e9ce266e 2022-03-07 op test_patch_simple_edit_file() {
103 e9ce266e 2022-03-07 op local testroot=`test_init patch_simple_edit_file`
105 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
107 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
108 e9ce266e 2022-03-07 op test_done $testroot $ret
112 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
117 e9ce266e 2022-03-07 op +alpha is my favourite character
120 e9ce266e 2022-03-07 op echo "M alpha" > $testroot/stdout.expected
122 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
124 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
125 e9ce266e 2022-03-07 op test_done $testroot $ret
129 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
131 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
132 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
133 e9ce266e 2022-03-07 op test_done $testroot $ret
137 e9ce266e 2022-03-07 op echo 'alpha is my favourite character' > $testroot/wt/alpha.expected
138 e9ce266e 2022-03-07 op cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
140 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
141 e9ce266e 2022-03-07 op diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
143 e9ce266e 2022-03-07 op test_done $testroot $ret
146 e9ce266e 2022-03-07 op test_patch_prepend_line() {
147 e9ce266e 2022-03-07 op local testroot=`test_init patch_prepend_line`
149 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
151 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
152 e9ce266e 2022-03-07 op test_done $testroot $ret
156 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
159 e9ce266e 2022-03-07 op @@ -1 +1,2 @@
164 e9ce266e 2022-03-07 op echo "M alpha" > $testroot/stdout.expected
166 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
168 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
169 e9ce266e 2022-03-07 op test_done $testroot $ret
173 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
175 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
176 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
177 e9ce266e 2022-03-07 op test_done $testroot $ret
181 e9ce266e 2022-03-07 op echo hatsuseno > $testroot/wt/alpha.expected
182 e9ce266e 2022-03-07 op echo alpha >> $testroot/wt/alpha.expected
183 e9ce266e 2022-03-07 op cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
185 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
186 e9ce266e 2022-03-07 op diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
188 e9ce266e 2022-03-07 op test_done $testroot $ret
191 e9ce266e 2022-03-07 op test_patch_replace_line() {
192 e9ce266e 2022-03-07 op local testroot=`test_init patch_replace_line`
194 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
196 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
197 e9ce266e 2022-03-07 op test_done $testroot $ret
201 e9ce266e 2022-03-07 op jot 10 > $testroot/wt/numbers
202 e9ce266e 2022-03-07 op (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
205 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
206 e9ce266e 2022-03-07 op test_done $testroot $ret
210 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
213 e9ce266e 2022-03-07 op @@ -3,7 +3,7 @@
224 e9ce266e 2022-03-07 op echo "M numbers" > $testroot/stdout.expected
226 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
228 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
229 e9ce266e 2022-03-07 op test_done $testroot $ret
233 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
235 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
236 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
237 e9ce266e 2022-03-07 op test_done $testroot $ret
241 e9ce266e 2022-03-07 op jot 10 | sed 's/6/foo/' > $testroot/wt/numbers.expected
242 e9ce266e 2022-03-07 op cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
244 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
245 e9ce266e 2022-03-07 op diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
247 e9ce266e 2022-03-07 op test_done $testroot $ret
250 e9ce266e 2022-03-07 op test_patch_multiple_hunks() {
251 fd79e2e0 2022-03-08 op local testroot=`test_init patch_replace_multiple_hunks`
253 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
255 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
256 e9ce266e 2022-03-07 op test_done $testroot $ret
260 e9ce266e 2022-03-07 op jot 100 > $testroot/wt/numbers
261 e9ce266e 2022-03-07 op (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
264 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
265 e9ce266e 2022-03-07 op test_done $testroot $ret
269 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
272 e9ce266e 2022-03-07 op @@ -3,7 +3,7 @@
281 e9ce266e 2022-03-07 op @@ -57,7 +57,7 @@
290 e9ce266e 2022-03-07 op @@ -98,3 +98,6 @@
299 e9ce266e 2022-03-07 op echo "M numbers" > $testroot/stdout.expected
301 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
303 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
304 e9ce266e 2022-03-07 op test_done $testroot $ret
308 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
310 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
311 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
312 e9ce266e 2022-03-07 op test_done $testroot $ret
316 e9ce266e 2022-03-07 op jot 100 | sed -e 's/^6$/foo/' -e 's/^60$/foo foo/' \
317 e9ce266e 2022-03-07 op > $testroot/wt/numbers.expected
318 e9ce266e 2022-03-07 op echo "101" >> $testroot/wt/numbers.expected
319 e9ce266e 2022-03-07 op echo "102" >> $testroot/wt/numbers.expected
320 e9ce266e 2022-03-07 op echo "..." >> $testroot/wt/numbers.expected
322 e9ce266e 2022-03-07 op cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
324 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
325 e9ce266e 2022-03-07 op diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
327 e9ce266e 2022-03-07 op test_done $testroot $ret
330 e9ce266e 2022-03-07 op test_patch_multiple_files() {
331 e9ce266e 2022-03-07 op local testroot=`test_init patch_multiple_files`
333 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
335 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
336 e9ce266e 2022-03-07 op test_done $testroot $ret
340 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
341 e9ce266e 2022-03-07 op --- alpha Mon Mar 7 19:02:07 2022
342 e9ce266e 2022-03-07 op +++ alpha Mon Mar 7 19:01:53 2022
343 e9ce266e 2022-03-07 op @@ -1 +1,3 @@
347 e9ce266e 2022-03-07 op --- beta Mon Mar 7 19:02:11 2022
348 e9ce266e 2022-03-07 op +++ beta Mon Mar 7 19:01:46 2022
349 e9ce266e 2022-03-07 op @@ -1 +1,3 @@
353 e9ce266e 2022-03-07 op --- gamma/delta Mon Mar 7 19:02:17 2022
354 e9ce266e 2022-03-07 op +++ gamma/delta Mon Mar 7 19:01:37 2022
360 e9ce266e 2022-03-07 op echo "M alpha" > $testroot/stdout.expected
361 e9ce266e 2022-03-07 op echo "M beta" >> $testroot/stdout.expected
362 e9ce266e 2022-03-07 op echo "M gamma/delta" >> $testroot/stdout.expected
364 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
366 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
367 fd79e2e0 2022-03-08 op test_done $testroot $ret
371 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
373 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
374 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
375 e9ce266e 2022-03-07 op test_done $testroot $ret
379 e9ce266e 2022-03-07 op printf 'new\nalpha\navailable\n' > $testroot/wt/alpha.expected
380 e9ce266e 2022-03-07 op printf 'beta\nwas\nimproved\n' > $testroot/wt/beta.expected
381 e9ce266e 2022-03-07 op printf 'delta new\n' > $testroot/wt/gamma/delta.expected
383 e9ce266e 2022-03-07 op for f in alpha beta gamma/delta; do
384 e9ce266e 2022-03-07 op cmp -s $testroot/wt/$f.expected $testroot/wt/$f
386 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
387 e9ce266e 2022-03-07 op diff -u $testroot/wt/$f.expected $testroot/wt/$f
388 e9ce266e 2022-03-07 op test_done $testroot $ret
393 e9ce266e 2022-03-07 op test_done $testroot 0
396 e9ce266e 2022-03-07 op test_patch_dont_apply() {
397 e9ce266e 2022-03-07 op local testroot=`test_init patch_dont_apply`
399 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
401 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
402 e9ce266e 2022-03-07 op test_done $testroot $ret
406 5b67f96e 2022-03-13 op jot 100 > $testroot/wt/numbers
407 5b67f96e 2022-03-13 op (cd $testroot/wt && got add numbers && got commit -m 'add numbers') \
410 5b67f96e 2022-03-13 op if [ $ret -ne 0 ]; then
411 5b67f96e 2022-03-13 op test_done $testroot $ret
415 5b67f96e 2022-03-13 op cat <<EOF > $testroot/wt/patch
418 60aa1fa0 2022-03-17 op @@ -1 +1,2 @@
420 60aa1fa0 2022-03-17 op alpha something
422 5b67f96e 2022-03-13 op +++ /dev/null
423 5b67f96e 2022-03-13 op @@ -1,9 +0,0 @@
435 60aa1fa0 2022-03-17 op (cd $testroot/wt && got patch patch) > $testroot/stdout 2> /dev/null
437 5b67f96e 2022-03-13 op if [ $ret -eq 0 ]; then # should fail
438 5b67f96e 2022-03-13 op test_done $testroot 1
442 60aa1fa0 2022-03-17 op cat <<EOF > $testroot/stdout.expected
444 60aa1fa0 2022-03-17 op @@ -1,1 +1,2 @@ hunk failed to apply
446 60aa1fa0 2022-03-17 op @@ -1,9 +0,0 @@ hunk failed to apply
449 60aa1fa0 2022-03-17 op cmp -s $testroot/stdout.expected $testroot/stdout
451 5b67f96e 2022-03-13 op if [ $ret -ne 0 ]; then
452 60aa1fa0 2022-03-17 op diff -u $testroot/stdout.expected $testroot/stdout
454 e9ce266e 2022-03-07 op test_done $testroot $ret
457 e9ce266e 2022-03-07 op test_patch_malformed() {
458 e9ce266e 2022-03-07 op local testroot=`test_init patch_malformed`
460 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
462 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
463 e9ce266e 2022-03-07 op test_done $testroot $ret
467 e9ce266e 2022-03-07 op # missing "@@"
468 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
476 e9ce266e 2022-03-07 op echo -n > $testroot/stdout.expected
477 e9ce266e 2022-03-07 op echo "got: malformed patch" > $testroot/stderr.expected
479 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) \
480 e9ce266e 2022-03-07 op > $testroot/stdout \
481 e9ce266e 2022-03-07 op 2> $testroot/stderr
483 bfbccd0a 2022-03-08 op if [ $ret -eq 0 ]; then
484 e9ce266e 2022-03-07 op echo "got managed to apply an invalid patch"
485 e9ce266e 2022-03-07 op test_done $testroot 1
489 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
491 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
492 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
493 e9ce266e 2022-03-07 op test_done $testroot $ret
497 e9ce266e 2022-03-07 op cmp -s $testroot/stderr.expected $testroot/stderr
499 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
500 e9ce266e 2022-03-07 op diff -u $testroot/stderr.expected $testroot/stderr
501 e9ce266e 2022-03-07 op test_done $testroot $ret
505 e9ce266e 2022-03-07 op # wrong first character
506 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
509 e9ce266e 2022-03-07 op @@ -1 +1,2 @@
514 be33dff7 2022-05-13 op (cd $testroot/wt && got patch patch) \
515 be33dff7 2022-05-13 op > $testroot/stdout \
516 be33dff7 2022-05-13 op 2> $testroot/stderr
518 be33dff7 2022-05-13 op if [ $ret -eq 0 ]; then
519 be33dff7 2022-05-13 op echo "got managed to apply an invalid patch"
520 be33dff7 2022-05-13 op test_done $testroot 1
524 be33dff7 2022-05-13 op cmp -s $testroot/stdout.expected $testroot/stdout
526 be33dff7 2022-05-13 op if [ $ret -ne 0 ]; then
527 be33dff7 2022-05-13 op diff -u $testroot/stdout.expected $testroot/stdout
528 be33dff7 2022-05-13 op test_done $testroot $ret
532 be33dff7 2022-05-13 op cmp -s $testroot/stderr.expected $testroot/stderr
534 be33dff7 2022-05-13 op if [ $ret -ne 0 ]; then
535 be33dff7 2022-05-13 op diff -u $testroot/stderr.expected $testroot/stderr
536 be33dff7 2022-05-13 op test_done $testroot $ret
541 be33dff7 2022-05-13 op cat <<EOF > $testroot/wt/patch
542 be33dff7 2022-05-13 op diff --git a/alpha b/iota
545 be33dff7 2022-05-13 op @@ -0,0 +0,0 @@
548 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) \
549 e9ce266e 2022-03-07 op > $testroot/stdout \
550 e9ce266e 2022-03-07 op 2> $testroot/stderr
552 bfbccd0a 2022-03-08 op if [ $ret -eq 0 ]; then
553 e9ce266e 2022-03-07 op echo "got managed to apply an invalid patch"
554 e9ce266e 2022-03-07 op test_done $testroot 1
558 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
560 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
561 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
562 e9ce266e 2022-03-07 op test_done $testroot $ret
566 e9ce266e 2022-03-07 op cmp -s $testroot/stderr.expected $testroot/stderr
568 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
569 e9ce266e 2022-03-07 op diff -u $testroot/stderr.expected $testroot/stderr
570 e9ce266e 2022-03-07 op test_done $testroot $ret
574 e9ce266e 2022-03-07 op test_done $testroot $ret
577 e9ce266e 2022-03-07 op test_patch_no_patch() {
578 e9ce266e 2022-03-07 op local testroot=`test_init patch_no_patch`
580 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
582 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
583 e9ce266e 2022-03-07 op test_done $testroot $ret
587 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
591 e9ce266e 2022-03-07 op some other nonsense
594 e9ce266e 2022-03-07 op there's no patch in here!
597 e9ce266e 2022-03-07 op echo -n > $testroot/stdout.expected
598 e9ce266e 2022-03-07 op echo "got: no patch found" > $testroot/stderr.expected
600 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) \
601 e9ce266e 2022-03-07 op > $testroot/stdout \
602 e9ce266e 2022-03-07 op 2> $testroot/stderr
604 bfbccd0a 2022-03-08 op if [ $ret -eq 0 ]; then # should fail
605 e9ce266e 2022-03-07 op test_done $testroot 1
609 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
611 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
612 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
613 e9ce266e 2022-03-07 op test_done $testroot $ret
617 e9ce266e 2022-03-07 op cmp -s $testroot/stderr.expected $testroot/stderr
619 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
620 e9ce266e 2022-03-07 op diff -u $testroot/stderr.expected $testroot/stderr
621 e9ce266e 2022-03-07 op test_done $testroot $ret
625 e9ce266e 2022-03-07 op test_done $testroot $ret
628 e9ce266e 2022-03-07 op test_patch_equals_for_context() {
629 f1d6cebb 2022-04-23 op local testroot=`test_init patch_equals_for_context`
631 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
633 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
634 e9ce266e 2022-03-07 op test_done $testroot $ret
638 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
641 e9ce266e 2022-03-07 op @@ -1 +1,2 @@
646 e9ce266e 2022-03-07 op echo "M alpha" > $testroot/stdout.expected
648 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
650 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
651 e9ce266e 2022-03-07 op test_done $testroot $ret
655 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
657 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
658 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
659 e9ce266e 2022-03-07 op test_done $testroot $ret
663 e9ce266e 2022-03-07 op echo hatsuseno > $testroot/wt/alpha.expected
664 e9ce266e 2022-03-07 op echo alpha >> $testroot/wt/alpha.expected
665 e9ce266e 2022-03-07 op cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
667 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
668 e9ce266e 2022-03-07 op diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
670 e9ce266e 2022-03-07 op test_done $testroot $ret
673 6e96b326 2022-03-12 op test_patch_rename() {
674 6e96b326 2022-03-12 op local testroot=`test_init patch_rename`
676 6e96b326 2022-03-12 op got checkout $testroot/repo $testroot/wt > /dev/null
678 6e96b326 2022-03-12 op if [ $ret -ne 0 ]; then
679 6e96b326 2022-03-12 op test_done $testroot $ret
683 6e96b326 2022-03-12 op cat <<EOF > $testroot/wt/patch
684 4379a9aa 2022-05-02 op diff --git a/beta b/iota
685 4379a9aa 2022-05-02 op similarity index 100%
686 4379a9aa 2022-05-02 op rename from beta
687 4379a9aa 2022-05-02 op rename to iota
688 7a30b5cb 2022-03-20 op diff --git a/alpha b/eta
696 4379a9aa 2022-05-02 op echo 'D beta' > $testroot/stdout.expected
697 4379a9aa 2022-05-02 op echo 'A iota' >> $testroot/stdout.expected
698 4379a9aa 2022-05-02 op echo 'D alpha' >> $testroot/stdout.expected
699 4379a9aa 2022-05-02 op echo 'A eta' >> $testroot/stdout.expected
701 6e96b326 2022-03-12 op (cd $testroot/wt && got patch patch) > $testroot/stdout
703 6e96b326 2022-03-12 op if [ $ret -ne 0 ]; then
704 6e96b326 2022-03-12 op test_done $testroot $ret
708 6e96b326 2022-03-12 op cmp -s $testroot/stdout.expected $testroot/stdout
710 6e96b326 2022-03-12 op if [ $ret -ne 0 ]; then
711 6e96b326 2022-03-12 op diff -u $testroot/stdout.expected $testroot/stdout
712 6e96b326 2022-03-12 op test_done $testroot $ret
716 4379a9aa 2022-05-02 op if [ -f $testroot/wt/alpha -o -f $testroot/wt/beta ]; then
717 4379a9aa 2022-05-02 op echo "alpha or beta were not removed" >&2
718 6e96b326 2022-03-12 op test_done $testroot 1
721 4379a9aa 2022-05-02 op if [ ! -f $testroot/wt/iota -o ! -f $testroot/wt/eta ]; then
722 4379a9aa 2022-05-02 op echo "iota or eta were not created" >&2
723 6e96b326 2022-03-12 op test_done $testroot 1
727 4379a9aa 2022-05-02 op echo beta > $testroot/wt/iota.expected
728 4379a9aa 2022-05-02 op cmp -s $testroot/wt/iota.expected $testroot/wt/iota
730 6e96b326 2022-03-12 op if [ $ret -ne 0 ]; then
731 4379a9aa 2022-05-02 op diff -u $testroot/wt/iota.expected $testroot/wt/iota
732 6e96b326 2022-03-12 op test_done $testroot $ret
736 4379a9aa 2022-05-02 op echo eta > $testroot/wt/eta.expected
737 4379a9aa 2022-05-02 op cmp -s $testroot/wt/eta.expected $testroot/wt/eta
739 6e96b326 2022-03-12 op if [ $ret -ne 0 ]; then
740 4379a9aa 2022-05-02 op diff -u $testroot/wt/eta.expected $testroot/wt/eta
741 6e96b326 2022-03-12 op test_done $testroot $ret
745 6e96b326 2022-03-12 op test_done $testroot $ret
748 dbda770b 2022-03-13 op test_patch_illegal_status() {
749 dbda770b 2022-03-13 op local testroot=`test_init patch_illegal_status`
751 dbda770b 2022-03-13 op got checkout $testroot/repo $testroot/wt > /dev/null
753 dbda770b 2022-03-13 op if [ $ret -ne 0 ]; then
754 dbda770b 2022-03-13 op test_done $testroot $ret
758 60aa1fa0 2022-03-17 op # try to patch an obstructed file, add a versioned one, edit a
759 60aa1fa0 2022-03-17 op # non existent file and an unversioned one, and remove a
760 60aa1fa0 2022-03-17 op # non existent file.
761 dbda770b 2022-03-13 op cat <<EOF > $testroot/wt/patch
764 60aa1fa0 2022-03-17 op @@ -1 +1,2 @@
767 60aa1fa0 2022-03-17 op --- /dev/null
769 60aa1fa0 2022-03-17 op @@ -0,0 +1 @@
782 60aa1fa0 2022-03-17 op +++ /dev/null
783 60aa1fa0 2022-03-17 op @@ -1 +0,0 @@
787 60aa1fa0 2022-03-17 op echo kappa > $testroot/wt/kappa
788 dbda770b 2022-03-13 op rm $testroot/wt/alpha
789 dbda770b 2022-03-13 op mkdir $testroot/wt/alpha
791 60aa1fa0 2022-03-17 op (cd $testroot/wt && got patch patch) > $testroot/stdout \
792 dbda770b 2022-03-13 op 2> $testroot/stderr
794 dbda770b 2022-03-13 op if [ $ret -eq 0 ]; then
795 dbda770b 2022-03-13 op echo "edited a missing file" >&2
796 a19f439c 2022-06-03 op test_done $testroot 1
800 60aa1fa0 2022-03-17 op cat <<EOF > $testroot/stdout.expected
808 60aa1fa0 2022-03-17 op cat <<EOF > $testroot/stderr.expected
809 60aa1fa0 2022-03-17 op got: alpha: file has unexpected status
810 60aa1fa0 2022-03-17 op got: beta: file has unexpected status
811 60aa1fa0 2022-03-17 op got: iota: No such file or directory
812 60aa1fa0 2022-03-17 op got: kappa: file has unexpected status
813 60aa1fa0 2022-03-17 op got: lambda: No such file or directory
814 60aa1fa0 2022-03-17 op got: patch failed to apply
817 60aa1fa0 2022-03-17 op cmp -s $testroot/stdout.expected $testroot/stdout
819 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
820 60aa1fa0 2022-03-17 op diff -u $testroot/stdout.expected $testroot/stdout
821 dbda770b 2022-03-13 op test_done $testroot $ret
825 dbda770b 2022-03-13 op cmp -s $testroot/stderr.expected $testroot/stderr
827 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
828 dbda770b 2022-03-13 op diff -u $testroot/stderr.expected $testroot/stderr
829 78f5ac24 2022-03-19 op test_done $testroot $ret
833 78f5ac24 2022-03-19 op (cd $testroot/wt && got status) > $testroot/stdout
834 78f5ac24 2022-03-19 op cat <<EOF > $testroot/stdout.expected
840 78f5ac24 2022-03-19 op cmp -s $testroot/stdout.expected $testroot/stdout
842 78f5ac24 2022-03-19 op if [ $ret -ne 0 ]; then
843 78f5ac24 2022-03-19 op diff -u $testroot/stdout.expected $testroot/stdout
845 899fcfdf 2022-03-13 op test_done $testroot $ret
848 899fcfdf 2022-03-13 op test_patch_nop() {
849 899fcfdf 2022-03-13 op local testroot=`test_init patch_nop`
851 899fcfdf 2022-03-13 op got checkout $testroot/repo $testroot/wt > /dev/null
853 899fcfdf 2022-03-13 op if [ $ret -ne 0 ]; then
854 899fcfdf 2022-03-13 op test_done $testroot $ret
858 899fcfdf 2022-03-13 op cat <<EOF > $testroot/wt/patch
865 899fcfdf 2022-03-13 op +++ /dev/null
866 899fcfdf 2022-03-13 op @@ -1 +0,0 @@
868 7a30b5cb 2022-03-20 op diff --git a/gamma/delta b/gamma/delta.new
869 899fcfdf 2022-03-13 op --- gamma/delta
870 899fcfdf 2022-03-13 op +++ gamma/delta.new
873 899fcfdf 2022-03-13 op +delta updated and renamed!
876 899fcfdf 2022-03-13 op (cd $testroot/wt && got patch -n patch)
878 899fcfdf 2022-03-13 op if [ $ret -ne 0 ]; then
879 899fcfdf 2022-03-13 op test_done $testroot $ret
883 899fcfdf 2022-03-13 op # remove the patch to avoid the ? entry
884 899fcfdf 2022-03-13 op rm $testroot/wt/patch
886 899fcfdf 2022-03-13 op (cd $testroot/wt && got status) > $testroot/stdout
888 899fcfdf 2022-03-13 op if [ $ret -ne 0 ]; then
889 899fcfdf 2022-03-13 op test_done $testroot $ret
893 899fcfdf 2022-03-13 op echo -n > $testroot/stdout.expected
894 899fcfdf 2022-03-13 op cmp -s $testroot/stdout.expected $testroot/stdout
896 899fcfdf 2022-03-13 op if [ $ret -ne 0 ]; then
897 899fcfdf 2022-03-13 op diff -u $testroot/stdout.expected $testroot/stdout
899 dbda770b 2022-03-13 op test_done $testroot $ret
902 2be5e1a2 2022-03-16 op test_patch_preserve_perm() {
903 2be5e1a2 2022-03-16 op local testroot=`test_init patch_preserve_perm`
905 2be5e1a2 2022-03-16 op got checkout $testroot/repo $testroot/wt > /dev/null
907 2be5e1a2 2022-03-16 op if [ $ret -ne 0 ]; then
908 2be5e1a2 2022-03-16 op test_done $testroot $ret
912 2be5e1a2 2022-03-16 op chmod +x $testroot/wt/alpha
913 2be5e1a2 2022-03-16 op (cd $testroot/wt && got commit -m 'alpha executable') > /dev/null
915 2be5e1a2 2022-03-16 op if [ $ret -ne 0 ]; then
916 2be5e1a2 2022-03-16 op test_done $testroot $ret
920 2be5e1a2 2022-03-16 op cat <<EOF > $testroot/wt/patch
923 2be5e1a2 2022-03-16 op @@ -1 +1,2 @@
928 2be5e1a2 2022-03-16 op (cd $testroot/wt && got patch patch) > /dev/null
930 2be5e1a2 2022-03-16 op if [ $ret -ne 0 ]; then
931 2be5e1a2 2022-03-16 op test_done $testroot $ret
935 2be5e1a2 2022-03-16 op if [ ! -x $testroot/wt/alpha ]; then
936 2be5e1a2 2022-03-16 op echo "alpha is no more executable!" >&2
937 2be5e1a2 2022-03-16 op test_done $testroot 1
940 95d68340 2022-03-16 op test_done $testroot 0
943 95d68340 2022-03-16 op test_patch_create_dirs() {
944 95d68340 2022-03-16 op local testroot=`test_init patch_create_dirs`
946 95d68340 2022-03-16 op got checkout $testroot/repo $testroot/wt > /dev/null
948 95d68340 2022-03-16 op if [ $ret -ne 0 ]; then
949 95d68340 2022-03-16 op test_done $testroot $ret
953 95d68340 2022-03-16 op cat <<EOF > $testroot/wt/patch
954 95d68340 2022-03-16 op --- /dev/null
955 95d68340 2022-03-16 op +++ iota/kappa/lambda
956 95d68340 2022-03-16 op @@ -0,0 +1 @@
960 95d68340 2022-03-16 op (cd $testroot/wt && got patch patch) > $testroot/stdout
962 95d68340 2022-03-16 op if [ $ret -ne 0 ]; then
963 95d68340 2022-03-16 op test_done $testroot $ret
967 95d68340 2022-03-16 op echo 'A iota/kappa/lambda' >> $testroot/stdout.expected
968 95d68340 2022-03-16 op cmp -s $testroot/stdout.expected $testroot/stdout
970 95d68340 2022-03-16 op if [ $ret -ne 0 ]; then
971 95d68340 2022-03-16 op diff -u $testroot/stdout.expected $testroot/stdout
972 95d68340 2022-03-16 op test_done $testroot $ret
976 95d68340 2022-03-16 op if [ ! -f $testroot/wt/iota/kappa/lambda ]; then
977 95d68340 2022-03-16 op echo "file not created!" >&2
978 95d68340 2022-03-16 op test_done $testroot $ret
981 2be5e1a2 2022-03-16 op test_done $testroot 0
984 60aa1fa0 2022-03-17 op test_patch_with_offset() {
985 60aa1fa0 2022-03-17 op local testroot=`test_init patch_with_offset`
987 60aa1fa0 2022-03-17 op got checkout $testroot/repo $testroot/wt > /dev/null
989 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
990 60aa1fa0 2022-03-17 op test_done $testroot $ret
994 60aa1fa0 2022-03-17 op cat <<EOF > $testroot/wt/patch
997 60aa1fa0 2022-03-17 op @@ -47,7 +47,7 @@
1002 60aa1fa0 2022-03-17 op +midway tru it!
1006 60aa1fa0 2022-03-17 op @@ -87,7 +87,7 @@
1011 60aa1fa0 2022-03-17 op +almost there!
1017 60aa1fa0 2022-03-17 op jot 100 > $testroot/wt/numbers
1018 60aa1fa0 2022-03-17 op ed $testroot/wt/numbers <<EOF > /dev/null 2> /dev/null
1025 60aa1fa0 2022-03-17 op (cd $testroot/wt && got add numbers && got commit -m '+numbers') \
1028 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
1029 60aa1fa0 2022-03-17 op test_done $testroot $ret
1033 60aa1fa0 2022-03-17 op (cd $testroot/wt && got patch patch) > $testroot/stdout
1035 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
1036 60aa1fa0 2022-03-17 op test_done $testroot/wt $ret
1040 60aa1fa0 2022-03-17 op cat <<EOF > $testroot/stdout.expected
1042 60aa1fa0 2022-03-17 op @@ -47,7 +47,7 @@ applied with offset -10
1043 60aa1fa0 2022-03-17 op @@ -87,7 +87,7 @@ applied with offset 10
1046 7a30b5cb 2022-03-20 op cmp -s $testroot/stdout.expected $testroot/stdout
1048 7a30b5cb 2022-03-20 op if [ $ret -ne 0 ]; then
1049 7a30b5cb 2022-03-20 op diff -u $testroot/stdout.expected $testroot/stdout
1051 7a30b5cb 2022-03-20 op test_done $testroot $ret
1054 7a30b5cb 2022-03-20 op test_patch_prefer_new_path() {
1055 7a30b5cb 2022-03-20 op local testroot=`test_init patch_orig`
1057 7a30b5cb 2022-03-20 op got checkout $testroot/repo $testroot/wt > /dev/null
1059 7a30b5cb 2022-03-20 op if [ $ret -ne 0 ]; then
1060 7a30b5cb 2022-03-20 op test_done $testroot $ret
1064 7a30b5cb 2022-03-20 op cat <<EOF > $testroot/wt/patch
1065 7a30b5cb 2022-03-20 op --- alpha.orig
1067 7a30b5cb 2022-03-20 op @@ -1 +1,2 @@
1072 7a30b5cb 2022-03-20 op (cd $testroot/wt && got patch patch) > $testroot/stdout
1074 7a30b5cb 2022-03-20 op if [ $ret -ne 0 ]; then
1075 7a30b5cb 2022-03-20 op test_done $testroot $ret
1079 3313bcd8 2022-04-19 op echo 'M alpha' > $testroot/stdout.expected
1080 60aa1fa0 2022-03-17 op cmp -s $testroot/stdout.expected $testroot/stdout
1082 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
1083 60aa1fa0 2022-03-17 op diff -u $testroot/stdout.expected $testroot/stdout
1085 60aa1fa0 2022-03-17 op test_done $testroot $ret
1088 b3c57ab2 2022-03-22 op test_patch_no_newline() {
1089 b3c57ab2 2022-03-22 op local testroot=`test_init patch_no_newline`
1091 b3c57ab2 2022-03-22 op got checkout $testroot/repo $testroot/wt > /dev/null
1093 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1094 b3c57ab2 2022-03-22 op test_done $testroot $ret
1098 b3c57ab2 2022-03-22 op cat <<EOF > $testroot/wt/patch
1099 b3c57ab2 2022-03-22 op --- /dev/null
1101 b3c57ab2 2022-03-22 op @@ -0,0 +1 @@
1103 b3c57ab2 2022-03-22 op \ No newline at end of file
1106 b3c57ab2 2022-03-22 op (cd $testroot/wt && got patch patch) > $testroot/stdout
1108 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1109 b3c57ab2 2022-03-22 op test_done $testroot $ret
1113 b3c57ab2 2022-03-22 op echo "A eta" > $testroot/stdout.expected
1114 b3c57ab2 2022-03-22 op cmp -s $testroot/stdout.expected $testroot/stdout
1116 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1117 b3c57ab2 2022-03-22 op diff -u $testroot/stdout.expected $testroot/stdout
1118 b3c57ab2 2022-03-22 op test_done $testroot $ret
1122 b3c57ab2 2022-03-22 op echo -n eta > $testroot/wt/eta.expected
1123 b3c57ab2 2022-03-22 op cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1125 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1126 b3c57ab2 2022-03-22 op diff -u $testroot/wt/eta.expected $testroot/wt/eta
1127 b3c57ab2 2022-03-22 op test_done $testroot $ret
1131 b3c57ab2 2022-03-22 op (cd $testroot/wt && got commit -m 'add eta') > /dev/null
1133 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1134 b3c57ab2 2022-03-22 op test_done $testroot $ret
1138 b3c57ab2 2022-03-22 op cat <<EOF > $testroot/wt/patch
1143 b3c57ab2 2022-03-22 op \ No newline at end of file
1145 b3c57ab2 2022-03-22 op \ No newline at end of file
1148 b3c57ab2 2022-03-22 op (cd $testroot/wt && got patch patch) > $testroot/stdout
1150 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1151 b3c57ab2 2022-03-22 op test_done $testroot $ret
1155 b3c57ab2 2022-03-22 op echo "M eta" > $testroot/stdout.expected
1156 b3c57ab2 2022-03-22 op cmp -s $testroot/stdout.expected $testroot/stdout
1158 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1159 b3c57ab2 2022-03-22 op diff -u $testroot/stdout.expected $testroot/stdout
1160 b3c57ab2 2022-03-22 op test_done $testroot $ret
1164 b3c57ab2 2022-03-22 op echo -n ETA > $testroot/wt/eta.expected
1165 b3c57ab2 2022-03-22 op cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1167 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1168 b3c57ab2 2022-03-22 op diff -u $testroot/wt/eta.expected $testroot/wt/eta
1169 b3c57ab2 2022-03-22 op test_done $testroot $ret
1173 b3c57ab2 2022-03-22 op (cd $testroot/wt && got commit -m 'edit eta') > /dev/null
1175 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1176 b3c57ab2 2022-03-22 op test_done $testroot $ret
1180 b3c57ab2 2022-03-22 op cat <<EOF > $testroot/wt/patch
1185 b3c57ab2 2022-03-22 op \ No newline at end of file
1189 b3c57ab2 2022-03-22 op (cd $testroot/wt && got patch patch) > $testroot/stdout
1191 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1192 b3c57ab2 2022-03-22 op test_done $testroot $ret
1196 b3c57ab2 2022-03-22 op echo "M eta" > $testroot/stdout.expected
1197 b3c57ab2 2022-03-22 op cmp -s $testroot/stdout.expected $testroot/stdout
1199 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1200 b3c57ab2 2022-03-22 op diff -u $testroot/stdout.expected $testroot/stdout
1201 b3c57ab2 2022-03-22 op test_done $testroot $ret
1205 b3c57ab2 2022-03-22 op echo eta > $testroot/wt/eta.expected
1206 b3c57ab2 2022-03-22 op cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1208 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1209 b3c57ab2 2022-03-22 op diff -u $testroot/wt/eta.expected $testroot/wt/eta
1211 b3c57ab2 2022-03-22 op test_done $testroot $ret
1214 9d6cabd5 2022-04-07 op test_patch_strip() {
1215 9d6cabd5 2022-04-07 op local testroot=`test_init patch_strip`
1217 9d6cabd5 2022-04-07 op got checkout $testroot/repo $testroot/wt > /dev/null
1219 9d6cabd5 2022-04-07 op if [ $ret -ne 0 ]; then
1220 9d6cabd5 2022-04-07 op test_done $testroot $ret
1224 9d6cabd5 2022-04-07 op cat <<EOF > $testroot/wt/patch
1225 9d6cabd5 2022-04-07 op --- foo/bar/alpha.orig
1226 9d6cabd5 2022-04-07 op +++ foo/bar/alpha
1232 9d6cabd5 2022-04-07 op (cd $testroot/wt && got patch -p2 patch) > $testroot/stdout
1234 9d6cabd5 2022-04-07 op if [ $ret -ne 0 ]; then
1235 9d6cabd5 2022-04-07 op test_done $testroot $ret
1239 9d6cabd5 2022-04-07 op echo "M alpha" >> $testroot/stdout.expected
1240 9d6cabd5 2022-04-07 op cmp -s $testroot/stdout.expected $testroot/stdout
1242 9d6cabd5 2022-04-07 op if [ $ret -ne 0 ]; then
1243 9d6cabd5 2022-04-07 op diff -u $testroot/stdout.expected $testroot/stdout
1244 9d6cabd5 2022-04-07 op test_done $testroot $ret
1248 9d6cabd5 2022-04-07 op (cd $testroot/wt && got revert alpha) > /dev/null 2>&1
1250 9d6cabd5 2022-04-07 op if [ $ret -ne 0 ]; then
1251 9d6cabd5 2022-04-07 op test_done $testroot $ret
1255 9d6cabd5 2022-04-07 op (cd $testroot/wt && got patch -p3 patch) \
1256 9d6cabd5 2022-04-07 op 2> $testroot/stderr
1258 9d6cabd5 2022-04-07 op if [ $ret -eq 0 ]; then
1259 9d6cabd5 2022-04-07 op echo "stripped more components than available!"
1260 9d6cabd5 2022-04-07 op test_done $testroot 1
1264 9d6cabd5 2022-04-07 op cat <<EOF > $testroot/stderr.expected
1265 9d6cabd5 2022-04-07 op got: can't strip 1 path-components from foo/bar/alpha: bad path
1268 9d6cabd5 2022-04-07 op cmp -s $testroot/stderr.expected $testroot/stderr
1270 9d6cabd5 2022-04-07 op if [ $ret -ne 0 ]; then
1271 9d6cabd5 2022-04-07 op diff -u $testroot/stderr.expected $testroot/stderr
1273 9d6cabd5 2022-04-07 op test_done $testroot 0
1276 ed3bff83 2022-04-23 op test_patch_relative_paths() {
1277 f1d6cebb 2022-04-23 op local testroot=`test_init patch_relative_paths`
1279 ed3bff83 2022-04-23 op got checkout $testroot/repo $testroot/wt > /dev/null
1281 ed3bff83 2022-04-23 op if [ $ret -ne 0 ]; then
1282 ed3bff83 2022-04-23 op test_done $testroot $ret
1286 ed3bff83 2022-04-23 op cat <<EOF > $testroot/wt/gamma/patch
1292 ed3bff83 2022-04-23 op --- /dev/null
1294 ed3bff83 2022-04-23 op @@ -0,0 +1 @@
1298 ed3bff83 2022-04-23 op (cd $testroot/wt/gamma && got patch patch) > $testroot/stdout
1300 ed3bff83 2022-04-23 op if [ $ret -ne 0 ]; then
1301 ed3bff83 2022-04-23 op test_done $testroot $ret
1305 ed3bff83 2022-04-23 op echo 'M gamma/delta' > $testroot/stdout.expected
1306 ed3bff83 2022-04-23 op echo 'A gamma/eta' >> $testroot/stdout.expected
1308 15e1bda6 2022-04-23 op cmp -s $testroot/stdout.expected $testroot/stdout
1310 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1311 15e1bda6 2022-04-23 op diff -u $testroot/stdout.expected $testroot/stdout
1313 15e1bda6 2022-04-23 op test_done $testroot $ret
1316 15e1bda6 2022-04-23 op test_patch_with_path_prefix() {
1317 15e1bda6 2022-04-23 op local testroot=`test_init patch_with_path_prefix`
1319 15e1bda6 2022-04-23 op got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1321 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1322 15e1bda6 2022-04-23 op test_done $testroot $ret
1326 15e1bda6 2022-04-23 op cat <<EOF > $testroot/wt/patch
1332 15e1bda6 2022-04-23 op --- /dev/null
1334 15e1bda6 2022-04-23 op @@ -0,0 +1 @@
1338 15e1bda6 2022-04-23 op (cd $testroot/wt && got patch patch) > $testroot/stdout
1340 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1341 15e1bda6 2022-04-23 op test_done $testroot $ret
1345 15e1bda6 2022-04-23 op echo 'M delta' > $testroot/stdout.expected
1346 15e1bda6 2022-04-23 op echo 'A eta' >> $testroot/stdout.expected
1348 15e1bda6 2022-04-23 op cmp -s $testroot/stdout.expected $testroot/stdout
1350 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1351 15e1bda6 2022-04-23 op diff -u $testroot/stdout.expected $testroot/stdout
1353 15e1bda6 2022-04-23 op test_done $testroot $ret
1356 15e1bda6 2022-04-23 op test_patch_relpath_with_path_prefix() {
1357 15e1bda6 2022-04-23 op local testroot=`test_init patch_relpaths_with_path_prefix`
1359 15e1bda6 2022-04-23 op got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1361 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1362 15e1bda6 2022-04-23 op test_done $testroot $ret
1366 15e1bda6 2022-04-23 op mkdir -p $testroot/wt/epsilon/zeta/
1368 15e1bda6 2022-04-23 op cat <<EOF > $testroot/wt/patch
1369 15e1bda6 2022-04-23 op --- /dev/null
1370 15e1bda6 2022-04-23 op +++ zeta/theta
1371 15e1bda6 2022-04-23 op @@ -0,0 +1 @@
1375 15e1bda6 2022-04-23 op (cd $testroot/wt/epsilon/zeta && got patch -p1 $testroot/wt/patch) \
1376 15e1bda6 2022-04-23 op > $testroot/stdout
1378 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1379 15e1bda6 2022-04-23 op test_done $testroot $ret
1383 15e1bda6 2022-04-23 op echo 'A epsilon/zeta/theta' >> $testroot/stdout.expected
1385 ed3bff83 2022-04-23 op cmp -s $testroot/stdout.expected $testroot/stdout
1387 ed3bff83 2022-04-23 op if [ $ret -ne 0 ]; then
1388 ed3bff83 2022-04-23 op diff -u $testroot/stdout.expected $testroot/stdout
1389 15e1bda6 2022-04-23 op test_done $testroot $ret
1393 15e1bda6 2022-04-23 op echo 'theta' > $testroot/theta.expected
1394 15e1bda6 2022-04-23 op cmp -s $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1396 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1397 15e1bda6 2022-04-23 op diff -u $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1399 ed3bff83 2022-04-23 op test_done $testroot $ret
1402 bad961bf 2022-04-23 op test_patch_reverse() {
1403 bad961bf 2022-04-23 op local testroot=`test_init patch_reverse`
1405 bad961bf 2022-04-23 op got checkout $testroot/repo $testroot/wt > /dev/null
1407 bad961bf 2022-04-23 op if [ $ret -ne 0 ]; then
1408 bad961bf 2022-04-23 op test_done $testroot $ret
1412 bad961bf 2022-04-23 op cat <<EOF > $testroot/wt/patch
1417 bad961bf 2022-04-23 op \ No newline at end of file
1421 bad961bf 2022-04-23 op (cd $testroot/wt && got patch -R patch) > $testroot/stdout
1423 bad961bf 2022-04-23 op if [ $ret -ne 0 ]; then
1424 bad961bf 2022-04-23 op test_done $testroot $ret
1428 bad961bf 2022-04-23 op echo "M alpha" > $testroot/stdout.expected
1429 bad961bf 2022-04-23 op cmp -s $testroot/stdout.expected $testroot/stdout
1431 bad961bf 2022-04-23 op if [ $ret -ne 0 ]; then
1432 bad961bf 2022-04-23 op diff -u $testroot/stdout.expected $testroot/stdout
1433 bad961bf 2022-04-23 op test_done $testroot $ret
1437 bad961bf 2022-04-23 op echo -n ALPHA > $testroot/wt/alpha.expected
1438 bad961bf 2022-04-23 op cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
1440 bad961bf 2022-04-23 op if [ $ret -ne 0 ]; then
1441 bad961bf 2022-04-23 op diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
1443 55e9459f 2022-06-19 op test_done $testroot $ret
1446 55e9459f 2022-06-19 op test_patch_merge_simple() {
1447 55e9459f 2022-06-19 op local testroot=`test_init patch_merge_simple`
1449 55e9459f 2022-06-19 op got checkout $testroot/repo $testroot/wt > /dev/null
1451 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1452 55e9459f 2022-06-19 op test_done $testroot $ret
1456 55e9459f 2022-06-19 op jot 10 > $testroot/wt/numbers
1457 55e9459f 2022-06-19 op (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1460 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1461 55e9459f 2022-06-19 op test_done $testroot $ret
1465 55e9459f 2022-06-19 op jot 10 | sed 's/4/four/g' > $testroot/wt/numbers
1467 55e9459f 2022-06-19 op (cd $testroot/wt && got diff > $testroot/old.diff \
1468 55e9459f 2022-06-19 op && got revert numbers) >/dev/null
1470 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1471 55e9459f 2022-06-19 op test_done $testroot $ret
1475 55e9459f 2022-06-19 op jot 10 | sed 's/6/six/g' > $testroot/wt/numbers
1476 55e9459f 2022-06-19 op (cd $testroot/wt && got commit -m 'edit numbers') \
1479 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1480 55e9459f 2022-06-19 op test_done $testroot $ret
1484 55e9459f 2022-06-19 op (cd $testroot/wt && got patch $testroot/old.diff) \
1485 9802c41c 2022-06-21 op > $testroot/stdout
1487 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1488 9802c41c 2022-06-21 op test_done $testroot $ret
1492 9802c41c 2022-06-21 op echo 'G numbers' > $testroot/stdout.expected
1493 9802c41c 2022-06-21 op cmp -s $testroot/stdout $testroot/stdout.expected
1495 9802c41c 2022-06-21 op if [ $ret -ne 0 ]; then
1496 9802c41c 2022-06-21 op diff -u $testroot/stdout $testroot/stdout.expected
1497 55e9459f 2022-06-19 op test_done $testroot $ret
1501 55e9459f 2022-06-19 op jot 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
1502 55e9459f 2022-06-19 op cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1504 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1505 55e9459f 2022-06-19 op diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1507 db0dfdd7 2022-06-27 op test_done $testroot $ret
1510 db0dfdd7 2022-06-27 op test_patch_merge_gitdiff() {
1511 db0dfdd7 2022-06-27 op local testroot=`test_init patch_merge_gitdiff`
1513 db0dfdd7 2022-06-27 op jot 10 > $testroot/repo/numbers
1514 db0dfdd7 2022-06-27 op (cd $testroot/repo && git add numbers && \
1515 db0dfdd7 2022-06-27 op git_commit $testroot/repo -m "nums")
1517 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1518 db0dfdd7 2022-06-27 op test_done $testroot $ret
1522 db0dfdd7 2022-06-27 op jot 10 | sed 's/4/four/g' > $testroot/repo/numbers
1523 db0dfdd7 2022-06-27 op (cd $testroot/repo && git diff > $testroot/old.diff)
1525 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1526 db0dfdd7 2022-06-27 op test_done $testroot $ret
1530 db0dfdd7 2022-06-27 op # restore numbers
1531 db0dfdd7 2022-06-27 op jot 10 > $testroot/repo/numbers
1533 db0dfdd7 2022-06-27 op jot 10 | sed 's/6/six/g' > $testroot/repo/numbers
1534 db0dfdd7 2022-06-27 op (cd $testroot/repo && git add numbers && \
1535 db0dfdd7 2022-06-27 op git_commit $testroot/repo -m "edit")
1537 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1538 db0dfdd7 2022-06-27 op test_done $testroot $ret
1542 db0dfdd7 2022-06-27 op # now work with got:
1543 db0dfdd7 2022-06-27 op got checkout $testroot/repo $testroot/wt > /dev/null
1545 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1546 db0dfdd7 2022-06-27 op test_done $testroot $ret
1550 db0dfdd7 2022-06-27 op (cd $testroot/wt && got patch $testroot/old.diff) > $testroot/stdout
1552 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1553 db0dfdd7 2022-06-27 op test_done $testroot $ret
1557 db0dfdd7 2022-06-27 op echo 'G numbers' > $testroot/stdout.expected
1558 db0dfdd7 2022-06-27 op cmp -s $testroot/stdout $testroot/stdout.expected
1560 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1561 db0dfdd7 2022-06-27 op diff -u $testroot/stdout $testroot/stdout.expected
1563 55e9459f 2022-06-19 op test_done $testroot $ret
1566 55e9459f 2022-06-19 op test_patch_merge_conflict() {
1567 55e9459f 2022-06-19 op local testroot=`test_init patch_merge_conflict`
1569 55e9459f 2022-06-19 op got checkout $testroot/repo $testroot/wt > /dev/null
1571 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1572 55e9459f 2022-06-19 op test_done $testroot $ret
1576 55e9459f 2022-06-19 op jot 10 > $testroot/wt/numbers
1577 55e9459f 2022-06-19 op (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1580 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1581 55e9459f 2022-06-19 op test_done $testroot $ret
1585 d8b5af43 2022-06-19 op local commit_id=`git_show_head $testroot/repo`
1587 55e9459f 2022-06-19 op jot 10 | sed 's/6/six/g' > $testroot/wt/numbers
1589 55e9459f 2022-06-19 op (cd $testroot/wt && got diff > $testroot/old.diff \
1590 55e9459f 2022-06-19 op && got revert numbers) >/dev/null
1592 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1593 55e9459f 2022-06-19 op test_done $testroot $ret
1597 55e9459f 2022-06-19 op jot 10 | sed 's/6/3+3/g' > $testroot/wt/numbers
1598 55e9459f 2022-06-19 op (cd $testroot/wt && got commit -m 'edit numbers') \
1601 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1602 55e9459f 2022-06-19 op test_done $testroot $ret
1606 55e9459f 2022-06-19 op (cd $testroot/wt && got patch $testroot/old.diff) \
1607 9802c41c 2022-06-21 op > $testroot/stdout 2>/dev/null
1609 55e9459f 2022-06-19 op if [ $ret -eq 0 ]; then
1610 55e9459f 2022-06-19 op echo "got patch merged a diff that should conflict" >&2
1611 55e9459f 2022-06-19 op test_done $testroot 0
1615 9802c41c 2022-06-21 op echo 'C numbers' > $testroot/stdout.expected
1616 9802c41c 2022-06-21 op cmp -s $testroot/stdout $testroot/stdout.expected
1618 9802c41c 2022-06-21 op if [ $ret -ne 0 ]; then
1619 9802c41c 2022-06-21 op diff -u $testroot/stdout $testroot/stdout.expected
1620 9802c41c 2022-06-21 op test_done $testroot $ret
1624 55e9459f 2022-06-19 op # XXX: prefixing every line with a tab otherwise got thinks
1625 55e9459f 2022-06-19 op # the file has conflicts in it.
1626 55e9459f 2022-06-19 op cat <<-EOF > $testroot/wt/numbers.expected
1632 55e9459f 2022-06-19 op <<<<<<< --- numbers
1634 d8b5af43 2022-06-19 op ||||||| commit $commit_id
1638 55e9459f 2022-06-19 op >>>>>>> +++ numbers
1645 55e9459f 2022-06-19 op cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1647 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1648 55e9459f 2022-06-19 op diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1650 bad961bf 2022-04-23 op test_done $testroot $ret
1653 55e9459f 2022-06-19 op test_patch_merge_unknown_blob() {
1654 55e9459f 2022-06-19 op local testroot=`test_init patch_merge_unknown_blob`
1656 55e9459f 2022-06-19 op got checkout $testroot/repo $testroot/wt > /dev/null
1658 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1659 55e9459f 2022-06-19 op test_done $testroot $ret
1663 55e9459f 2022-06-19 op cat <<EOF > $testroot/wt/patch
1665 dbc68eed 2022-06-21 op diff aaaabbbbccccddddeeeeffff0000111122223333 foo/bar
1667 55e9459f 2022-06-19 op blob - aaaabbbbccccddddeeeeffff0000111122223333
1669 dbc68eed 2022-06-21 op blob + 0000111122223333444455556666777788889999
1670 55e9459f 2022-06-19 op for this dummy diff
1676 55e9459f 2022-06-19 op will it work?
1679 55e9459f 2022-06-19 op (cd $testroot/wt/ && got patch patch) > $testroot/stdout
1681 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1682 55e9459f 2022-06-19 op test_done $testroot $ret
1686 55e9459f 2022-06-19 op echo 'M alpha' > $testroot/stdout.expected
1687 55e9459f 2022-06-19 op cmp -s $testroot/stdout.expected $testroot/stdout
1689 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1690 55e9459f 2022-06-19 op diff -u $testroot/stdout.expected $testroot/stdout
1691 dbc68eed 2022-06-21 op test_done $testroot $ret
1695 dbc68eed 2022-06-21 op # try again without a `diff' header
1697 dbc68eed 2022-06-21 op cat <<EOF > $testroot/wt/patch
1699 dbc68eed 2022-06-21 op blob - aaaabbbbccccddddeeeeffff0000111122223333
1701 dbc68eed 2022-06-21 op blob + 0000111122223333444455556666777788889999
1702 dbc68eed 2022-06-21 op for this dummy diff
1708 dbc68eed 2022-06-21 op will it work?
1711 dbc68eed 2022-06-21 op (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1712 dbc68eed 2022-06-21 op > $testroot/stdout
1714 dbc68eed 2022-06-21 op if [ $ret -ne 0 ]; then
1715 dbc68eed 2022-06-21 op test_done $testroot $ret
1719 dbc68eed 2022-06-21 op echo 'M alpha' > $testroot/stdout.expected
1720 dbc68eed 2022-06-21 op cmp -s $testroot/stdout.expected $testroot/stdout
1722 dbc68eed 2022-06-21 op if [ $ret -ne 0 ]; then
1723 dbc68eed 2022-06-21 op diff -u $testroot/stdout.expected $testroot/stdout
1724 db0dfdd7 2022-06-27 op test_done $testroot $ret
1728 db0dfdd7 2022-06-27 op # try again with a git-style diff
1730 db0dfdd7 2022-06-27 op cat <<EOF > $testroot/wt/patch
1731 db0dfdd7 2022-06-27 op diff --git a/alpha b/alpha
1732 db0dfdd7 2022-06-27 op index 0123456789ab..abcdef012345 100644
1740 db0dfdd7 2022-06-27 op (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1741 db0dfdd7 2022-06-27 op > $testroot/stdout
1743 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1744 db0dfdd7 2022-06-27 op test_done $testroot $ret
1748 db0dfdd7 2022-06-27 op echo 'M alpha' > $testroot/stdout.expected
1749 db0dfdd7 2022-06-27 op cmp -s $testroot/stdout.expected $testroot/stdout
1751 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1752 db0dfdd7 2022-06-27 op diff -u $testroot/stdout.expected $testroot/stdout
1754 55e9459f 2022-06-19 op test_done $testroot $ret
1757 e9ce266e 2022-03-07 op test_parseargs "$@"
1758 e9ce266e 2022-03-07 op run_test test_patch_simple_add_file
1759 e9ce266e 2022-03-07 op run_test test_patch_simple_rm_file
1760 e9ce266e 2022-03-07 op run_test test_patch_simple_edit_file
1761 e9ce266e 2022-03-07 op run_test test_patch_prepend_line
1762 e9ce266e 2022-03-07 op run_test test_patch_replace_line
1763 e9ce266e 2022-03-07 op run_test test_patch_multiple_hunks
1764 e9ce266e 2022-03-07 op run_test test_patch_multiple_files
1765 e9ce266e 2022-03-07 op run_test test_patch_dont_apply
1766 e9ce266e 2022-03-07 op run_test test_patch_malformed
1767 e9ce266e 2022-03-07 op run_test test_patch_no_patch
1768 e9ce266e 2022-03-07 op run_test test_patch_equals_for_context
1769 6e96b326 2022-03-12 op run_test test_patch_rename
1770 dbda770b 2022-03-13 op run_test test_patch_illegal_status
1771 899fcfdf 2022-03-13 op run_test test_patch_nop
1772 2be5e1a2 2022-03-16 op run_test test_patch_preserve_perm
1773 95d68340 2022-03-16 op run_test test_patch_create_dirs
1774 60aa1fa0 2022-03-17 op run_test test_patch_with_offset
1775 7a30b5cb 2022-03-20 op run_test test_patch_prefer_new_path
1776 b3c57ab2 2022-03-22 op run_test test_patch_no_newline
1777 9d6cabd5 2022-04-07 op run_test test_patch_strip
1778 ed3bff83 2022-04-23 op run_test test_patch_relative_paths
1779 15e1bda6 2022-04-23 op run_test test_patch_with_path_prefix
1780 15e1bda6 2022-04-23 op run_test test_patch_relpath_with_path_prefix
1781 bad961bf 2022-04-23 op run_test test_patch_reverse
1782 55e9459f 2022-06-19 op run_test test_patch_merge_simple
1783 db0dfdd7 2022-06-27 op run_test test_patch_merge_gitdiff
1784 55e9459f 2022-06-19 op run_test test_patch_merge_conflict
1785 55e9459f 2022-06-19 op run_test test_patch_merge_unknown_blob