blob: 1d48e90be4e74546c55f90b0a79a41962cc94391 [file] [log] [blame]
Denis Vlasenkocc2965f2008-03-25 14:15:39 +00001#!/bin/sh
2# Copyright 2008 by Denys Vlasenko
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003# Licensed under GPLv2, see file LICENSE in this source tree.
Denis Vlasenkocc2965f2008-03-25 14:15:39 +00004
Mike Frysingercaa79402009-11-04 18:41:22 -05005. ./testing.sh
Denis Vlasenkocc2965f2008-03-25 14:15:39 +00006
Denys Vlasenkoa4160e12010-08-16 01:33:57 +02007# testing "test name" "command(s)" "expected result" "file input" "stdin"
Denis Vlasenkocc2965f2008-03-25 14:15:39 +00008
9testing "patch with old_file == new_file" \
Rob Landley1bbc0cd2010-08-13 15:50:26 +020010 'patch 2>&1; echo $?; cat input' \
Denis Vlasenkocc2965f2008-03-25 14:15:39 +000011"\
12patching file input
130
14qwe
15asd
16zxc
17" \
Denys Vlasenko17c838b2009-10-24 17:11:55 +020018"\
19qwe
20zxc
21" \
Denis Vlasenkocc2965f2008-03-25 14:15:39 +000022"\
23--- input Jan 01 01:01:01 2000
24+++ input Jan 01 01:01:01 2000
25@@ -1,2 +1,3 @@
26 qwe
27+asd
28 zxc
29" \
30
31testing "patch with nonexistent old_file" \
Rob Landley1bbc0cd2010-08-13 15:50:26 +020032 'patch 2>&1; echo $?; cat input' \
Denis Vlasenkocc2965f2008-03-25 14:15:39 +000033"\
34patching file input
350
36qwe
37asd
38zxc
39" \
Denys Vlasenko17c838b2009-10-24 17:11:55 +020040"\
41qwe
42zxc
43" \
Denis Vlasenkocc2965f2008-03-25 14:15:39 +000044"\
45--- input.doesnt_exist Jan 01 01:01:01 2000
46+++ input Jan 01 01:01:01 2000
47@@ -1,2 +1,3 @@
48 qwe
49+asd
50 zxc
51" \
52
Denis Vlasenko08ec67b2008-03-26 13:32:30 +000053testing "patch -R with nonexistent old_file" \
Rob Landley1bbc0cd2010-08-13 15:50:26 +020054 'patch -R 2>&1; echo $?; cat input' \
Denis Vlasenko08ec67b2008-03-26 13:32:30 +000055"\
56patching file input
570
58qwe
59zxc
60" \
Denys Vlasenko17c838b2009-10-24 17:11:55 +020061"\
62qwe
63asd
64zxc
65" \
Denis Vlasenko08ec67b2008-03-26 13:32:30 +000066"\
67--- input.doesnt_exist Jan 01 01:01:01 2000
68+++ input Jan 01 01:01:01 2000
69@@ -1,2 +1,3 @@
70 qwe
71+asd
72 zxc
73" \
74
Denys Vlasenko17c838b2009-10-24 17:11:55 +020075testing "patch detects already applied hunk" \
76 'patch 2>&1; echo $?; cat input' \
77"\
Denys Vlasenko5fa5c4b2020-06-23 21:28:19 +020078patching file input
Denys Vlasenkob82ae982010-11-21 05:53:34 +010079Possibly reversed hunk 1 at 4
Rob Landley1bbc0cd2010-08-13 15:50:26 +020080Hunk 1 FAILED 1/1.
81 abc
82+def
83 123
Denys Vlasenko17c838b2009-10-24 17:11:55 +0200841
85abc
86def
87123
88" \
89"\
90abc
91def
92123
93" \
94"\
95--- input.old Jan 01 01:01:01 2000
96+++ input Jan 01 01:01:01 2000
97@@ -1,2 +1,3 @@
98 abc
99+def
100 123
101" \
102
Denys Vlasenko3f75d7b2010-08-16 02:56:32 +0200103testing "patch detects already applied hunk at the EOF" \
Denys Vlasenko6f2ebae2009-10-25 00:35:04 +0200104 'patch 2>&1; echo $?; cat input' \
105"\
Denys Vlasenko5fa5c4b2020-06-23 21:28:19 +0200106patching file input
Denys Vlasenkob82ae982010-11-21 05:53:34 +0100107Possibly reversed hunk 1 at 4
Denys Vlasenko3f75d7b2010-08-16 02:56:32 +0200108Hunk 1 FAILED 1/1.
109 abc
110 123
111+456
Denys Vlasenko6f2ebae2009-10-25 00:35:04 +02001121
113abc
114123
115456
116" \
117"\
118abc
119123
120456
121" \
122"\
123--- input.old Jan 01 01:01:01 2000
124+++ input Jan 01 01:01:01 2000
125@@ -1,2 +1,3 @@
126 abc
127 123
128+456
129" \
130
Denys Vlasenkoa4160e12010-08-16 01:33:57 +0200131# testing "test name" "command(s)" "expected result" "file input" "stdin"
Denys Vlasenkoa4160e12010-08-16 01:33:57 +0200132testing "patch -N ignores already applied hunk" \
133 'patch -N 2>&1; echo $?; cat input' \
134"\
135patching file input
1360
137abc
138def
139123
140" \
141"\
142abc
143def
144123
145" \
146"\
147--- input
148+++ input
149@@ -1,2 +1,3 @@
150 abc
151+def
152 123
153" \
154
Denys Vlasenkoe7b0a9e2010-08-22 05:39:15 +0200155# testing "test name" "command(s)" "expected result" "file input" "stdin"
156testing "patch FILE PATCH" \
157 'cat >a.patch; patch input a.patch 2>&1; echo $?; cat input; rm a.patch' \
158"\
159patching file input
1600
161abc
162def
163123
164" \
165"\
166abc
167123
168" \
169"\
170--- foo.old
171+++ foo
172@@ -1,2 +1,3 @@
173 abc
174+def
175 123
176" \
177
Denys Vlasenkofe9403a2010-11-28 01:41:40 +0100178# testing "test name" "command(s)" "expected result" "file input" "stdin"
179testing "patch at the beginning" \
180 'patch 2>&1; cat input' \
181"\
182patching file input
183111changed
184444
185555
186666
187777
188888
189999
190" \
191"\
192111
193222
194333
195444
196555
197666
198777
199888
200999
201" \
202"\
203--- input
204+++ input
205@@ -1,6 +1,4 @@
206-111
207-222
208-333
209+111changed
210 444
211 555
212 666
213" \
214
Denys Vlasenko9176f6c2011-08-16 22:57:12 +0200215# testing "test name" "command(s)" "expected result" "file input" "stdin"
216testing "patch creates new file" \
217 'patch 2>&1; echo $?; cat testfile; rm testfile' \
218"\
219creating testfile
2200
221qwerty
222" "" "\
223--- /dev/null
224+++ testfile
225@@ -0,0 +1 @@
226+qwerty
227"
228
Rob Landley39ec6a22011-10-10 19:59:38 +0200229# testing "test name" "command(s)" "expected result" "file input" "stdin"
230testing "patch understands ...dir///dir..." \
231 'patch -p1 2>&1; echo $?' \
232"\
233patching file dir2///file
234patch: can't open 'dir2///file': No such file or directory
2351
236" "" "\
237--- bogus_dir///dir2///file
238+++ bogus_dir///dir2///file
239@@ -1,2 +1,3 @@
240 qwe
241+asd
242 zxc
243"
244
Aaro Koskinencb810c42016-11-22 00:19:51 +0200245testing "patch internal buffering bug?" \
246 'patch -p1 2>&1; echo $?; cat input' \
247"\
248patching file input
2490
250foo
251
252
253
254
255
256
2571
2582
2593
260
261bar
262" \
263"\
264foo
265
266
267
268
269
270
271
272bar
273" \
274"\
275--- a/input.orig
276+++ b/input
277@@ -5,5 +5,8 @@ foo
278
279
280
281+1
282+2
283+3
284
285 bar
286--
2872.9.2
288" \
289
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200290rm input.orig 2>/dev/null
291
Denis Vlasenkocc2965f2008-03-25 14:15:39 +0000292exit $FAILCOUNT