Blame


1 069bbb86 2022-03-07 thomas #!/bin/sh
2 069bbb86 2022-03-07 thomas #
3 069bbb86 2022-03-07 thomas # Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 069bbb86 2022-03-07 thomas #
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.
8 069bbb86 2022-03-07 thomas #
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.
16 069bbb86 2022-03-07 thomas
17 069bbb86 2022-03-07 thomas . ./common.sh
18 069bbb86 2022-03-07 thomas
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`
21 069bbb86 2022-03-07 thomas
22 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
23 069bbb86 2022-03-07 thomas ret=$?
24 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
25 069bbb86 2022-03-07 thomas test_done $testroot $ret
26 069bbb86 2022-03-07 thomas return 1
27 069bbb86 2022-03-07 thomas fi
28 069bbb86 2022-03-07 thomas
29 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
30 069bbb86 2022-03-07 thomas --- /dev/null
31 069bbb86 2022-03-07 thomas +++ eta
32 069bbb86 2022-03-07 thomas @@ -0,0 +1 @@
33 069bbb86 2022-03-07 thomas +eta
34 069bbb86 2022-03-07 thomas EOF
35 069bbb86 2022-03-07 thomas
36 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
37 069bbb86 2022-03-07 thomas ret=$?
38 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
39 069bbb86 2022-03-07 thomas test_done $testroot $ret
40 069bbb86 2022-03-07 thomas return 1
41 069bbb86 2022-03-07 thomas fi
42 069bbb86 2022-03-07 thomas
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
45 069bbb86 2022-03-07 thomas ret=$?
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
49 069bbb86 2022-03-07 thomas return 1
50 069bbb86 2022-03-07 thomas fi
51 069bbb86 2022-03-07 thomas
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
54 069bbb86 2022-03-07 thomas ret=$?
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
57 069bbb86 2022-03-07 thomas fi
58 069bbb86 2022-03-07 thomas test_done $testroot $ret
59 069bbb86 2022-03-07 thomas }
60 069bbb86 2022-03-07 thomas
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`
63 069bbb86 2022-03-07 thomas
64 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
65 069bbb86 2022-03-07 thomas ret=$?
66 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
67 069bbb86 2022-03-07 thomas test_done $testroot $ret
68 069bbb86 2022-03-07 thomas return 1
69 069bbb86 2022-03-07 thomas fi
70 069bbb86 2022-03-07 thomas
71 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
72 069bbb86 2022-03-07 thomas --- alpha
73 069bbb86 2022-03-07 thomas +++ /dev/null
74 069bbb86 2022-03-07 thomas @@ -1 +0,0 @@
75 069bbb86 2022-03-07 thomas -alpha
76 069bbb86 2022-03-07 thomas EOF
77 069bbb86 2022-03-07 thomas
78 069bbb86 2022-03-07 thomas echo "D alpha" > $testroot/stdout.expected
79 069bbb86 2022-03-07 thomas
80 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
81 069bbb86 2022-03-07 thomas ret=$?
82 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
83 069bbb86 2022-03-07 thomas test_done $testroot $ret
84 069bbb86 2022-03-07 thomas return 1
85 069bbb86 2022-03-07 thomas fi
86 069bbb86 2022-03-07 thomas
87 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
88 069bbb86 2022-03-07 thomas ret=$?
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
92 069bbb86 2022-03-07 thomas return 1
93 069bbb86 2022-03-07 thomas fi
94 069bbb86 2022-03-07 thomas
95 069bbb86 2022-03-07 thomas if [ -f $testroot/wt/alpha ]; then
96 069bbb86 2022-03-07 thomas ret=1
97 069bbb86 2022-03-07 thomas echo "alpha still exists!"
98 069bbb86 2022-03-07 thomas fi
99 069bbb86 2022-03-07 thomas test_done $testroot $ret
100 069bbb86 2022-03-07 thomas }
101 069bbb86 2022-03-07 thomas
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`
104 069bbb86 2022-03-07 thomas
105 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
106 069bbb86 2022-03-07 thomas ret=$?
107 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
108 069bbb86 2022-03-07 thomas test_done $testroot $ret
109 069bbb86 2022-03-07 thomas return 1
110 069bbb86 2022-03-07 thomas fi
111 069bbb86 2022-03-07 thomas
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 @@
116 069bbb86 2022-03-07 thomas -alpha
117 069bbb86 2022-03-07 thomas +alpha is my favourite character
118 069bbb86 2022-03-07 thomas EOF
119 069bbb86 2022-03-07 thomas
120 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
121 069bbb86 2022-03-07 thomas
122 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
123 069bbb86 2022-03-07 thomas ret=$?
124 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
125 069bbb86 2022-03-07 thomas test_done $testroot $ret
126 069bbb86 2022-03-07 thomas return 1
127 069bbb86 2022-03-07 thomas fi
128 069bbb86 2022-03-07 thomas
129 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
130 069bbb86 2022-03-07 thomas ret=$?
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
134 069bbb86 2022-03-07 thomas return 1
135 069bbb86 2022-03-07 thomas fi
136 069bbb86 2022-03-07 thomas
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
139 069bbb86 2022-03-07 thomas ret=$?
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
142 069bbb86 2022-03-07 thomas fi
143 069bbb86 2022-03-07 thomas test_done $testroot $ret
144 069bbb86 2022-03-07 thomas }
145 069bbb86 2022-03-07 thomas
146 069bbb86 2022-03-07 thomas test_patch_prepend_line() {
147 069bbb86 2022-03-07 thomas local testroot=`test_init patch_prepend_line`
148 069bbb86 2022-03-07 thomas
149 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
150 069bbb86 2022-03-07 thomas ret=$?
151 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
152 069bbb86 2022-03-07 thomas test_done $testroot $ret
153 069bbb86 2022-03-07 thomas return 1
154 069bbb86 2022-03-07 thomas fi
155 069bbb86 2022-03-07 thomas
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
161 069bbb86 2022-03-07 thomas alpha
162 069bbb86 2022-03-07 thomas EOF
163 069bbb86 2022-03-07 thomas
164 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
165 069bbb86 2022-03-07 thomas
166 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
167 069bbb86 2022-03-07 thomas ret=$?
168 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
169 069bbb86 2022-03-07 thomas test_done $testroot $ret
170 069bbb86 2022-03-07 thomas return 1
171 069bbb86 2022-03-07 thomas fi
172 069bbb86 2022-03-07 thomas
173 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
174 069bbb86 2022-03-07 thomas ret=$?
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
178 069bbb86 2022-03-07 thomas return 1
179 069bbb86 2022-03-07 thomas fi
180 069bbb86 2022-03-07 thomas
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
184 069bbb86 2022-03-07 thomas ret=$?
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
187 069bbb86 2022-03-07 thomas fi
188 069bbb86 2022-03-07 thomas test_done $testroot $ret
189 069bbb86 2022-03-07 thomas }
190 069bbb86 2022-03-07 thomas
191 069bbb86 2022-03-07 thomas test_patch_replace_line() {
192 069bbb86 2022-03-07 thomas local testroot=`test_init patch_replace_line`
193 069bbb86 2022-03-07 thomas
194 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
195 069bbb86 2022-03-07 thomas ret=$?
196 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
197 069bbb86 2022-03-07 thomas test_done $testroot $ret
198 069bbb86 2022-03-07 thomas return 1
199 069bbb86 2022-03-07 thomas fi
200 069bbb86 2022-03-07 thomas
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
204 069bbb86 2022-03-07 thomas ret=$?
205 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
206 069bbb86 2022-03-07 thomas test_done $testroot $ret
207 069bbb86 2022-03-07 thomas return 1
208 069bbb86 2022-03-07 thomas fi
209 069bbb86 2022-03-07 thomas
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 @@
214 069bbb86 2022-03-07 thomas 3
215 069bbb86 2022-03-07 thomas 4
216 069bbb86 2022-03-07 thomas 5
217 069bbb86 2022-03-07 thomas -6
218 069bbb86 2022-03-07 thomas +foo
219 069bbb86 2022-03-07 thomas 7
220 069bbb86 2022-03-07 thomas 8
221 069bbb86 2022-03-07 thomas 9
222 069bbb86 2022-03-07 thomas EOF
223 069bbb86 2022-03-07 thomas
224 069bbb86 2022-03-07 thomas echo "M numbers" > $testroot/stdout.expected
225 069bbb86 2022-03-07 thomas
226 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
227 069bbb86 2022-03-07 thomas ret=$?
228 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
229 069bbb86 2022-03-07 thomas test_done $testroot $ret
230 069bbb86 2022-03-07 thomas return 1
231 069bbb86 2022-03-07 thomas fi
232 069bbb86 2022-03-07 thomas
233 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
234 069bbb86 2022-03-07 thomas ret=$?
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
238 069bbb86 2022-03-07 thomas return 1
239 069bbb86 2022-03-07 thomas fi
240 069bbb86 2022-03-07 thomas
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
243 069bbb86 2022-03-07 thomas ret=$?
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
246 069bbb86 2022-03-07 thomas fi
247 069bbb86 2022-03-07 thomas test_done $testroot $ret
248 069bbb86 2022-03-07 thomas }
249 069bbb86 2022-03-07 thomas
250 069bbb86 2022-03-07 thomas test_patch_multiple_hunks() {
251 02e4f0d8 2022-03-08 thomas local testroot=`test_init patch_replace_multiple_hunks`
252 069bbb86 2022-03-07 thomas
253 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
254 069bbb86 2022-03-07 thomas ret=$?
255 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
256 069bbb86 2022-03-07 thomas test_done $testroot $ret
257 069bbb86 2022-03-07 thomas return 1
258 069bbb86 2022-03-07 thomas fi
259 069bbb86 2022-03-07 thomas
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
263 069bbb86 2022-03-07 thomas ret=$?
264 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
265 069bbb86 2022-03-07 thomas test_done $testroot $ret
266 069bbb86 2022-03-07 thomas return 1
267 069bbb86 2022-03-07 thomas fi
268 069bbb86 2022-03-07 thomas
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 @@
273 069bbb86 2022-03-07 thomas 3
274 069bbb86 2022-03-07 thomas 4
275 069bbb86 2022-03-07 thomas 5
276 069bbb86 2022-03-07 thomas -6
277 069bbb86 2022-03-07 thomas +foo
278 069bbb86 2022-03-07 thomas 7
279 069bbb86 2022-03-07 thomas 8
280 069bbb86 2022-03-07 thomas 9
281 069bbb86 2022-03-07 thomas @@ -57,7 +57,7 @@
282 069bbb86 2022-03-07 thomas 57
283 069bbb86 2022-03-07 thomas 58
284 069bbb86 2022-03-07 thomas 59
285 069bbb86 2022-03-07 thomas -60
286 069bbb86 2022-03-07 thomas +foo foo
287 069bbb86 2022-03-07 thomas 61
288 069bbb86 2022-03-07 thomas 62
289 069bbb86 2022-03-07 thomas 63
290 069bbb86 2022-03-07 thomas @@ -98,3 +98,6 @@
291 069bbb86 2022-03-07 thomas 98
292 069bbb86 2022-03-07 thomas 99
293 069bbb86 2022-03-07 thomas 100
294 069bbb86 2022-03-07 thomas +101
295 069bbb86 2022-03-07 thomas +102
296 069bbb86 2022-03-07 thomas +...
297 069bbb86 2022-03-07 thomas EOF
298 069bbb86 2022-03-07 thomas
299 069bbb86 2022-03-07 thomas echo "M numbers" > $testroot/stdout.expected
300 069bbb86 2022-03-07 thomas
301 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
302 069bbb86 2022-03-07 thomas ret=$?
303 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
304 069bbb86 2022-03-07 thomas test_done $testroot $ret
305 069bbb86 2022-03-07 thomas return 1
306 069bbb86 2022-03-07 thomas fi
307 069bbb86 2022-03-07 thomas
308 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
309 069bbb86 2022-03-07 thomas ret=$?
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
313 069bbb86 2022-03-07 thomas return 1
314 069bbb86 2022-03-07 thomas fi
315 069bbb86 2022-03-07 thomas
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
321 069bbb86 2022-03-07 thomas
322 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
323 069bbb86 2022-03-07 thomas ret=$?
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
326 069bbb86 2022-03-07 thomas fi
327 069bbb86 2022-03-07 thomas test_done $testroot $ret
328 069bbb86 2022-03-07 thomas }
329 069bbb86 2022-03-07 thomas
330 069bbb86 2022-03-07 thomas test_patch_multiple_files() {
331 069bbb86 2022-03-07 thomas local testroot=`test_init patch_multiple_files`
332 069bbb86 2022-03-07 thomas
333 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
334 069bbb86 2022-03-07 thomas ret=$?
335 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
336 069bbb86 2022-03-07 thomas test_done $testroot $ret
337 069bbb86 2022-03-07 thomas return 1
338 069bbb86 2022-03-07 thomas fi
339 069bbb86 2022-03-07 thomas
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 @@
344 069bbb86 2022-03-07 thomas +new
345 069bbb86 2022-03-07 thomas alpha
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 @@
350 069bbb86 2022-03-07 thomas beta
351 069bbb86 2022-03-07 thomas +was
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 @@
356 069bbb86 2022-03-07 thomas -delta
357 069bbb86 2022-03-07 thomas +delta new
358 069bbb86 2022-03-07 thomas EOF
359 069bbb86 2022-03-07 thomas
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
363 069bbb86 2022-03-07 thomas
364 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
365 069bbb86 2022-03-07 thomas ret=$?
366 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
367 02e4f0d8 2022-03-08 thomas test_done $testroot $ret
368 069bbb86 2022-03-07 thomas return 1
369 069bbb86 2022-03-07 thomas fi
370 069bbb86 2022-03-07 thomas
371 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
372 069bbb86 2022-03-07 thomas ret=$?
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
376 069bbb86 2022-03-07 thomas return 1
377 069bbb86 2022-03-07 thomas fi
378 069bbb86 2022-03-07 thomas
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
382 069bbb86 2022-03-07 thomas
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
385 069bbb86 2022-03-07 thomas ret=$?
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
389 069bbb86 2022-03-07 thomas return 1
390 069bbb86 2022-03-07 thomas fi
391 069bbb86 2022-03-07 thomas done
392 069bbb86 2022-03-07 thomas
393 069bbb86 2022-03-07 thomas test_done $testroot 0
394 069bbb86 2022-03-07 thomas }
395 069bbb86 2022-03-07 thomas
396 069bbb86 2022-03-07 thomas test_patch_dont_apply() {
397 069bbb86 2022-03-07 thomas local testroot=`test_init patch_dont_apply`
398 069bbb86 2022-03-07 thomas
399 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
400 069bbb86 2022-03-07 thomas ret=$?
401 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
402 069bbb86 2022-03-07 thomas test_done $testroot $ret
403 069bbb86 2022-03-07 thomas return 1
404 069bbb86 2022-03-07 thomas fi
405 069bbb86 2022-03-07 thomas
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
412 069bbb86 2022-03-07 thomas EOF
413 069bbb86 2022-03-07 thomas
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
416 069bbb86 2022-03-07 thomas
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
420 069bbb86 2022-03-07 thomas ret=$?
421 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then # should fail
422 069bbb86 2022-03-07 thomas test_done $testroot 1
423 069bbb86 2022-03-07 thomas return 1
424 069bbb86 2022-03-07 thomas fi
425 069bbb86 2022-03-07 thomas
426 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
427 069bbb86 2022-03-07 thomas ret=$?
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
431 069bbb86 2022-03-07 thomas return 1
432 069bbb86 2022-03-07 thomas fi
433 069bbb86 2022-03-07 thomas
434 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
435 069bbb86 2022-03-07 thomas ret=$?
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
439 069bbb86 2022-03-07 thomas return 1
440 069bbb86 2022-03-07 thomas fi
441 069bbb86 2022-03-07 thomas
442 069bbb86 2022-03-07 thomas test_done $testroot $ret
443 069bbb86 2022-03-07 thomas }
444 069bbb86 2022-03-07 thomas
445 069bbb86 2022-03-07 thomas test_patch_malformed() {
446 069bbb86 2022-03-07 thomas local testroot=`test_init patch_malformed`
447 069bbb86 2022-03-07 thomas
448 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
449 069bbb86 2022-03-07 thomas ret=$?
450 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
451 069bbb86 2022-03-07 thomas test_done $testroot $ret
452 069bbb86 2022-03-07 thomas return 1
453 069bbb86 2022-03-07 thomas fi
454 069bbb86 2022-03-07 thomas
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
461 069bbb86 2022-03-07 thomas alpha
462 069bbb86 2022-03-07 thomas EOF
463 069bbb86 2022-03-07 thomas
464 069bbb86 2022-03-07 thomas echo -n > $testroot/stdout.expected
465 069bbb86 2022-03-07 thomas echo "got: malformed patch" > $testroot/stderr.expected
466 069bbb86 2022-03-07 thomas
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
470 069bbb86 2022-03-07 thomas ret=$?
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
474 069bbb86 2022-03-07 thomas return 1
475 069bbb86 2022-03-07 thomas fi
476 069bbb86 2022-03-07 thomas
477 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
478 069bbb86 2022-03-07 thomas ret=$?
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
482 069bbb86 2022-03-07 thomas return 1
483 069bbb86 2022-03-07 thomas fi
484 069bbb86 2022-03-07 thomas
485 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
486 069bbb86 2022-03-07 thomas ret=$?
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
490 069bbb86 2022-03-07 thomas return 1
491 069bbb86 2022-03-07 thomas fi
492 069bbb86 2022-03-07 thomas
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
499 069bbb86 2022-03-07 thomas alpha
500 069bbb86 2022-03-07 thomas EOF
501 069bbb86 2022-03-07 thomas
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
505 069bbb86 2022-03-07 thomas ret=$?
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
509 069bbb86 2022-03-07 thomas return 1
510 069bbb86 2022-03-07 thomas fi
511 069bbb86 2022-03-07 thomas
512 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
513 069bbb86 2022-03-07 thomas ret=$?
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
517 069bbb86 2022-03-07 thomas return 1
518 069bbb86 2022-03-07 thomas fi
519 069bbb86 2022-03-07 thomas
520 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
521 069bbb86 2022-03-07 thomas ret=$?
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
525 069bbb86 2022-03-07 thomas return 1
526 069bbb86 2022-03-07 thomas fi
527 069bbb86 2022-03-07 thomas
528 069bbb86 2022-03-07 thomas test_done $testroot $ret
529 069bbb86 2022-03-07 thomas }
530 069bbb86 2022-03-07 thomas
531 069bbb86 2022-03-07 thomas test_patch_no_patch() {
532 069bbb86 2022-03-07 thomas local testroot=`test_init patch_no_patch`
533 069bbb86 2022-03-07 thomas
534 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
535 069bbb86 2022-03-07 thomas ret=$?
536 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
537 069bbb86 2022-03-07 thomas test_done $testroot $ret
538 069bbb86 2022-03-07 thomas return 1
539 069bbb86 2022-03-07 thomas fi
540 069bbb86 2022-03-07 thomas
541 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
542 069bbb86 2022-03-07 thomas hello world!
543 069bbb86 2022-03-07 thomas ...
544 069bbb86 2022-03-07 thomas
545 069bbb86 2022-03-07 thomas some other nonsense
546 069bbb86 2022-03-07 thomas ...
547 069bbb86 2022-03-07 thomas
548 069bbb86 2022-03-07 thomas there's no patch in here!
549 069bbb86 2022-03-07 thomas EOF
550 069bbb86 2022-03-07 thomas
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
553 069bbb86 2022-03-07 thomas
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
557 069bbb86 2022-03-07 thomas ret=$?
558 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then # should fail
559 069bbb86 2022-03-07 thomas test_done $testroot 1
560 069bbb86 2022-03-07 thomas return 1
561 069bbb86 2022-03-07 thomas fi
562 069bbb86 2022-03-07 thomas
563 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
564 069bbb86 2022-03-07 thomas ret=$?
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
568 069bbb86 2022-03-07 thomas return 1
569 069bbb86 2022-03-07 thomas fi
570 069bbb86 2022-03-07 thomas
571 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
572 069bbb86 2022-03-07 thomas ret=$?
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
576 069bbb86 2022-03-07 thomas return 1
577 069bbb86 2022-03-07 thomas fi
578 069bbb86 2022-03-07 thomas
579 069bbb86 2022-03-07 thomas test_done $testroot $ret
580 069bbb86 2022-03-07 thomas }
581 069bbb86 2022-03-07 thomas
582 069bbb86 2022-03-07 thomas test_patch_equals_for_context() {
583 069bbb86 2022-03-07 thomas local testroot=`test_init patch_prepend_line`
584 069bbb86 2022-03-07 thomas
585 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
586 069bbb86 2022-03-07 thomas ret=$?
587 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
588 069bbb86 2022-03-07 thomas test_done $testroot $ret
589 069bbb86 2022-03-07 thomas return 1
590 069bbb86 2022-03-07 thomas fi
591 069bbb86 2022-03-07 thomas
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
597 069bbb86 2022-03-07 thomas =alpha
598 069bbb86 2022-03-07 thomas EOF
599 069bbb86 2022-03-07 thomas
600 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
601 069bbb86 2022-03-07 thomas
602 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
603 069bbb86 2022-03-07 thomas ret=$?
604 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
605 069bbb86 2022-03-07 thomas test_done $testroot $ret
606 069bbb86 2022-03-07 thomas return 1
607 069bbb86 2022-03-07 thomas fi
608 069bbb86 2022-03-07 thomas
609 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
610 069bbb86 2022-03-07 thomas ret=$?
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
614 069bbb86 2022-03-07 thomas return 1
615 069bbb86 2022-03-07 thomas fi
616 069bbb86 2022-03-07 thomas
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
620 069bbb86 2022-03-07 thomas ret=$?
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
623 069bbb86 2022-03-07 thomas fi
624 069bbb86 2022-03-07 thomas test_done $testroot $ret
625 069bbb86 2022-03-07 thomas }
626 069bbb86 2022-03-07 thomas
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