3 069bbb86 2022-03-07 thomas # Copyright (c) 2022 Omar Polo <op@openbsd.org>
5 069bbb86 2022-03-07 thomas # Permission to use, copy, modify, and distribute this software for any
6 069bbb86 2022-03-07 thomas # purpose with or without fee is hereby granted, provided that the above
7 069bbb86 2022-03-07 thomas # copyright notice and this permission notice appear in all copies.
9 069bbb86 2022-03-07 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 069bbb86 2022-03-07 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 069bbb86 2022-03-07 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 069bbb86 2022-03-07 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 069bbb86 2022-03-07 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 069bbb86 2022-03-07 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 069bbb86 2022-03-07 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 069bbb86 2022-03-07 thomas . ./common.sh
19 069bbb86 2022-03-07 thomas test_patch_simple_add_file() {
20 069bbb86 2022-03-07 thomas local testroot=`test_init patch_simple_add_file`
22 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
24 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
25 069bbb86 2022-03-07 thomas test_done $testroot $ret
29 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
30 069bbb86 2022-03-07 thomas --- /dev/null
32 069bbb86 2022-03-07 thomas @@ -0,0 +1 @@
36 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
38 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
39 069bbb86 2022-03-07 thomas test_done $testroot $ret
43 069bbb86 2022-03-07 thomas echo "A eta" > $testroot/stdout.expected
44 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
46 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
47 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
48 069bbb86 2022-03-07 thomas test_done $testroot $ret
52 069bbb86 2022-03-07 thomas echo eta > $testroot/wt/eta.expected
53 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/eta.expected $testroot/wt/eta
55 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
56 069bbb86 2022-03-07 thomas diff -u $testroot/wt/eta.expected $testroot/wt/eta
58 069bbb86 2022-03-07 thomas test_done $testroot $ret
61 069bbb86 2022-03-07 thomas test_patch_simple_rm_file() {
62 069bbb86 2022-03-07 thomas local testroot=`test_init patch_simple_rm_file`
64 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
66 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
67 069bbb86 2022-03-07 thomas test_done $testroot $ret
71 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
73 069bbb86 2022-03-07 thomas +++ /dev/null
74 069bbb86 2022-03-07 thomas @@ -1 +0,0 @@
78 069bbb86 2022-03-07 thomas echo "D alpha" > $testroot/stdout.expected
80 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
82 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
83 069bbb86 2022-03-07 thomas test_done $testroot $ret
87 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
89 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
90 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
91 069bbb86 2022-03-07 thomas test_done $testroot $ret
95 069bbb86 2022-03-07 thomas if [ -f $testroot/wt/alpha ]; then
97 069bbb86 2022-03-07 thomas echo "alpha still exists!"
99 069bbb86 2022-03-07 thomas test_done $testroot $ret
102 069bbb86 2022-03-07 thomas test_patch_simple_edit_file() {
103 069bbb86 2022-03-07 thomas local testroot=`test_init patch_simple_edit_file`
105 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
107 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
108 069bbb86 2022-03-07 thomas test_done $testroot $ret
112 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
113 069bbb86 2022-03-07 thomas --- alpha
114 069bbb86 2022-03-07 thomas +++ alpha
115 069bbb86 2022-03-07 thomas @@ -1 +1 @@
117 069bbb86 2022-03-07 thomas +alpha is my favourite character
120 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
122 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
124 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
125 069bbb86 2022-03-07 thomas test_done $testroot $ret
129 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
131 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
132 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
133 069bbb86 2022-03-07 thomas test_done $testroot $ret
137 069bbb86 2022-03-07 thomas echo 'alpha is my favourite character' > $testroot/wt/alpha.expected
138 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
140 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
141 069bbb86 2022-03-07 thomas diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
143 069bbb86 2022-03-07 thomas test_done $testroot $ret
146 069bbb86 2022-03-07 thomas test_patch_prepend_line() {
147 069bbb86 2022-03-07 thomas local testroot=`test_init patch_prepend_line`
149 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
151 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
152 069bbb86 2022-03-07 thomas test_done $testroot $ret
156 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
157 069bbb86 2022-03-07 thomas --- alpha
158 069bbb86 2022-03-07 thomas +++ alpha
159 069bbb86 2022-03-07 thomas @@ -1 +1,2 @@
160 069bbb86 2022-03-07 thomas +hatsuseno
164 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
166 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
168 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
169 069bbb86 2022-03-07 thomas test_done $testroot $ret
173 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
175 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
176 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
177 069bbb86 2022-03-07 thomas test_done $testroot $ret
181 069bbb86 2022-03-07 thomas echo hatsuseno > $testroot/wt/alpha.expected
182 069bbb86 2022-03-07 thomas echo alpha >> $testroot/wt/alpha.expected
183 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
185 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
186 069bbb86 2022-03-07 thomas diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
188 069bbb86 2022-03-07 thomas test_done $testroot $ret
191 069bbb86 2022-03-07 thomas test_patch_replace_line() {
192 069bbb86 2022-03-07 thomas local testroot=`test_init patch_replace_line`
194 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
196 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
197 069bbb86 2022-03-07 thomas test_done $testroot $ret
201 069bbb86 2022-03-07 thomas jot 10 > $testroot/wt/numbers
202 069bbb86 2022-03-07 thomas (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
203 069bbb86 2022-03-07 thomas >/dev/null
205 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
206 069bbb86 2022-03-07 thomas test_done $testroot $ret
210 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
211 069bbb86 2022-03-07 thomas --- numbers
212 069bbb86 2022-03-07 thomas +++ numbers
213 069bbb86 2022-03-07 thomas @@ -3,7 +3,7 @@
224 069bbb86 2022-03-07 thomas echo "M numbers" > $testroot/stdout.expected
226 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
228 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
229 069bbb86 2022-03-07 thomas test_done $testroot $ret
233 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
235 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
236 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
237 069bbb86 2022-03-07 thomas test_done $testroot $ret
241 069bbb86 2022-03-07 thomas jot 10 | sed 's/6/foo/' > $testroot/wt/numbers.expected
242 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
244 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
245 069bbb86 2022-03-07 thomas diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
247 069bbb86 2022-03-07 thomas test_done $testroot $ret
250 069bbb86 2022-03-07 thomas test_patch_multiple_hunks() {
251 02e4f0d8 2022-03-08 thomas local testroot=`test_init patch_replace_multiple_hunks`
253 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
255 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
256 069bbb86 2022-03-07 thomas test_done $testroot $ret
260 069bbb86 2022-03-07 thomas jot 100 > $testroot/wt/numbers
261 069bbb86 2022-03-07 thomas (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
262 069bbb86 2022-03-07 thomas >/dev/null
264 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
265 069bbb86 2022-03-07 thomas test_done $testroot $ret
269 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
270 069bbb86 2022-03-07 thomas --- numbers
271 069bbb86 2022-03-07 thomas +++ numbers
272 069bbb86 2022-03-07 thomas @@ -3,7 +3,7 @@
281 069bbb86 2022-03-07 thomas @@ -57,7 +57,7 @@
290 069bbb86 2022-03-07 thomas @@ -98,3 +98,6 @@
299 069bbb86 2022-03-07 thomas echo "M numbers" > $testroot/stdout.expected
301 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
303 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
304 069bbb86 2022-03-07 thomas test_done $testroot $ret
308 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
310 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
311 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
312 069bbb86 2022-03-07 thomas test_done $testroot $ret
316 069bbb86 2022-03-07 thomas jot 100 | sed -e 's/^6$/foo/' -e 's/^60$/foo foo/' \
317 069bbb86 2022-03-07 thomas > $testroot/wt/numbers.expected
318 069bbb86 2022-03-07 thomas echo "101" >> $testroot/wt/numbers.expected
319 069bbb86 2022-03-07 thomas echo "102" >> $testroot/wt/numbers.expected
320 069bbb86 2022-03-07 thomas echo "..." >> $testroot/wt/numbers.expected
322 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
324 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
325 069bbb86 2022-03-07 thomas diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
327 069bbb86 2022-03-07 thomas test_done $testroot $ret
330 069bbb86 2022-03-07 thomas test_patch_multiple_files() {
331 069bbb86 2022-03-07 thomas local testroot=`test_init patch_multiple_files`
333 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
335 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
336 069bbb86 2022-03-07 thomas test_done $testroot $ret
340 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
341 069bbb86 2022-03-07 thomas --- alpha Mon Mar 7 19:02:07 2022
342 069bbb86 2022-03-07 thomas +++ alpha Mon Mar 7 19:01:53 2022
343 069bbb86 2022-03-07 thomas @@ -1 +1,3 @@
346 069bbb86 2022-03-07 thomas +available
347 069bbb86 2022-03-07 thomas --- beta Mon Mar 7 19:02:11 2022
348 069bbb86 2022-03-07 thomas +++ beta Mon Mar 7 19:01:46 2022
349 069bbb86 2022-03-07 thomas @@ -1 +1,3 @@
352 069bbb86 2022-03-07 thomas +improved
353 069bbb86 2022-03-07 thomas --- gamma/delta Mon Mar 7 19:02:17 2022
354 069bbb86 2022-03-07 thomas +++ gamma/delta Mon Mar 7 19:01:37 2022
355 069bbb86 2022-03-07 thomas @@ -1 +1 @@
357 069bbb86 2022-03-07 thomas +delta new
360 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
361 069bbb86 2022-03-07 thomas echo "M beta" >> $testroot/stdout.expected
362 069bbb86 2022-03-07 thomas echo "M gamma/delta" >> $testroot/stdout.expected
364 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
366 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
367 02e4f0d8 2022-03-08 thomas test_done $testroot $ret
371 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
373 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
374 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
375 069bbb86 2022-03-07 thomas test_done $testroot $ret
379 069bbb86 2022-03-07 thomas printf 'new\nalpha\navailable\n' > $testroot/wt/alpha.expected
380 069bbb86 2022-03-07 thomas printf 'beta\nwas\nimproved\n' > $testroot/wt/beta.expected
381 069bbb86 2022-03-07 thomas printf 'delta new\n' > $testroot/wt/gamma/delta.expected
383 069bbb86 2022-03-07 thomas for f in alpha beta gamma/delta; do
384 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/$f.expected $testroot/wt/$f
386 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
387 069bbb86 2022-03-07 thomas diff -u $testroot/wt/$f.expected $testroot/wt/$f
388 069bbb86 2022-03-07 thomas test_done $testroot $ret
393 069bbb86 2022-03-07 thomas test_done $testroot 0
396 069bbb86 2022-03-07 thomas test_patch_dont_apply() {
397 069bbb86 2022-03-07 thomas local testroot=`test_init patch_dont_apply`
399 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
401 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
402 069bbb86 2022-03-07 thomas test_done $testroot $ret
406 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
407 069bbb86 2022-03-07 thomas --- alpha
408 069bbb86 2022-03-07 thomas +++ alpha
409 069bbb86 2022-03-07 thomas @@ -1 +1,2 @@
410 069bbb86 2022-03-07 thomas +hatsuseno
411 069bbb86 2022-03-07 thomas alpha something
414 069bbb86 2022-03-07 thomas echo -n > $testroot/stdout.expected
415 069bbb86 2022-03-07 thomas echo "got: patch doesn't apply" > $testroot/stderr.expected
417 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) \
418 069bbb86 2022-03-07 thomas > $testroot/stdout \
419 069bbb86 2022-03-07 thomas 2> $testroot/stderr
421 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then # should fail
422 069bbb86 2022-03-07 thomas test_done $testroot 1
426 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
428 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
429 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
430 069bbb86 2022-03-07 thomas test_done $testroot $ret
434 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
436 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
437 069bbb86 2022-03-07 thomas diff -u $testroot/stderr.expected $testroot/stderr
438 069bbb86 2022-03-07 thomas test_done $testroot $ret
442 069bbb86 2022-03-07 thomas test_done $testroot $ret
445 069bbb86 2022-03-07 thomas test_patch_malformed() {
446 069bbb86 2022-03-07 thomas local testroot=`test_init patch_malformed`
448 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
450 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
451 069bbb86 2022-03-07 thomas test_done $testroot $ret
455 069bbb86 2022-03-07 thomas # missing "@@"
456 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
457 069bbb86 2022-03-07 thomas --- alpha
458 069bbb86 2022-03-07 thomas +++ alpha
459 069bbb86 2022-03-07 thomas @@ -1 +1,2
460 069bbb86 2022-03-07 thomas +hatsuseno
464 069bbb86 2022-03-07 thomas echo -n > $testroot/stdout.expected
465 069bbb86 2022-03-07 thomas echo "got: malformed patch" > $testroot/stderr.expected
467 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) \
468 069bbb86 2022-03-07 thomas > $testroot/stdout \
469 069bbb86 2022-03-07 thomas 2> $testroot/stderr
471 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then
472 069bbb86 2022-03-07 thomas echo "got managed to apply an invalid patch"
473 069bbb86 2022-03-07 thomas test_done $testroot 1
477 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
479 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
480 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
481 069bbb86 2022-03-07 thomas test_done $testroot $ret
485 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
487 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
488 069bbb86 2022-03-07 thomas diff -u $testroot/stderr.expected $testroot/stderr
489 069bbb86 2022-03-07 thomas test_done $testroot $ret
493 069bbb86 2022-03-07 thomas # wrong first character
494 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
495 069bbb86 2022-03-07 thomas --- alpha
496 069bbb86 2022-03-07 thomas +++ alpha
497 069bbb86 2022-03-07 thomas @@ -1 +1,2 @@
498 069bbb86 2022-03-07 thomas +hatsuseno
502 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) \
503 069bbb86 2022-03-07 thomas > $testroot/stdout \
504 069bbb86 2022-03-07 thomas 2> $testroot/stderr
506 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then
507 069bbb86 2022-03-07 thomas echo "got managed to apply an invalid patch"
508 069bbb86 2022-03-07 thomas test_done $testroot 1
512 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
514 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
515 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
516 069bbb86 2022-03-07 thomas test_done $testroot $ret
520 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
522 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
523 069bbb86 2022-03-07 thomas diff -u $testroot/stderr.expected $testroot/stderr
524 069bbb86 2022-03-07 thomas test_done $testroot $ret
528 069bbb86 2022-03-07 thomas test_done $testroot $ret
531 069bbb86 2022-03-07 thomas test_patch_no_patch() {
532 069bbb86 2022-03-07 thomas local testroot=`test_init patch_no_patch`
534 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
536 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
537 069bbb86 2022-03-07 thomas test_done $testroot $ret
541 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
542 069bbb86 2022-03-07 thomas hello world!
545 069bbb86 2022-03-07 thomas some other nonsense
548 069bbb86 2022-03-07 thomas there's no patch in here!
551 069bbb86 2022-03-07 thomas echo -n > $testroot/stdout.expected
552 069bbb86 2022-03-07 thomas echo "got: no patch found" > $testroot/stderr.expected
554 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) \
555 069bbb86 2022-03-07 thomas > $testroot/stdout \
556 069bbb86 2022-03-07 thomas 2> $testroot/stderr
558 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then # should fail
559 069bbb86 2022-03-07 thomas test_done $testroot 1
563 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
565 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
566 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
567 069bbb86 2022-03-07 thomas test_done $testroot $ret
571 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
573 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
574 069bbb86 2022-03-07 thomas diff -u $testroot/stderr.expected $testroot/stderr
575 069bbb86 2022-03-07 thomas test_done $testroot $ret
579 069bbb86 2022-03-07 thomas test_done $testroot $ret
582 069bbb86 2022-03-07 thomas test_patch_equals_for_context() {
583 069bbb86 2022-03-07 thomas local testroot=`test_init patch_prepend_line`
585 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
587 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
588 069bbb86 2022-03-07 thomas test_done $testroot $ret
592 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
593 069bbb86 2022-03-07 thomas --- alpha
594 069bbb86 2022-03-07 thomas +++ alpha
595 069bbb86 2022-03-07 thomas @@ -1 +1,2 @@
596 069bbb86 2022-03-07 thomas +hatsuseno
600 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
602 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
604 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
605 069bbb86 2022-03-07 thomas test_done $testroot $ret
609 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
611 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
612 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
613 069bbb86 2022-03-07 thomas test_done $testroot $ret
617 069bbb86 2022-03-07 thomas echo hatsuseno > $testroot/wt/alpha.expected
618 069bbb86 2022-03-07 thomas echo alpha >> $testroot/wt/alpha.expected
619 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
621 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
622 069bbb86 2022-03-07 thomas diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
624 069bbb86 2022-03-07 thomas test_done $testroot $ret
627 069bbb86 2022-03-07 thomas test_parseargs "$@"
628 069bbb86 2022-03-07 thomas run_test test_patch_simple_add_file
629 069bbb86 2022-03-07 thomas run_test test_patch_simple_rm_file
630 069bbb86 2022-03-07 thomas run_test test_patch_simple_edit_file
631 069bbb86 2022-03-07 thomas run_test test_patch_prepend_line
632 069bbb86 2022-03-07 thomas run_test test_patch_replace_line
633 069bbb86 2022-03-07 thomas run_test test_patch_multiple_hunks
634 069bbb86 2022-03-07 thomas run_test test_patch_multiple_files
635 069bbb86 2022-03-07 thomas run_test test_patch_dont_apply
636 069bbb86 2022-03-07 thomas run_test test_patch_malformed
637 069bbb86 2022-03-07 thomas run_test test_patch_no_patch
638 069bbb86 2022-03-07 thomas run_test test_patch_equals_for_context