patch.tests 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/bin/sh
  2. # Copyright 2008 by Denys Vlasenko
  3. # Licensed under GPL v2, see file LICENSE for details.
  4. . ./testing.sh
  5. # testing "test name" "options" "expected result" "file input" "stdin"
  6. testing "patch with old_file == new_file" \
  7. 'patch; 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; 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; 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. patch: hunk #1 FAILED at 1
  74. patch: 1 out of 1 hunk FAILED
  75. 1
  76. abc
  77. def
  78. 123
  79. " \
  80. "\
  81. abc
  82. def
  83. 123
  84. " \
  85. "\
  86. --- input.old Jan 01 01:01:01 2000
  87. +++ input Jan 01 01:01:01 2000
  88. @@ -1,2 +1,3 @@
  89. abc
  90. +def
  91. 123
  92. " \
  93. # Currently fails (erroneously appends second "456" line):
  94. false && testing "patch detects already applied hunk" \
  95. 'patch 2>&1; echo $?; cat input' \
  96. "\
  97. patching file input
  98. patch: hunk #1 FAILED at 2
  99. patch: 1 out of 1 hunk FAILED
  100. 1
  101. abc
  102. 123
  103. 456
  104. " \
  105. "\
  106. abc
  107. 123
  108. 456
  109. " \
  110. "\
  111. --- input.old Jan 01 01:01:01 2000
  112. +++ input Jan 01 01:01:01 2000
  113. @@ -1,2 +1,3 @@
  114. abc
  115. 123
  116. +456
  117. " \
  118. rm input.orig 2>/dev/null
  119. exit $FAILCOUNT