diff.tests 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. # 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 "test name" "options" "expected result" "file input" "stdin"
  41. rm -rf diff1 diff2
  42. mkdir diff1 diff2 diff2/subdir
  43. echo qwe >diff1/-
  44. echo asd >diff2/subdir/-
  45. testing "diff diff1 diff2/subdir" \
  46. "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
  47. "\
  48. --- diff1/-
  49. +++ diff2/subdir/-
  50. @@ -1 +1 @@
  51. -qwe
  52. +asd
  53. " \
  54. "" ""
  55. # using directory structure from prev test...
  56. testing "diff dir dir2/file/-" \
  57. "diff -ur diff1 diff2/subdir/- | $TRIM_TAB" \
  58. "\
  59. --- diff1/-
  60. +++ diff2/subdir/-
  61. @@ -1 +1 @@
  62. -qwe
  63. +asd
  64. " \
  65. "" ""
  66. # using directory structure from prev test...
  67. mkdir diff1/test
  68. mkfifo diff2/subdir/test
  69. testing "diff of dir and fifo" \
  70. "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
  71. "\
  72. --- diff1/-
  73. +++ diff2/subdir/-
  74. @@ -1 +1 @@
  75. -qwe
  76. +asd
  77. Only in diff2/subdir: test
  78. " \
  79. "" ""
  80. # using directory structure from prev test...
  81. rmdir diff1/test
  82. echo >diff1/test
  83. testing "diff of file and fifo" \
  84. "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
  85. "\
  86. --- diff1/-
  87. +++ diff2/subdir/-
  88. @@ -1 +1 @@
  89. -qwe
  90. +asd
  91. File diff2/subdir/test is not a regular file or directory and was skipped
  92. " \
  93. "" ""
  94. # using directory structure from prev test...
  95. mkfifo diff1/test2
  96. testing "diff -rN does not read non-regular files" \
  97. "diff -urN diff1 diff2/subdir | $TRIM_TAB" \
  98. "\
  99. --- diff1/-
  100. +++ diff2/subdir/-
  101. @@ -1 +1 @@
  102. -qwe
  103. +asd
  104. File diff2/subdir/test is not a regular file or directory and was skipped
  105. File diff1/test2 is not a regular file or directory and was skipped
  106. " \
  107. "" ""
  108. # clean up
  109. rm -rf diff1 diff2
  110. exit $FAILCOUNT