3
0

diff.tests 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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" "commands" "expected result" "file input" "stdin"
  6. # diff outputs date/time in the header, which should not be analysed
  7. # NB: sed has tab character in s command!
  8. TRIM_TAB="sed 's/ .*//'"
  9. testing "diff of stdin" \
  10. "diff -u - input | $TRIM_TAB" \
  11. "\
  12. --- -
  13. +++ input
  14. @@ -1 +1,3 @@
  15. +qwe
  16. asd
  17. +zxc
  18. " \
  19. "qwe\nasd\nzxc\n" \
  20. "asd\n"
  21. testing "diff of stdin, no newline in the file" \
  22. "diff -u - input | $TRIM_TAB" \
  23. "\
  24. --- -
  25. +++ input
  26. @@ -1 +1,3 @@
  27. +qwe
  28. asd
  29. +zxc
  30. \\ No newline at end of file
  31. " \
  32. "qwe\nasd\nzxc" \
  33. "asd\n"
  34. # we also test that stdin is in fact NOT read
  35. testing "diff of stdin, twice" \
  36. 'diff - -; echo $?; wc -c' \
  37. "0\n5\n" \
  38. "" \
  39. "stdin"
  40. testing "diff of empty file against nonempty one" \
  41. "diff -u - input | $TRIM_TAB" \
  42. "\
  43. --- -
  44. +++ input
  45. @@ -0,0 +1 @@
  46. +a
  47. " \
  48. "a\n" \
  49. ""
  50. testing "diff -b treats EOF as whitespace" \
  51. 'diff -ub - input; echo $?' \
  52. "0\n" \
  53. "abc" \
  54. "abc "
  55. testing "diff -b treats all spaces as equal" \
  56. 'diff -ub - input; echo $?' \
  57. "0\n" \
  58. "a \t c\n" \
  59. "a\t \tc\n"
  60. testing "diff -B ignores changes whose lines are all blank" \
  61. 'diff -uB - input; echo $?' \
  62. "0\n" \
  63. "a\n" \
  64. "\na\n\n"
  65. testing "diff -B does not ignore changes whose lines are not all blank" \
  66. "diff -uB - input | $TRIM_TAB" \
  67. "\
  68. --- -
  69. +++ input
  70. @@ -1,3 +1 @@
  71. -
  72. -b
  73. -
  74. +a
  75. " \
  76. "a\n" \
  77. "\nb\n\n"
  78. testing "diff always takes context from old file" \
  79. "diff -ub - input | $TRIM_TAB" \
  80. "\
  81. --- -
  82. +++ input
  83. @@ -1 +1,3 @@
  84. +abc
  85. a c
  86. +def
  87. " \
  88. "abc\na c\ndef\n" \
  89. "a c\n"
  90. # testing "test name" "commands" "expected result" "file input" "stdin"
  91. # clean up
  92. rm -rf diff1 diff2
  93. mkdir diff1 diff2 diff2/subdir
  94. echo qwe >diff1/-
  95. echo asd >diff2/subdir/-
  96. optional FEATURE_DIFF_DIR
  97. testing "diff diff1 diff2/subdir" \
  98. "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
  99. "\
  100. --- diff1/-
  101. +++ diff2/subdir/-
  102. @@ -1 +1 @@
  103. -qwe
  104. +asd
  105. " \
  106. "" ""
  107. SKIP=
  108. # using directory structure from prev test...
  109. optional FEATURE_DIFF_DIR
  110. testing "diff dir dir2/file/-" \
  111. "diff -ur diff1 diff2/subdir/- | $TRIM_TAB" \
  112. "\
  113. --- diff1/-
  114. +++ diff2/subdir/-
  115. @@ -1 +1 @@
  116. -qwe
  117. +asd
  118. " \
  119. "" ""
  120. SKIP=
  121. # using directory structure from prev test...
  122. mkdir diff1/test
  123. mkfifo diff2/subdir/test
  124. optional FEATURE_DIFF_DIR
  125. testing "diff of dir and fifo" \
  126. "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
  127. "\
  128. --- diff1/-
  129. +++ diff2/subdir/-
  130. @@ -1 +1 @@
  131. -qwe
  132. +asd
  133. Only in diff2/subdir: test
  134. " \
  135. "" ""
  136. SKIP=
  137. # using directory structure from prev test...
  138. rmdir diff1/test
  139. echo >diff1/test
  140. optional FEATURE_DIFF_DIR
  141. testing "diff of file and fifo" \
  142. "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
  143. "\
  144. --- diff1/-
  145. +++ diff2/subdir/-
  146. @@ -1 +1 @@
  147. -qwe
  148. +asd
  149. File diff2/subdir/test is not a regular file or directory and was skipped
  150. " \
  151. "" ""
  152. SKIP=
  153. # using directory structure from prev test...
  154. mkfifo diff1/test2
  155. optional FEATURE_DIFF_DIR
  156. testing "diff -rN does not read non-regular files" \
  157. "diff -urN diff1 diff2/subdir | $TRIM_TAB" \
  158. "\
  159. --- diff1/-
  160. +++ diff2/subdir/-
  161. @@ -1 +1 @@
  162. -qwe
  163. +asd
  164. File diff2/subdir/test is not a regular file or directory and was skipped
  165. File diff1/test2 is not a regular file or directory and was skipped
  166. " \
  167. "" ""
  168. SKIP=
  169. # clean up
  170. rm -rf diff1 diff2
  171. # NOT using directory structure from prev test...
  172. mkdir diff1 diff2
  173. echo qwe >diff1/-
  174. echo rty >diff2/-
  175. optional FEATURE_DIFF_DIR
  176. testing "diff diff1 diff2/" \
  177. "diff -ur diff1 diff2/ | $TRIM_TAB; diff -ur .///diff1 diff2//// | $TRIM_TAB" \
  178. "\
  179. --- diff1/-
  180. +++ diff2/-
  181. @@ -1 +1 @@
  182. -qwe
  183. +rty
  184. --- .///diff1/-
  185. +++ diff2////-
  186. @@ -1 +1 @@
  187. -qwe
  188. +rty
  189. " \
  190. "" ""
  191. SKIP=
  192. # clean up
  193. rm -rf diff1 diff2
  194. exit $FAILCOUNT