shithub: regress

Download patch

ref: fa29f36fe713a4bbdfca6770ebb3867436c1ac18
parent: 75f5c7d3948bc647b21272c2e0bcbf841fb4d9f7
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jun 3 21:57:51 EDT 2022

patch: add tests for our new patch program

--- a/cmd/mkfile
+++ b/cmd/mkfile
@@ -4,6 +4,7 @@
 	cpp\
 	date\
 	git\
+	patch\
 	test\
 
 <../regress
--- /dev/null
+++ b/cmd/patch/basic.expected
@@ -1,0 +1,100 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+100
--- /dev/null
+++ b/cmd/patch/basic.in
@@ -1,0 +1,93 @@
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+13
+12
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
--- /dev/null
+++ b/cmd/patch/basic.patch
@@ -1,0 +1,42 @@
+--- basic.in
++++ basic.out
+@@ -1,3 +1,5 @@
++1
++2
+ 3
+ 4
+ 5
+@@ -10,8 +12,8 @@
+ 12
+ 13
+ 14
+-13
+-12
++15
++16
+ 17
+ 18
+ 19
+@@ -35,6 +37,8 @@
+ 37
+ 38
+ 39
++40
++41
+ 42
+ 43
+ 44
+@@ -80,6 +84,7 @@
+ 84
+ 85
+ 86
++87
+ 88
+ 89
+ 90
+@@ -91,3 +96,5 @@
+ 96
+ 97
+ 98
++99
++100
--- /dev/null
+++ b/cmd/patch/create.expected
@@ -1,0 +1,12 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
--- /dev/null
+++ b/cmd/patch/create.patch
@@ -1,0 +1,15 @@
+--- /dev/null
++++ create.out
+@@ -1,0 +1,12 @@
++1
++2
++3
++4
++5
++6
++7
++8
++9
++10
++11
++12
--- /dev/null
+++ b/cmd/patch/delete.expected
@@ -1,0 +1,10 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
--- /dev/null
+++ b/cmd/patch/delete.patch
@@ -1,0 +1,15 @@
+--- delete.out
++++ /dev/null
+@@ -1,12 +1,0 @@
+-1
+-2
+-3
+-4
+-5
+-6
+-7
+-8
+-9
+-10
+-11
+-12
--- /dev/null
+++ b/cmd/patch/header.expected
@@ -1,0 +1,100 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+100
--- /dev/null
+++ b/cmd/patch/header.in
@@ -1,0 +1,93 @@
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+13
+12
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
--- /dev/null
+++ b/cmd/patch/header.patch
@@ -1,0 +1,54 @@
+diff should handle headers just fine, so
+this file contains a few lines of header
+and footer, with a couple of false starts,
+consisting of lines starting with
+--- some words
+but no immediately following 
++++ words
+lines
+
+--- header.in
++++ header.out
+@@ -1,3 +1,5 @@
++1
++2
+ 3
+ 4
+ 5
+@@ -10,8 +12,8 @@
+ 12
+ 13
+ 14
+-13
+-12
++15
++16
+ 17
+ 18
+ 19
+@@ -35,6 +37,8 @@
+ 37
+ 38
+ 39
++40
++41
+ 42
+ 43
+ 44
+@@ -80,6 +84,7 @@
+ 84
+ 85
+ 86
++87
+ 88
+ 89
+ 90
+@@ -91,3 +96,5 @@
+ 96
+ 97
+ 98
++99
++100
+-- signature footer: should not get picked up
+and here is the footer that should
+also be ignored.
--- /dev/null
+++ b/cmd/patch/mkfile
@@ -1,0 +1,5 @@
+</$objtype/mkfile
+
+TEST=patch
+
+<../../regress
--- /dev/null
+++ b/cmd/patch/multifile.patch
@@ -1,0 +1,89 @@
+--- multifile2.in
++++ multifile2.out
+@@ -1,21 +1,19 @@
+-77777
+ 77778
+ 77779
+ 77780
+ 77781
+ 77782
+-77783
+-77784
+-77785
+-77786
+-77787
+-77788
+ 77789
++77788
++77787
++77786
++77785
++77784
++77783
+ 77790
+ 77791
+ 77792
+ 77793
+ 77794
+-77795
+ 77796
+ 77797
+
+of course, each patch can have its own comment
+lines mixed in, so we should handle these.
+--- multifile1.in
++++ multifile1.out
+@@ -14,16 +14,6 @@
+ 12
+ 17
+ 18
+-19
+-20
+-21
+-22
+-23
+-24
+-25
+-26
+-27
+-28
+ 29
+ 30
+ 31
+@@ -32,20 +22,6 @@
+ 34
+ 35
+ 36
+-37
+-38
+-39
+-42
+-43
+-44
+-45
+-46
+-47
+-48
+-49
+-50
+-51
+-52
+ 53
+ 54
+ 55
+@@ -73,11 +49,11 @@
+ 77
+ 78
+ 79
+-80
+-81
+-82
+-83
+ 84
++83
++82
++81
++80
+ 85
+ 86
+ 88
--- /dev/null
+++ b/cmd/patch/multifile1.expected
@@ -1,0 +1,69 @@
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+13
+12
+17
+18
+29
+30
+31
+32
+33
+34
+35
+36
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+84
+83
+82
+81
+80
+85
+86
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
--- /dev/null
+++ b/cmd/patch/multifile1.in
@@ -1,0 +1,93 @@
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+13
+12
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
--- /dev/null
+++ b/cmd/patch/multifile2.expected
@@ -1,0 +1,19 @@
+77778
+77779
+77780
+77781
+77782
+77789
+77788
+77787
+77786
+77785
+77784
+77783
+77790
+77791
+77792
+77793
+77794
+77796
+77797
--- /dev/null
+++ b/cmd/patch/multifile2.in
@@ -1,0 +1,21 @@
+77777
+77778
+77779
+77780
+77781
+77782
+77783
+77784
+77785
+77786
+77787
+77788
+77789
+77790
+77791
+77792
+77793
+77794
+77795
+77796
+77797
--- /dev/null
+++ b/cmd/patch/nop.expected
@@ -1,0 +1,10 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
--- /dev/null
+++ b/cmd/patch/patch.rc
@@ -1,0 +1,31 @@
+#!/bin/rc -e
+
+fn check{
+	if(! cmp $1 $2){
+		>[2=1] echo fail: $1 $2
+		>[2=1] diff -u $1 $2
+		exit mismatch
+	}
+	status=()
+}
+
+fn checkpatch{
+	rm -f $1.out
+	patch $1.patch
+	check $1.out $1.expected
+}
+
+checkpatch basic
+checkpatch header
+checkpatch create
+
+seq 12 > delete.out
+patch delete.patch
+test ! -f delete.out
+
+rm -f multifile^(1 2)^.out
+patch multifile.patch
+check multifile1.out multifile1.expected
+check multifile2.out multifile2.expected
+
+status=()