Changes for kernel and Busybox
[tomato.git] / release / src / router / busybox / testsuite / patch.tests
blob2759d2ad4b788cad47a5afb78c28ae2ba257222a
1 #!/bin/sh
2 # Copyright 2008 by Denys Vlasenko
3 # Licensed under GPLv2, see file LICENSE in this source tree.
5 . ./testing.sh
7 # testing "test name" "command(s)" "expected result" "file input" "stdin"
9 testing "patch with old_file == new_file" \
10 'patch 2>&1; echo $?; cat input' \
12 patching file input
14 qwe
15 asd
16 zxc
17 " \
19 qwe
20 zxc
21 " \
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 " \
31 testing "patch with nonexistent old_file" \
32 'patch 2>&1; echo $?; cat input' \
34 patching file input
36 qwe
37 asd
38 zxc
39 " \
41 qwe
42 zxc
43 " \
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 " \
53 testing "patch -R with nonexistent old_file" \
54 'patch -R 2>&1; echo $?; cat input' \
56 patching file input
58 qwe
59 zxc
60 " \
62 qwe
63 asd
64 zxc
65 " \
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 " \
75 testing "patch detects already applied hunk" \
76 'patch 2>&1; echo $?; cat input' \
78 Possibly reversed hunk 1 at 4
79 Hunk 1 FAILED 1/1.
80 abc
81 +def
82 123
83 patching file input
85 abc
86 def
87 123
88 " \
90 abc
91 def
92 123
93 " \
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
103 testing "patch detects already applied hunk at the EOF" \
104 'patch 2>&1; echo $?; cat input' \
106 Possibly reversed hunk 1 at 4
107 Hunk 1 FAILED 1/1.
110 +456
111 patching file input
123 --- input.old Jan 01 01:01:01 2000
124 +++ input Jan 01 01:01:01 2000
125 @@ -1,2 +1,3 @@
128 +456
131 # testing "test name" "command(s)" "expected result" "file input" "stdin"
132 testing "patch -N ignores already applied hunk" \
133 'patch -N 2>&1; echo $?; cat input' \
135 patching file input
147 --- input
148 +++ input
149 @@ -1,2 +1,3 @@
151 +def
155 # testing "test name" "command(s)" "expected result" "file input" "stdin"
156 testing "patch FILE PATCH" \
157 'cat >a.patch; patch input a.patch 2>&1; echo $?; cat input; rm a.patch' \
159 patching file input
170 --- foo.old
171 +++ foo
172 @@ -1,2 +1,3 @@
174 +def
178 # testing "test name" "command(s)" "expected result" "file input" "stdin"
179 testing "patch at the beginning" \
180 'patch 2>&1; cat input' \
182 patching file input
183 111changed
203 --- input
204 +++ input
205 @@ -1,6 +1,4 @@
206 -111
207 -222
208 -333
209 +111changed
215 # testing "test name" "command(s)" "expected result" "file input" "stdin"
216 testing "patch creates new file" \
217 'patch 2>&1; echo $?; cat testfile; rm testfile' \
219 creating testfile
221 qwerty
222 " "" "\
223 --- /dev/null
224 +++ testfile
225 @@ -0,0 +1 @@
226 +qwerty
229 # testing "test name" "command(s)" "expected result" "file input" "stdin"
230 testing "patch understands ...dir///dir..." \
231 'patch -p1 2>&1; echo $?' \
233 patching file dir2///file
234 patch: can't open 'dir2///file': No such file or directory
236 " "" "\
237 --- bogus_dir///dir2///file
238 +++ bogus_dir///dir2///file
239 @@ -1,2 +1,3 @@
241 +asd
245 rm input.orig 2>/dev/null
247 exit $FAILCOUNT