Blame


1 e9ce266e 2022-03-07 op #!/bin/sh
2 e9ce266e 2022-03-07 op #
3 e9ce266e 2022-03-07 op # Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 e9ce266e 2022-03-07 op #
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.
8 e9ce266e 2022-03-07 op #
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.
16 e9ce266e 2022-03-07 op
17 e9ce266e 2022-03-07 op . ./common.sh
18 e9ce266e 2022-03-07 op
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`
21 e9ce266e 2022-03-07 op
22 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
23 e9ce266e 2022-03-07 op ret=$?
24 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
25 e9ce266e 2022-03-07 op test_done $testroot $ret
26 e9ce266e 2022-03-07 op return 1
27 e9ce266e 2022-03-07 op fi
28 e9ce266e 2022-03-07 op
29 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
30 e9ce266e 2022-03-07 op --- /dev/null
31 e9ce266e 2022-03-07 op +++ eta
32 e9ce266e 2022-03-07 op @@ -0,0 +1 @@
33 e9ce266e 2022-03-07 op +eta
34 e9ce266e 2022-03-07 op EOF
35 e9ce266e 2022-03-07 op
36 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
37 e9ce266e 2022-03-07 op ret=$?
38 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
39 e9ce266e 2022-03-07 op test_done $testroot $ret
40 e9ce266e 2022-03-07 op return 1
41 e9ce266e 2022-03-07 op fi
42 e9ce266e 2022-03-07 op
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
45 e9ce266e 2022-03-07 op ret=$?
46 e9ce266e 2022-03-07 op if [ $ret != 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
49 e9ce266e 2022-03-07 op return 1
50 e9ce266e 2022-03-07 op fi
51 e9ce266e 2022-03-07 op
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
54 e9ce266e 2022-03-07 op ret=$?
55 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
56 e9ce266e 2022-03-07 op diff -u $testroot/wt/eta.expected $testroot/wt/eta
57 e9ce266e 2022-03-07 op fi
58 e9ce266e 2022-03-07 op test_done $testroot $ret
59 e9ce266e 2022-03-07 op }
60 e9ce266e 2022-03-07 op
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`
63 e9ce266e 2022-03-07 op
64 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
65 e9ce266e 2022-03-07 op ret=$?
66 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
67 e9ce266e 2022-03-07 op test_done $testroot $ret
68 e9ce266e 2022-03-07 op return 1
69 e9ce266e 2022-03-07 op fi
70 e9ce266e 2022-03-07 op
71 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
72 e9ce266e 2022-03-07 op --- alpha
73 e9ce266e 2022-03-07 op +++ /dev/null
74 e9ce266e 2022-03-07 op @@ -1 +0,0 @@
75 e9ce266e 2022-03-07 op -alpha
76 e9ce266e 2022-03-07 op EOF
77 e9ce266e 2022-03-07 op
78 e9ce266e 2022-03-07 op echo "D alpha" > $testroot/stdout.expected
79 e9ce266e 2022-03-07 op
80 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
81 e9ce266e 2022-03-07 op ret=$?
82 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
83 e9ce266e 2022-03-07 op test_done $testroot $ret
84 e9ce266e 2022-03-07 op return 1
85 e9ce266e 2022-03-07 op fi
86 e9ce266e 2022-03-07 op
87 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
88 e9ce266e 2022-03-07 op ret=$?
89 e9ce266e 2022-03-07 op if [ $ret != 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
92 e9ce266e 2022-03-07 op return 1
93 e9ce266e 2022-03-07 op fi
94 e9ce266e 2022-03-07 op
95 e9ce266e 2022-03-07 op if [ -f $testroot/wt/alpha ]; then
96 e9ce266e 2022-03-07 op ret=1
97 e9ce266e 2022-03-07 op echo "alpha still exists!"
98 e9ce266e 2022-03-07 op fi
99 e9ce266e 2022-03-07 op test_done $testroot $ret
100 e9ce266e 2022-03-07 op }
101 e9ce266e 2022-03-07 op
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`
104 e9ce266e 2022-03-07 op
105 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
106 e9ce266e 2022-03-07 op ret=$?
107 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
108 e9ce266e 2022-03-07 op test_done $testroot $ret
109 e9ce266e 2022-03-07 op return 1
110 e9ce266e 2022-03-07 op fi
111 e9ce266e 2022-03-07 op
112 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
113 e9ce266e 2022-03-07 op --- alpha
114 e9ce266e 2022-03-07 op +++ alpha
115 e9ce266e 2022-03-07 op @@ -1 +1 @@
116 e9ce266e 2022-03-07 op -alpha
117 e9ce266e 2022-03-07 op +alpha is my favourite character
118 e9ce266e 2022-03-07 op EOF
119 e9ce266e 2022-03-07 op
120 e9ce266e 2022-03-07 op echo "M alpha" > $testroot/stdout.expected
121 e9ce266e 2022-03-07 op
122 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
123 e9ce266e 2022-03-07 op ret=$?
124 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
125 e9ce266e 2022-03-07 op test_done $testroot $ret
126 e9ce266e 2022-03-07 op return 1
127 e9ce266e 2022-03-07 op fi
128 e9ce266e 2022-03-07 op
129 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
130 e9ce266e 2022-03-07 op ret=$?
131 e9ce266e 2022-03-07 op if [ $ret != 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
134 e9ce266e 2022-03-07 op return 1
135 e9ce266e 2022-03-07 op fi
136 e9ce266e 2022-03-07 op
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
139 e9ce266e 2022-03-07 op ret=$?
140 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
141 e9ce266e 2022-03-07 op diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
142 e9ce266e 2022-03-07 op fi
143 e9ce266e 2022-03-07 op test_done $testroot $ret
144 e9ce266e 2022-03-07 op }
145 e9ce266e 2022-03-07 op
146 e9ce266e 2022-03-07 op test_patch_prepend_line() {
147 e9ce266e 2022-03-07 op local testroot=`test_init patch_prepend_line`
148 e9ce266e 2022-03-07 op
149 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
150 e9ce266e 2022-03-07 op ret=$?
151 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
152 e9ce266e 2022-03-07 op test_done $testroot $ret
153 e9ce266e 2022-03-07 op return 1
154 e9ce266e 2022-03-07 op fi
155 e9ce266e 2022-03-07 op
156 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
157 e9ce266e 2022-03-07 op --- alpha
158 e9ce266e 2022-03-07 op +++ alpha
159 e9ce266e 2022-03-07 op @@ -1 +1,2 @@
160 e9ce266e 2022-03-07 op +hatsuseno
161 e9ce266e 2022-03-07 op alpha
162 e9ce266e 2022-03-07 op EOF
163 e9ce266e 2022-03-07 op
164 e9ce266e 2022-03-07 op echo "M alpha" > $testroot/stdout.expected
165 e9ce266e 2022-03-07 op
166 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
167 e9ce266e 2022-03-07 op ret=$?
168 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
169 e9ce266e 2022-03-07 op test_done $testroot $ret
170 e9ce266e 2022-03-07 op return 1
171 e9ce266e 2022-03-07 op fi
172 e9ce266e 2022-03-07 op
173 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
174 e9ce266e 2022-03-07 op ret=$?
175 e9ce266e 2022-03-07 op if [ $ret != 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
178 e9ce266e 2022-03-07 op return 1
179 e9ce266e 2022-03-07 op fi
180 e9ce266e 2022-03-07 op
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
184 e9ce266e 2022-03-07 op ret=$?
185 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
186 e9ce266e 2022-03-07 op diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
187 e9ce266e 2022-03-07 op fi
188 e9ce266e 2022-03-07 op test_done $testroot $ret
189 e9ce266e 2022-03-07 op }
190 e9ce266e 2022-03-07 op
191 e9ce266e 2022-03-07 op test_patch_replace_line() {
192 e9ce266e 2022-03-07 op local testroot=`test_init patch_replace_line`
193 e9ce266e 2022-03-07 op
194 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
195 e9ce266e 2022-03-07 op ret=$?
196 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
197 e9ce266e 2022-03-07 op test_done $testroot $ret
198 e9ce266e 2022-03-07 op return 1
199 e9ce266e 2022-03-07 op fi
200 e9ce266e 2022-03-07 op
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') \
203 e9ce266e 2022-03-07 op >/dev/null
204 e9ce266e 2022-03-07 op ret=$?
205 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
206 e9ce266e 2022-03-07 op test_done $testroot $ret
207 e9ce266e 2022-03-07 op return 1
208 e9ce266e 2022-03-07 op fi
209 e9ce266e 2022-03-07 op
210 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
211 e9ce266e 2022-03-07 op --- numbers
212 e9ce266e 2022-03-07 op +++ numbers
213 e9ce266e 2022-03-07 op @@ -3,7 +3,7 @@
214 e9ce266e 2022-03-07 op 3
215 e9ce266e 2022-03-07 op 4
216 e9ce266e 2022-03-07 op 5
217 e9ce266e 2022-03-07 op -6
218 e9ce266e 2022-03-07 op +foo
219 e9ce266e 2022-03-07 op 7
220 e9ce266e 2022-03-07 op 8
221 e9ce266e 2022-03-07 op 9
222 e9ce266e 2022-03-07 op EOF
223 e9ce266e 2022-03-07 op
224 e9ce266e 2022-03-07 op echo "M numbers" > $testroot/stdout.expected
225 e9ce266e 2022-03-07 op
226 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
227 e9ce266e 2022-03-07 op ret=$?
228 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
229 e9ce266e 2022-03-07 op test_done $testroot $ret
230 e9ce266e 2022-03-07 op return 1
231 e9ce266e 2022-03-07 op fi
232 e9ce266e 2022-03-07 op
233 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
234 e9ce266e 2022-03-07 op ret=$?
235 e9ce266e 2022-03-07 op if [ $ret != 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
238 e9ce266e 2022-03-07 op return 1
239 e9ce266e 2022-03-07 op fi
240 e9ce266e 2022-03-07 op
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
243 e9ce266e 2022-03-07 op ret=$?
244 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
245 e9ce266e 2022-03-07 op diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
246 e9ce266e 2022-03-07 op fi
247 e9ce266e 2022-03-07 op test_done $testroot $ret
248 e9ce266e 2022-03-07 op }
249 e9ce266e 2022-03-07 op
250 e9ce266e 2022-03-07 op test_patch_multiple_hunks() {
251 e9ce266e 2022-03-07 op local testroot=`test_init patch_replace_multiple_lines`
252 e9ce266e 2022-03-07 op
253 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
254 e9ce266e 2022-03-07 op ret=$?
255 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
256 e9ce266e 2022-03-07 op test_done $testroot $ret
257 e9ce266e 2022-03-07 op return 1
258 e9ce266e 2022-03-07 op fi
259 e9ce266e 2022-03-07 op
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') \
262 e9ce266e 2022-03-07 op >/dev/null
263 e9ce266e 2022-03-07 op ret=$?
264 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
265 e9ce266e 2022-03-07 op test_done $testroot $ret
266 e9ce266e 2022-03-07 op return 1
267 e9ce266e 2022-03-07 op fi
268 e9ce266e 2022-03-07 op
269 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
270 e9ce266e 2022-03-07 op --- numbers
271 e9ce266e 2022-03-07 op +++ numbers
272 e9ce266e 2022-03-07 op @@ -3,7 +3,7 @@
273 e9ce266e 2022-03-07 op 3
274 e9ce266e 2022-03-07 op 4
275 e9ce266e 2022-03-07 op 5
276 e9ce266e 2022-03-07 op -6
277 e9ce266e 2022-03-07 op +foo
278 e9ce266e 2022-03-07 op 7
279 e9ce266e 2022-03-07 op 8
280 e9ce266e 2022-03-07 op 9
281 e9ce266e 2022-03-07 op @@ -57,7 +57,7 @@
282 e9ce266e 2022-03-07 op 57
283 e9ce266e 2022-03-07 op 58
284 e9ce266e 2022-03-07 op 59
285 e9ce266e 2022-03-07 op -60
286 e9ce266e 2022-03-07 op +foo foo
287 e9ce266e 2022-03-07 op 61
288 e9ce266e 2022-03-07 op 62
289 e9ce266e 2022-03-07 op 63
290 e9ce266e 2022-03-07 op @@ -98,3 +98,6 @@
291 e9ce266e 2022-03-07 op 98
292 e9ce266e 2022-03-07 op 99
293 e9ce266e 2022-03-07 op 100
294 e9ce266e 2022-03-07 op +101
295 e9ce266e 2022-03-07 op +102
296 e9ce266e 2022-03-07 op +...
297 e9ce266e 2022-03-07 op EOF
298 e9ce266e 2022-03-07 op
299 e9ce266e 2022-03-07 op echo "M numbers" > $testroot/stdout.expected
300 e9ce266e 2022-03-07 op
301 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
302 e9ce266e 2022-03-07 op ret=$?
303 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
304 e9ce266e 2022-03-07 op test_done $testroot $ret
305 e9ce266e 2022-03-07 op return 1
306 e9ce266e 2022-03-07 op fi
307 e9ce266e 2022-03-07 op
308 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
309 e9ce266e 2022-03-07 op ret=$?
310 e9ce266e 2022-03-07 op if [ $ret != 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
313 e9ce266e 2022-03-07 op return 1
314 e9ce266e 2022-03-07 op fi
315 e9ce266e 2022-03-07 op
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
321 e9ce266e 2022-03-07 op
322 e9ce266e 2022-03-07 op cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
323 e9ce266e 2022-03-07 op ret=$?
324 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
325 e9ce266e 2022-03-07 op diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
326 e9ce266e 2022-03-07 op fi
327 e9ce266e 2022-03-07 op test_done $testroot $ret
328 e9ce266e 2022-03-07 op }
329 e9ce266e 2022-03-07 op
330 e9ce266e 2022-03-07 op test_patch_multiple_files() {
331 e9ce266e 2022-03-07 op local testroot=`test_init patch_multiple_files`
332 e9ce266e 2022-03-07 op
333 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
334 e9ce266e 2022-03-07 op ret=$?
335 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
336 e9ce266e 2022-03-07 op test_done $testroot $ret
337 e9ce266e 2022-03-07 op return 1
338 e9ce266e 2022-03-07 op fi
339 e9ce266e 2022-03-07 op
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 @@
344 e9ce266e 2022-03-07 op +new
345 e9ce266e 2022-03-07 op alpha
346 e9ce266e 2022-03-07 op +available
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 @@
350 e9ce266e 2022-03-07 op beta
351 e9ce266e 2022-03-07 op +was
352 e9ce266e 2022-03-07 op +improved
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
355 e9ce266e 2022-03-07 op @@ -1 +1 @@
356 e9ce266e 2022-03-07 op -delta
357 e9ce266e 2022-03-07 op +delta new
358 e9ce266e 2022-03-07 op EOF
359 e9ce266e 2022-03-07 op
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
363 e9ce266e 2022-03-07 op
364 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
365 e9ce266e 2022-03-07 op ret=$?
366 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
367 e9ce266e 2022-03-07 op test_done $testrot $ret
368 e9ce266e 2022-03-07 op return 1
369 e9ce266e 2022-03-07 op fi
370 e9ce266e 2022-03-07 op
371 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
372 e9ce266e 2022-03-07 op ret=$?
373 e9ce266e 2022-03-07 op if [ $ret != 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
376 e9ce266e 2022-03-07 op return 1
377 e9ce266e 2022-03-07 op fi
378 e9ce266e 2022-03-07 op
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
382 e9ce266e 2022-03-07 op
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
385 e9ce266e 2022-03-07 op ret=$?
386 e9ce266e 2022-03-07 op if [ $ret != 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
389 e9ce266e 2022-03-07 op return 1
390 e9ce266e 2022-03-07 op fi
391 e9ce266e 2022-03-07 op done
392 e9ce266e 2022-03-07 op
393 e9ce266e 2022-03-07 op test_done $testroot 0
394 e9ce266e 2022-03-07 op }
395 e9ce266e 2022-03-07 op
396 e9ce266e 2022-03-07 op test_patch_dont_apply() {
397 e9ce266e 2022-03-07 op local testroot=`test_init patch_dont_apply`
398 e9ce266e 2022-03-07 op
399 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
400 e9ce266e 2022-03-07 op ret=$?
401 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
402 e9ce266e 2022-03-07 op test_done $testroot $ret
403 e9ce266e 2022-03-07 op return 1
404 e9ce266e 2022-03-07 op fi
405 e9ce266e 2022-03-07 op
406 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
407 e9ce266e 2022-03-07 op --- alpha
408 e9ce266e 2022-03-07 op +++ alpha
409 e9ce266e 2022-03-07 op @@ -1 +1,2 @@
410 e9ce266e 2022-03-07 op +hatsuseno
411 e9ce266e 2022-03-07 op alpha something
412 e9ce266e 2022-03-07 op EOF
413 e9ce266e 2022-03-07 op
414 e9ce266e 2022-03-07 op echo -n > $testroot/stdout.expected
415 e9ce266e 2022-03-07 op echo "got: patch doesn't apply" > $testroot/stderr.expected
416 e9ce266e 2022-03-07 op
417 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) \
418 e9ce266e 2022-03-07 op > $testroot/stdout \
419 e9ce266e 2022-03-07 op 2> $testroot/stderr
420 e9ce266e 2022-03-07 op ret=$?
421 e9ce266e 2022-03-07 op if [ $ret == 0 ]; then # should fail
422 e9ce266e 2022-03-07 op test_done $testroot 1
423 e9ce266e 2022-03-07 op return 1
424 e9ce266e 2022-03-07 op fi
425 e9ce266e 2022-03-07 op
426 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
427 e9ce266e 2022-03-07 op ret=$?
428 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
429 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
430 e9ce266e 2022-03-07 op test_done $testroot $ret
431 e9ce266e 2022-03-07 op return 1
432 e9ce266e 2022-03-07 op fi
433 e9ce266e 2022-03-07 op
434 e9ce266e 2022-03-07 op cmp -s $testroot/stderr.expected $testroot/stderr
435 e9ce266e 2022-03-07 op ret=$?
436 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
437 e9ce266e 2022-03-07 op diff -u $testroot/stderr.expected $testroot/stderr
438 e9ce266e 2022-03-07 op test_done $testroot $ret
439 e9ce266e 2022-03-07 op return 1
440 e9ce266e 2022-03-07 op fi
441 e9ce266e 2022-03-07 op
442 e9ce266e 2022-03-07 op test_done $testroot $ret
443 e9ce266e 2022-03-07 op }
444 e9ce266e 2022-03-07 op
445 e9ce266e 2022-03-07 op test_patch_malformed() {
446 e9ce266e 2022-03-07 op local testroot=`test_init patch_malformed`
447 e9ce266e 2022-03-07 op
448 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
449 e9ce266e 2022-03-07 op ret=$?
450 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
451 e9ce266e 2022-03-07 op test_done $testroot $ret
452 e9ce266e 2022-03-07 op return 1
453 e9ce266e 2022-03-07 op fi
454 e9ce266e 2022-03-07 op
455 e9ce266e 2022-03-07 op # missing "@@"
456 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
457 e9ce266e 2022-03-07 op --- alpha
458 e9ce266e 2022-03-07 op +++ alpha
459 e9ce266e 2022-03-07 op @@ -1 +1,2
460 e9ce266e 2022-03-07 op +hatsuseno
461 e9ce266e 2022-03-07 op alpha
462 e9ce266e 2022-03-07 op EOF
463 e9ce266e 2022-03-07 op
464 e9ce266e 2022-03-07 op echo -n > $testroot/stdout.expected
465 e9ce266e 2022-03-07 op echo "got: malformed patch" > $testroot/stderr.expected
466 e9ce266e 2022-03-07 op
467 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) \
468 e9ce266e 2022-03-07 op > $testroot/stdout \
469 e9ce266e 2022-03-07 op 2> $testroot/stderr
470 e9ce266e 2022-03-07 op ret=$?
471 e9ce266e 2022-03-07 op if [ $ret == 0 ]; then
472 e9ce266e 2022-03-07 op echo "got managed to apply an invalid patch"
473 e9ce266e 2022-03-07 op test_done $testroot 1
474 e9ce266e 2022-03-07 op return 1
475 e9ce266e 2022-03-07 op fi
476 e9ce266e 2022-03-07 op
477 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
478 e9ce266e 2022-03-07 op ret=$?
479 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
480 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
481 e9ce266e 2022-03-07 op test_done $testroot $ret
482 e9ce266e 2022-03-07 op return 1
483 e9ce266e 2022-03-07 op fi
484 e9ce266e 2022-03-07 op
485 e9ce266e 2022-03-07 op cmp -s $testroot/stderr.expected $testroot/stderr
486 e9ce266e 2022-03-07 op ret=$?
487 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
488 e9ce266e 2022-03-07 op diff -u $testroot/stderr.expected $testroot/stderr
489 e9ce266e 2022-03-07 op test_done $testroot $ret
490 e9ce266e 2022-03-07 op return 1
491 e9ce266e 2022-03-07 op fi
492 e9ce266e 2022-03-07 op
493 e9ce266e 2022-03-07 op # wrong first character
494 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
495 e9ce266e 2022-03-07 op --- alpha
496 e9ce266e 2022-03-07 op +++ alpha
497 e9ce266e 2022-03-07 op @@ -1 +1,2 @@
498 e9ce266e 2022-03-07 op +hatsuseno
499 e9ce266e 2022-03-07 op alpha
500 e9ce266e 2022-03-07 op EOF
501 e9ce266e 2022-03-07 op
502 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) \
503 e9ce266e 2022-03-07 op > $testroot/stdout \
504 e9ce266e 2022-03-07 op 2> $testroot/stderr
505 e9ce266e 2022-03-07 op ret=$?
506 e9ce266e 2022-03-07 op if [ $ret == 0 ]; then
507 e9ce266e 2022-03-07 op echo "got managed to apply an invalid patch"
508 e9ce266e 2022-03-07 op test_done $testroot 1
509 e9ce266e 2022-03-07 op return 1
510 e9ce266e 2022-03-07 op fi
511 e9ce266e 2022-03-07 op
512 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
513 e9ce266e 2022-03-07 op ret=$?
514 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
515 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
516 e9ce266e 2022-03-07 op test_done $testroot $ret
517 e9ce266e 2022-03-07 op return 1
518 e9ce266e 2022-03-07 op fi
519 e9ce266e 2022-03-07 op
520 e9ce266e 2022-03-07 op cmp -s $testroot/stderr.expected $testroot/stderr
521 e9ce266e 2022-03-07 op ret=$?
522 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
523 e9ce266e 2022-03-07 op diff -u $testroot/stderr.expected $testroot/stderr
524 e9ce266e 2022-03-07 op test_done $testroot $ret
525 e9ce266e 2022-03-07 op return 1
526 e9ce266e 2022-03-07 op fi
527 e9ce266e 2022-03-07 op
528 e9ce266e 2022-03-07 op test_done $testroot $ret
529 e9ce266e 2022-03-07 op }
530 e9ce266e 2022-03-07 op
531 e9ce266e 2022-03-07 op test_patch_no_patch() {
532 e9ce266e 2022-03-07 op local testroot=`test_init patch_no_patch`
533 e9ce266e 2022-03-07 op
534 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
535 e9ce266e 2022-03-07 op ret=$?
536 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
537 e9ce266e 2022-03-07 op test_done $testroot $ret
538 e9ce266e 2022-03-07 op return 1
539 e9ce266e 2022-03-07 op fi
540 e9ce266e 2022-03-07 op
541 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
542 e9ce266e 2022-03-07 op hello world!
543 e9ce266e 2022-03-07 op ...
544 e9ce266e 2022-03-07 op
545 e9ce266e 2022-03-07 op some other nonsense
546 e9ce266e 2022-03-07 op ...
547 e9ce266e 2022-03-07 op
548 e9ce266e 2022-03-07 op there's no patch in here!
549 e9ce266e 2022-03-07 op EOF
550 e9ce266e 2022-03-07 op
551 e9ce266e 2022-03-07 op echo -n > $testroot/stdout.expected
552 e9ce266e 2022-03-07 op echo "got: no patch found" > $testroot/stderr.expected
553 e9ce266e 2022-03-07 op
554 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) \
555 e9ce266e 2022-03-07 op > $testroot/stdout \
556 e9ce266e 2022-03-07 op 2> $testroot/stderr
557 e9ce266e 2022-03-07 op ret=$?
558 e9ce266e 2022-03-07 op if [ $ret == 0 ]; then # should fail
559 e9ce266e 2022-03-07 op test_done $testroot 1
560 e9ce266e 2022-03-07 op return 1
561 e9ce266e 2022-03-07 op fi
562 e9ce266e 2022-03-07 op
563 e9ce266e 2022-03-07 op
564 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
565 e9ce266e 2022-03-07 op ret=$?
566 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
567 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
568 e9ce266e 2022-03-07 op test_done $testroot $ret
569 e9ce266e 2022-03-07 op return 1
570 e9ce266e 2022-03-07 op fi
571 e9ce266e 2022-03-07 op
572 e9ce266e 2022-03-07 op cmp -s $testroot/stderr.expected $testroot/stderr
573 e9ce266e 2022-03-07 op ret=$?
574 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
575 e9ce266e 2022-03-07 op diff -u $testroot/stderr.expected $testroot/stderr
576 e9ce266e 2022-03-07 op test_done $testroot $ret
577 e9ce266e 2022-03-07 op return 1
578 e9ce266e 2022-03-07 op fi
579 e9ce266e 2022-03-07 op
580 e9ce266e 2022-03-07 op test_done $testroot $ret
581 e9ce266e 2022-03-07 op }
582 e9ce266e 2022-03-07 op
583 e9ce266e 2022-03-07 op test_patch_equals_for_context() {
584 e9ce266e 2022-03-07 op local testroot=`test_init patch_prepend_line`
585 e9ce266e 2022-03-07 op
586 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
587 e9ce266e 2022-03-07 op ret=$?
588 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
589 e9ce266e 2022-03-07 op test_done $testroot $ret
590 e9ce266e 2022-03-07 op return 1
591 e9ce266e 2022-03-07 op fi
592 e9ce266e 2022-03-07 op
593 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
594 e9ce266e 2022-03-07 op --- alpha
595 e9ce266e 2022-03-07 op +++ alpha
596 e9ce266e 2022-03-07 op @@ -1 +1,2 @@
597 e9ce266e 2022-03-07 op +hatsuseno
598 e9ce266e 2022-03-07 op =alpha
599 e9ce266e 2022-03-07 op EOF
600 e9ce266e 2022-03-07 op
601 e9ce266e 2022-03-07 op echo "M alpha" > $testroot/stdout.expected
602 e9ce266e 2022-03-07 op
603 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
604 e9ce266e 2022-03-07 op ret=$?
605 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
606 e9ce266e 2022-03-07 op test_done $testroot $ret
607 e9ce266e 2022-03-07 op return 1
608 e9ce266e 2022-03-07 op fi
609 e9ce266e 2022-03-07 op
610 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
611 e9ce266e 2022-03-07 op ret=$?
612 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
613 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
614 e9ce266e 2022-03-07 op test_done $testroot $ret
615 e9ce266e 2022-03-07 op return 1
616 e9ce266e 2022-03-07 op fi
617 e9ce266e 2022-03-07 op
618 e9ce266e 2022-03-07 op echo hatsuseno > $testroot/wt/alpha.expected
619 e9ce266e 2022-03-07 op echo alpha >> $testroot/wt/alpha.expected
620 e9ce266e 2022-03-07 op cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
621 e9ce266e 2022-03-07 op ret=$?
622 e9ce266e 2022-03-07 op if [ $ret != 0 ]; then
623 e9ce266e 2022-03-07 op diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
624 e9ce266e 2022-03-07 op fi
625 e9ce266e 2022-03-07 op test_done $testroot $ret
626 e9ce266e 2022-03-07 op }
627 e9ce266e 2022-03-07 op
628 e9ce266e 2022-03-07 op test_parseargs "$@"
629 e9ce266e 2022-03-07 op run_test test_patch_simple_add_file
630 e9ce266e 2022-03-07 op run_test test_patch_simple_rm_file
631 e9ce266e 2022-03-07 op run_test test_patch_simple_edit_file
632 e9ce266e 2022-03-07 op run_test test_patch_prepend_line
633 e9ce266e 2022-03-07 op run_test test_patch_replace_line
634 e9ce266e 2022-03-07 op run_test test_patch_multiple_hunks
635 e9ce266e 2022-03-07 op run_test test_patch_multiple_files
636 e9ce266e 2022-03-07 op run_test test_patch_dont_apply
637 e9ce266e 2022-03-07 op run_test test_patch_malformed
638 e9ce266e 2022-03-07 op run_test test_patch_no_patch
639 e9ce266e 2022-03-07 op run_test test_patch_equals_for_context