patch.tests 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. Possibly reversed hunk 1 at 4
  73. Hunk 1 FAILED 1/1.
  74. abc
  75. +def
  76. 123
  77. patching file input
  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. Possibly reversed hunk 1 at 4
  100. Hunk 1 FAILED 1/1.
  101. abc
  102. 123
  103. +456
  104. patching file input
  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. rm input.orig 2>/dev/null
  169. exit $FAILCOUNT