123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. TOP_DIR=$(cd $(dirname $0)/.. && pwd) || exit 1
  3. cd $TOP_DIR || exit 1
  4. YDIFF=./ydiff
  5. # To test with py3k: PYTHON=python3 make test
  6. PYTHON=${PYTHON:-python}
  7. function pass()
  8. {
  9. if [[ -t 1 ]]; then
  10. echo -e "\x1b[032mPASS\x1b[0m" "$*"
  11. else
  12. echo "PASS" "$*"
  13. fi
  14. }
  15. function fail()
  16. {
  17. if [[ -t 1 ]]; then
  18. echo -e "\x1b[01;31mFAIL\x1b[0m" "$*"
  19. else
  20. echo "FAIL" "$*"
  21. fi
  22. }
  23. function cmp_output()
  24. {
  25. local input=${1:?}
  26. local expected_out=${2:?}
  27. local ydiff_opt=${3:-""}
  28. local cmd
  29. cmd=$(printf "%-7s $YDIFF %-24s < %-30s " $PYTHON "$ydiff_opt" "$input")
  30. printf "$cmd"
  31. if eval $cmd 2>/dev/null | cmp --silent $expected_out -; then
  32. pass
  33. return 0
  34. else
  35. fail "!= $expected_out"
  36. return 1
  37. fi
  38. }
  39. function main()
  40. {
  41. local total=0
  42. local e=0
  43. local d
  44. for d in tests/*/; do
  45. d=${d%/}
  46. [[ -f $d/in.diff ]] || continue
  47. cmp_output $d/in.diff $d/out.normal "-c always" || ((e++))
  48. cmp_output $d/in.diff $d/out.side-by-side "-c always -s" || ((e++))
  49. cmp_output $d/in.diff $d/out.w70 "-c always -s -w70" || ((e++))
  50. cmp_output $d/in.diff $d/out.w70.wrap "-c always -s -w70 --wrap" || ((e++))
  51. cmp_output $d/in.diff $d/in.diff "-c auto" || ((e++))
  52. cmp_output $d/in.diff $d/in.diff "-c auto -s" || ((e++))
  53. cmp_output $d/in.diff $d/in.diff "-c auto -s -w70" || ((e++))
  54. cmp_output $d/in.diff $d/in.diff "-c auto -s -w70 --wrap" || ((e++))
  55. (( total += 6 ))
  56. done
  57. if (( e > 0 )); then
  58. echo "*** $e out of $total tests failed." >&2
  59. return 1
  60. else
  61. echo "All $total tests passed."
  62. return 0
  63. fi
  64. }
  65. main "$@"
  66. # vim:set et sts=4 sw=4: