Denis Vlasenko | cc2965f | 2008-03-25 14:15:39 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright 2008 by Denys Vlasenko |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 3 | # Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | cc2965f | 2008-03-25 14:15:39 +0000 | [diff] [blame] | 4 | |
Mike Frysinger | caa7940 | 2009-11-04 18:41:22 -0500 | [diff] [blame] | 5 | . ./testing.sh |
Denis Vlasenko | cc2965f | 2008-03-25 14:15:39 +0000 | [diff] [blame] | 6 | |
Denys Vlasenko | a4160e1 | 2010-08-16 01:33:57 +0200 | [diff] [blame] | 7 | # testing "test name" "command(s)" "expected result" "file input" "stdin" |
Denis Vlasenko | cc2965f | 2008-03-25 14:15:39 +0000 | [diff] [blame] | 8 | |
| 9 | testing "patch with old_file == new_file" \ |
Rob Landley | 1bbc0cd | 2010-08-13 15:50:26 +0200 | [diff] [blame] | 10 | 'patch 2>&1; echo $?; cat input' \ |
Denis Vlasenko | cc2965f | 2008-03-25 14:15:39 +0000 | [diff] [blame] | 11 | "\ |
| 12 | patching file input |
| 13 | 0 |
| 14 | qwe |
| 15 | asd |
| 16 | zxc |
| 17 | " \ |
Denys Vlasenko | 17c838b | 2009-10-24 17:11:55 +0200 | [diff] [blame] | 18 | "\ |
| 19 | qwe |
| 20 | zxc |
| 21 | " \ |
Denis Vlasenko | cc2965f | 2008-03-25 14:15:39 +0000 | [diff] [blame] | 22 | "\ |
| 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 | |
| 31 | testing "patch with nonexistent old_file" \ |
Rob Landley | 1bbc0cd | 2010-08-13 15:50:26 +0200 | [diff] [blame] | 32 | 'patch 2>&1; echo $?; cat input' \ |
Denis Vlasenko | cc2965f | 2008-03-25 14:15:39 +0000 | [diff] [blame] | 33 | "\ |
| 34 | patching file input |
| 35 | 0 |
| 36 | qwe |
| 37 | asd |
| 38 | zxc |
| 39 | " \ |
Denys Vlasenko | 17c838b | 2009-10-24 17:11:55 +0200 | [diff] [blame] | 40 | "\ |
| 41 | qwe |
| 42 | zxc |
| 43 | " \ |
Denis Vlasenko | cc2965f | 2008-03-25 14:15:39 +0000 | [diff] [blame] | 44 | "\ |
| 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 Vlasenko | 08ec67b | 2008-03-26 13:32:30 +0000 | [diff] [blame] | 53 | testing "patch -R with nonexistent old_file" \ |
Rob Landley | 1bbc0cd | 2010-08-13 15:50:26 +0200 | [diff] [blame] | 54 | 'patch -R 2>&1; echo $?; cat input' \ |
Denis Vlasenko | 08ec67b | 2008-03-26 13:32:30 +0000 | [diff] [blame] | 55 | "\ |
| 56 | patching file input |
| 57 | 0 |
| 58 | qwe |
| 59 | zxc |
| 60 | " \ |
Denys Vlasenko | 17c838b | 2009-10-24 17:11:55 +0200 | [diff] [blame] | 61 | "\ |
| 62 | qwe |
| 63 | asd |
| 64 | zxc |
| 65 | " \ |
Denis Vlasenko | 08ec67b | 2008-03-26 13:32:30 +0000 | [diff] [blame] | 66 | "\ |
| 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 Vlasenko | 17c838b | 2009-10-24 17:11:55 +0200 | [diff] [blame] | 75 | testing "patch detects already applied hunk" \ |
| 76 | 'patch 2>&1; echo $?; cat input' \ |
| 77 | "\ |
Denys Vlasenko | 5fa5c4b | 2020-06-23 21:28:19 +0200 | [diff] [blame] | 78 | patching file input |
Denys Vlasenko | b82ae98 | 2010-11-21 05:53:34 +0100 | [diff] [blame] | 79 | Possibly reversed hunk 1 at 4 |
Rob Landley | 1bbc0cd | 2010-08-13 15:50:26 +0200 | [diff] [blame] | 80 | Hunk 1 FAILED 1/1. |
| 81 | abc |
| 82 | +def |
| 83 | 123 |
Denys Vlasenko | 17c838b | 2009-10-24 17:11:55 +0200 | [diff] [blame] | 84 | 1 |
| 85 | abc |
| 86 | def |
| 87 | 123 |
| 88 | " \ |
| 89 | "\ |
| 90 | abc |
| 91 | def |
| 92 | 123 |
| 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 Vlasenko | 3f75d7b | 2010-08-16 02:56:32 +0200 | [diff] [blame] | 103 | testing "patch detects already applied hunk at the EOF" \ |
Denys Vlasenko | 6f2ebae | 2009-10-25 00:35:04 +0200 | [diff] [blame] | 104 | 'patch 2>&1; echo $?; cat input' \ |
| 105 | "\ |
Denys Vlasenko | 5fa5c4b | 2020-06-23 21:28:19 +0200 | [diff] [blame] | 106 | patching file input |
Denys Vlasenko | b82ae98 | 2010-11-21 05:53:34 +0100 | [diff] [blame] | 107 | Possibly reversed hunk 1 at 4 |
Denys Vlasenko | 3f75d7b | 2010-08-16 02:56:32 +0200 | [diff] [blame] | 108 | Hunk 1 FAILED 1/1. |
| 109 | abc |
| 110 | 123 |
| 111 | +456 |
Denys Vlasenko | 6f2ebae | 2009-10-25 00:35:04 +0200 | [diff] [blame] | 112 | 1 |
| 113 | abc |
| 114 | 123 |
| 115 | 456 |
| 116 | " \ |
| 117 | "\ |
| 118 | abc |
| 119 | 123 |
| 120 | 456 |
| 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 Vlasenko | a4160e1 | 2010-08-16 01:33:57 +0200 | [diff] [blame] | 131 | # testing "test name" "command(s)" "expected result" "file input" "stdin" |
Denys Vlasenko | a4160e1 | 2010-08-16 01:33:57 +0200 | [diff] [blame] | 132 | testing "patch -N ignores already applied hunk" \ |
| 133 | 'patch -N 2>&1; echo $?; cat input' \ |
| 134 | "\ |
| 135 | patching file input |
| 136 | 0 |
| 137 | abc |
| 138 | def |
| 139 | 123 |
| 140 | " \ |
| 141 | "\ |
| 142 | abc |
| 143 | def |
| 144 | 123 |
| 145 | " \ |
| 146 | "\ |
| 147 | --- input |
| 148 | +++ input |
| 149 | @@ -1,2 +1,3 @@ |
| 150 | abc |
| 151 | +def |
| 152 | 123 |
| 153 | " \ |
| 154 | |
Denys Vlasenko | e7b0a9e | 2010-08-22 05:39:15 +0200 | [diff] [blame] | 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' \ |
| 158 | "\ |
| 159 | patching file input |
| 160 | 0 |
| 161 | abc |
| 162 | def |
| 163 | 123 |
| 164 | " \ |
| 165 | "\ |
| 166 | abc |
| 167 | 123 |
| 168 | " \ |
| 169 | "\ |
| 170 | --- foo.old |
| 171 | +++ foo |
| 172 | @@ -1,2 +1,3 @@ |
| 173 | abc |
| 174 | +def |
| 175 | 123 |
| 176 | " \ |
| 177 | |
Denys Vlasenko | fe9403a | 2010-11-28 01:41:40 +0100 | [diff] [blame] | 178 | # testing "test name" "command(s)" "expected result" "file input" "stdin" |
| 179 | testing "patch at the beginning" \ |
| 180 | 'patch 2>&1; cat input' \ |
| 181 | "\ |
| 182 | patching file input |
| 183 | 111changed |
| 184 | 444 |
| 185 | 555 |
| 186 | 666 |
| 187 | 777 |
| 188 | 888 |
| 189 | 999 |
| 190 | " \ |
| 191 | "\ |
| 192 | 111 |
| 193 | 222 |
| 194 | 333 |
| 195 | 444 |
| 196 | 555 |
| 197 | 666 |
| 198 | 777 |
| 199 | 888 |
| 200 | 999 |
| 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 Vlasenko | 9176f6c | 2011-08-16 22:57:12 +0200 | [diff] [blame] | 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' \ |
| 218 | "\ |
| 219 | creating testfile |
| 220 | 0 |
| 221 | qwerty |
| 222 | " "" "\ |
| 223 | --- /dev/null |
| 224 | +++ testfile |
| 225 | @@ -0,0 +1 @@ |
| 226 | +qwerty |
| 227 | " |
| 228 | |
Rob Landley | 39ec6a2 | 2011-10-10 19:59:38 +0200 | [diff] [blame] | 229 | # testing "test name" "command(s)" "expected result" "file input" "stdin" |
| 230 | testing "patch understands ...dir///dir..." \ |
| 231 | 'patch -p1 2>&1; echo $?' \ |
| 232 | "\ |
| 233 | patching file dir2///file |
| 234 | patch: can't open 'dir2///file': No such file or directory |
| 235 | 1 |
| 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 Koskinen | cb810c4 | 2016-11-22 00:19:51 +0200 | [diff] [blame] | 245 | testing "patch internal buffering bug?" \ |
| 246 | 'patch -p1 2>&1; echo $?; cat input' \ |
| 247 | "\ |
| 248 | patching file input |
| 249 | 0 |
| 250 | foo |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | 1 |
| 258 | 2 |
| 259 | 3 |
| 260 | |
| 261 | bar |
| 262 | " \ |
| 263 | "\ |
| 264 | foo |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | bar |
| 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 | -- |
| 287 | 2.9.2 |
| 288 | " \ |
| 289 | |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 290 | rm input.orig 2>/dev/null |
| 291 | |
Denis Vlasenko | cc2965f | 2008-03-25 14:15:39 +0000 | [diff] [blame] | 292 | exit $FAILCOUNT |