regression.sh 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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[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 cdiff_opt=${3:-""}
  28. local cmd
  29. cmd=$(printf "%-8s $CDIFF %-18s < %-30s " $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. [[ -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/in.diff "-c auto" || ((e++))
  51. cmp_output $d/in.diff $d/in.diff "-c auto -s" || ((e++))
  52. cmp_output $d/in.diff $d/in.diff "-c auto -s -w70" || ((e++))
  53. (( total += 6 ))
  54. done
  55. if (( e > 0 )); then
  56. echo "*** $e out of $total tests failed." >&2
  57. return 1
  58. else
  59. echo "All $total tests passed."
  60. return 0
  61. fi
  62. }
  63. main "$@"
  64. # vim:set et sts=4 sw=4: