rpatch 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,203 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright (c) 2013 Jiang Xin
4
+ #
5
+
6
+ test_description='patch file test'
7
+
8
+ . ./test-lib.sh
9
+
10
+ ############################################################
11
+
12
+ cat > diff <<EOF
13
+ diff -u a/foo b/foo
14
+ --- a/foo 2013-11-04 16:01:56.000000000 +0800
15
+ +++ b/foo 2013-11-04 16:01:59.000000000 +0800
16
+ @@ add two lines
17
+ +baz
18
+ +foo
19
+ diff -u a/bar b/bar
20
+ --- a/bar 2013-11-04 16:01:56.000000000 +0800
21
+ +++ b/bar 2013-11-04 16:01:59.000000000 +0800
22
+ @@ add two lines
23
+ +baz
24
+ +bar
25
+ EOF
26
+
27
+ cat > expect <<EOF
28
+ EOF
29
+
30
+ cat > expect_errlog <<EOF
31
+ Error: Multiple patch entries (2) have been found in patch <IO>
32
+ Error: Multiple patch entries (2) have been found in patch <IO>
33
+ EOF
34
+
35
+ test_expect_success 'cannot patch single file with multi patch entries' '
36
+ touch ! -f actual &&
37
+ touch actual &&
38
+ test_must_fail rpatch actual < diff 2>actual_errlog &&
39
+ test_cmp expect actual &&
40
+ test_cmp expect_errlog actual_errlog
41
+ '
42
+
43
+ ############################################################
44
+
45
+ cat > expect_errlog <<EOF
46
+ Patched "output/foo".
47
+ Patched "output/bar".
48
+ EOF
49
+
50
+ cat > expect_foo <<EOF
51
+ baz
52
+ foo
53
+ EOF
54
+
55
+ cat > expect_bar <<EOF
56
+ baz
57
+ bar
58
+ EOF
59
+
60
+ test_expect_success 'Patch on directory: create new file automatically' '
61
+ mkdir output &&
62
+ rpatch output < diff 2>actual_errlog &&
63
+ test -f output/foo &&
64
+ test -f output/bar &&
65
+ test_cmp expect_foo output/foo &&
66
+ test_cmp expect_bar output/bar &&
67
+ test_cmp expect_errlog actual_errlog
68
+ '
69
+
70
+ ############################################################
71
+
72
+ cat > diff <<EOF
73
+ diff -u a/foo b/foo
74
+ --- a/foo 2013-11-04 16:01:56.000000000 +0800
75
+ +++ b/foo 2013-11-04 16:01:59.000000000 +0800
76
+ @@ heading
77
+ +heading of foo...
78
+ -baz
79
+ @@ tail
80
+ foo
81
+ +tail of foo ...
82
+ diff -u a/bar b/bar
83
+ --- a/bar 2013-11-04 16:01:56.000000000 +0800
84
+ +++ b/bar 2013-11-04 16:01:59.000000000 +0800
85
+ @@ heading
86
+ +heading of bar...
87
+ -baz
88
+ @@ tail
89
+ bar
90
+ +tail of bar ...
91
+ EOF
92
+
93
+ cat > expect_errlog <<EOF
94
+ Patched "output/foo".
95
+ Patched "output/bar".
96
+ EOF
97
+
98
+ cat > expect_foo <<EOF
99
+ heading of foo...
100
+ foo
101
+ tail of foo ...
102
+ EOF
103
+
104
+ cat > expect_bar <<EOF
105
+ heading of bar...
106
+ bar
107
+ tail of bar ...
108
+ EOF
109
+
110
+ test_expect_success 'Patch on directory (2): patch exist files' '
111
+ rpatch output < diff 2>actual_errlog &&
112
+ test -f output/foo &&
113
+ test -f output/bar &&
114
+ test_cmp expect_foo output/foo &&
115
+ test_cmp expect_bar output/bar &&
116
+ test_cmp expect_errlog actual_errlog
117
+ '
118
+
119
+ ############################################################
120
+
121
+ cat > diff <<EOF
122
+ diff -u a/foo b/foo
123
+ --- a/foo 2013-11-04 16:01:56.000000000 +0800
124
+ +++ b/foo 2013-11-04 16:01:59.000000000 +0800
125
+ @@ can not match
126
+ heading of foo...
127
+ foobar
128
+ -tail of foo ...
129
+ diff -u a/bar b/bar
130
+ --- a/bar 2013-11-04 16:01:56.000000000 +0800
131
+ +++ b/bar 2013-11-04 16:01:59.000000000 +0800
132
+ @@ remove tail
133
+ heading of bar...
134
+ bar
135
+ -tail of bar ...
136
+ EOF
137
+
138
+ cat > expect_errlog <<EOF
139
+ ERROR: output/foo: Hunk 1 (can not match) FAILED to apply. Match failed.
140
+ output/foo: nothing changed
141
+ Patched "output/bar".
142
+ EOF
143
+
144
+ cat > expect_foo <<EOF
145
+ heading of foo...
146
+ foo
147
+ tail of foo ...
148
+ EOF
149
+
150
+ cat > expect_bar <<EOF
151
+ heading of bar...
152
+ bar
153
+ EOF
154
+
155
+ test_expect_success 'Patch on directory (3): one fail, another success' '
156
+ test_must_fail rpatch output < diff 2>actual_errlog &&
157
+ test -f output/foo &&
158
+ test -f output/bar &&
159
+ test_cmp expect_foo output/foo &&
160
+ test_cmp expect_bar output/bar &&
161
+ test_cmp expect_errlog actual_errlog
162
+ '
163
+
164
+ ############################################################
165
+
166
+ cat > diff <<EOF
167
+ diff -u a/foo b/foo
168
+ --- a/foo 2013-11-04 16:01:56.000000000 +0800
169
+ +++ b/foo 2013-11-04 16:01:59.000000000 +0800
170
+ @@ can not match
171
+ RE:-heading
172
+ RE:-foo
173
+ RE:-tail.*
174
+ diff -u a/bar b/bar
175
+ --- a/bar 2013-11-04 16:01:56.000000000 +0800
176
+ +++ b/bar 2013-11-04 16:01:59.000000000 +0800
177
+ @@ add tail
178
+ RE: ^[bB][aA][rR]$
179
+ +tail of bar...
180
+ EOF
181
+
182
+ cat > expect_errlog <<EOF
183
+ Remove "output/foo".
184
+ Patched "output/bar".
185
+ EOF
186
+
187
+ cat > expect_bar <<EOF
188
+ heading of bar...
189
+ bar
190
+ tail of bar...
191
+ EOF
192
+
193
+ test_expect_success 'Patch on directory (4): remove file' '
194
+ rpatch -p1 output < diff 2>actual_errlog &&
195
+ test ! -f output/foo &&
196
+ test -f output/bar &&
197
+ test_cmp expect_bar output/bar &&
198
+ test_cmp expect_errlog actual_errlog
199
+ '
200
+
201
+ ############################################################
202
+
203
+ test_done