diff.test 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. #testing "name" "command" "result" "infile" "stdin"
  3. seq 10 > left
  4. seq 11 > right
  5. testcmd "unknown argument" '--oops left right 2>/dev/null ; echo $?' "2\n" "" ""
  6. testcmd "missing" 'missing1 missing2 2>/dev/null ; echo $?' "2\n" "" ""
  7. testcmd "- -" '- - ; echo $?' "0\n" "" "whatever"
  8. testcmd "simple" "-u -L lll -L rrr left right" '--- lll
  9. +++ rrr
  10. @@ -8,3 +8,4 @@
  11. 8
  12. 9
  13. 10
  14. +11
  15. ' "" ""
  16. mkdir -p tree1 tree2
  17. echo foo > tree1/file
  18. echo food > tree2/file
  19. # Debian's diff gratuitously echoes its command line with -r. No idea why.
  20. testcmd "-r" "-u -r -L tree1/file -L tree2/file tree1 tree2 | grep -v ^diff" \
  21. '--- tree1/file
  22. +++ tree2/file
  23. @@ -1 +1 @@
  24. -foo
  25. +food
  26. ' "" ""
  27. echo -e "hello\r\nworld\r\n"> a
  28. echo -e "hello\nworld\n"> b
  29. testcmd "--strip-trailing-cr off" "-q a b" "Files a and b differ\n" "" ""
  30. testcmd "--strip-trailing-cr on" '-u --strip-trailing-cr a b; echo $?' \
  31. "0\n" "" ""
  32. echo -e "1\n2" > aa
  33. echo -e "1\n3" > bb
  34. testcmd "line format" "--unchanged-line-format=U%l --old-line-format=D%l --new-line-format=A%l aa bb" "U1D2A3" "" ""
  35. testcmd "line format empty" "--unchanged-line-format= --old-line-format=D%l --new-line-format=A%l aa bb" "D2A3" "" ""
  36. mkfifo fifo1
  37. mkfifo fifo2
  38. echo -e "1\n2" > fifo1&
  39. echo -e "1\n3" > fifo2&
  40. testcmd "fifos" "-u -L fifo1 -L fifo2 fifo1 fifo2" '--- fifo1
  41. +++ fifo2
  42. @@ -1,2 +1,2 @@
  43. 1
  44. -2
  45. +3
  46. ' "" ""
  47. echo -e 'int bar() {
  48. }
  49. int foo() {
  50. }
  51. int baz() {
  52. 1
  53. {2
  54. 3
  55. 4
  56. foo
  57. }
  58. '> a
  59. echo -e 'int barbar() {
  60. }
  61. int foo() {
  62. }
  63. int baz() {
  64. 1a
  65. {2
  66. 3
  67. 4
  68. bar
  69. }
  70. '> b
  71. testcmd 'show function' "--show-function-line=' {$' -U1 -L lll -L rrr a b" \
  72. '--- lll
  73. +++ rrr
  74. @@ -1,2 +1,2 @@
  75. -int bar() {
  76. +int barbar() {
  77. }
  78. @@ -7,3 +7,3 @@ int foo() {
  79. int baz() {
  80. - 1
  81. + 1a
  82. {2
  83. @@ -11,3 +11,3 @@ int baz() {
  84. 4
  85. - foo
  86. + bar
  87. }
  88. ' \
  89. '' ''
  90. seq 1 100000 > one
  91. seq 1 4 100000 > two
  92. testcmd 'big hunk' '-u --label nope --label nope one two' \
  93. "$(echo -e '--- nope\n+++ nope\n@@ -1,100000 +1,25000 @@'; for((i=1;i<=100000;i++)); do (((i-1)&3)) && echo "-$i" || echo " $i"; done)\n" '' ''
  94. rm one two