patch.tests 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. #!/bin/sh
  2. # Copyright 2008 by Denys Vlasenko
  3. # Licensed under GPLv2, see file LICENSE in this source tree.
  4. . ./testing.sh
  5. # testing "test name" "command(s)" "expected result" "file input" "stdin"
  6. testing "patch with old_file == new_file" \
  7. 'patch 2>&1; echo $?; cat input' \
  8. "\
  9. patching file input
  10. 0
  11. qwe
  12. asd
  13. zxc
  14. " \
  15. "\
  16. qwe
  17. zxc
  18. " \
  19. "\
  20. --- input Jan 01 01:01:01 2000
  21. +++ input Jan 01 01:01:01 2000
  22. @@ -1,2 +1,3 @@
  23. qwe
  24. +asd
  25. zxc
  26. " \
  27. testing "patch with nonexistent old_file" \
  28. 'patch 2>&1; echo $?; cat input' \
  29. "\
  30. patching file input
  31. 0
  32. qwe
  33. asd
  34. zxc
  35. " \
  36. "\
  37. qwe
  38. zxc
  39. " \
  40. "\
  41. --- input.doesnt_exist Jan 01 01:01:01 2000
  42. +++ input Jan 01 01:01:01 2000
  43. @@ -1,2 +1,3 @@
  44. qwe
  45. +asd
  46. zxc
  47. " \
  48. testing "patch -R with nonexistent old_file" \
  49. 'patch -R 2>&1; echo $?; cat input' \
  50. "\
  51. patching file input
  52. 0
  53. qwe
  54. zxc
  55. " \
  56. "\
  57. qwe
  58. asd
  59. zxc
  60. " \
  61. "\
  62. --- input.doesnt_exist Jan 01 01:01:01 2000
  63. +++ input Jan 01 01:01:01 2000
  64. @@ -1,2 +1,3 @@
  65. qwe
  66. +asd
  67. zxc
  68. " \
  69. testing "patch detects already applied hunk" \
  70. 'patch 2>&1; echo $?; cat input' \
  71. "\
  72. patching file input
  73. Possibly reversed hunk 1 at 4
  74. Hunk 1 FAILED 1/1.
  75. abc
  76. +def
  77. 123
  78. 1
  79. abc
  80. def
  81. 123
  82. " \
  83. "\
  84. abc
  85. def
  86. 123
  87. " \
  88. "\
  89. --- input.old Jan 01 01:01:01 2000
  90. +++ input Jan 01 01:01:01 2000
  91. @@ -1,2 +1,3 @@
  92. abc
  93. +def
  94. 123
  95. " \
  96. testing "patch detects already applied hunk at the EOF" \
  97. 'patch 2>&1; echo $?; cat input' \
  98. "\
  99. patching file input
  100. Possibly reversed hunk 1 at 4
  101. Hunk 1 FAILED 1/1.
  102. abc
  103. 123
  104. +456
  105. 1
  106. abc
  107. 123
  108. 456
  109. " \
  110. "\
  111. abc
  112. 123
  113. 456
  114. " \
  115. "\
  116. --- input.old Jan 01 01:01:01 2000
  117. +++ input Jan 01 01:01:01 2000
  118. @@ -1,2 +1,3 @@
  119. abc
  120. 123
  121. +456
  122. " \
  123. # testing "test name" "command(s)" "expected result" "file input" "stdin"
  124. testing "patch -N ignores already applied hunk" \
  125. 'patch -N 2>&1; echo $?; cat input' \
  126. "\
  127. patching file input
  128. 0
  129. abc
  130. def
  131. 123
  132. " \
  133. "\
  134. abc
  135. def
  136. 123
  137. " \
  138. "\
  139. --- input
  140. +++ input
  141. @@ -1,2 +1,3 @@
  142. abc
  143. +def
  144. 123
  145. " \
  146. # testing "test name" "command(s)" "expected result" "file input" "stdin"
  147. testing "patch FILE PATCH" \
  148. 'cat >a.patch; patch input a.patch 2>&1; echo $?; cat input; rm a.patch' \
  149. "\
  150. patching file input
  151. 0
  152. abc
  153. def
  154. 123
  155. " \
  156. "\
  157. abc
  158. 123
  159. " \
  160. "\
  161. --- foo.old
  162. +++ foo
  163. @@ -1,2 +1,3 @@
  164. abc
  165. +def
  166. 123
  167. " \
  168. # testing "test name" "command(s)" "expected result" "file input" "stdin"
  169. testing "patch at the beginning" \
  170. 'patch 2>&1; cat input' \
  171. "\
  172. patching file input
  173. 111changed
  174. 444
  175. 555
  176. 666
  177. 777
  178. 888
  179. 999
  180. " \
  181. "\
  182. 111
  183. 222
  184. 333
  185. 444
  186. 555
  187. 666
  188. 777
  189. 888
  190. 999
  191. " \
  192. "\
  193. --- input
  194. +++ input
  195. @@ -1,6 +1,4 @@
  196. -111
  197. -222
  198. -333
  199. +111changed
  200. 444
  201. 555
  202. 666
  203. " \
  204. # testing "test name" "command(s)" "expected result" "file input" "stdin"
  205. testing "patch creates new file" \
  206. 'patch 2>&1; echo $?; cat testfile; rm testfile' \
  207. "\
  208. creating testfile
  209. 0
  210. qwerty
  211. " "" "\
  212. --- /dev/null
  213. +++ testfile
  214. @@ -0,0 +1 @@
  215. +qwerty
  216. "
  217. # testing "test name" "command(s)" "expected result" "file input" "stdin"
  218. testing "patch understands ...dir///dir..." \
  219. 'patch -p1 2>&1; echo $?' \
  220. "\
  221. patching file dir2///file
  222. patch: can't open 'dir2///file': No such file or directory
  223. 1
  224. " "" "\
  225. --- bogus_dir///dir2///file
  226. +++ bogus_dir///dir2///file
  227. @@ -1,2 +1,3 @@
  228. qwe
  229. +asd
  230. zxc
  231. "
  232. testing "patch internal buffering bug?" \
  233. 'patch -p1 2>&1; echo $?; cat input' \
  234. "\
  235. patching file input
  236. 0
  237. foo
  238. 1
  239. 2
  240. 3
  241. bar
  242. " \
  243. "\
  244. foo
  245. bar
  246. " \
  247. "\
  248. --- a/input.orig
  249. +++ b/input
  250. @@ -5,5 +5,8 @@ foo
  251. +1
  252. +2
  253. +3
  254. bar
  255. --
  256. 2.9.2
  257. " \
  258. rm input.orig 2>/dev/null
  259. exit $FAILCOUNT