regression.sh 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. TOP_DIR=$(cd $(dirname $0)/.. && pwd) || exit 1
  3. cd $TOP_DIR || exit 1
  4. CDIFF=./cdiff
  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[01;32mPASS\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 cdiff_opt=${3:-""}
  28. local cmd
  29. cmd=$(printf "%-8s $CDIFF %-18s < %-25s " $PYTHON "$cdiff_opt" "$input")
  30. printf "$cmd"
  31. if eval $cmd 2>/dev/null | diff -ubq $expected_out - >& /dev/null; 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. cmp_output $d/in.diff $d/out.normal "-c always" || ((e++))
  47. cmp_output $d/in.diff $d/out.side-by-side "-c always -s" || ((e++))
  48. cmp_output $d/in.diff $d/out.w70 "-c always -s -w70" || ((e++))
  49. cmp_output $d/in.diff $d/in.diff "-c auto" || ((e++))
  50. cmp_output $d/in.diff $d/in.diff "-c auto -s" || ((e++))
  51. cmp_output $d/in.diff $d/in.diff "-c auto -s -w70" || ((e++))
  52. (( total += 6 ))
  53. done
  54. if (( e > 0 )); then
  55. echo "*** $e out of $total tests failed." >&2
  56. return 1
  57. else
  58. echo "All $total tests passed."
  59. return 0
  60. fi
  61. }
  62. main "$@"
  63. # vim:set et sts=4 sw=4: