regression.sh 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. set -o errexit
  3. SELF_DIR=$(cd $(dirname $0) && pwd) || exit 1
  4. CDIFF=$SELF_DIR/../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 cmpOutput()
  24. {
  25. local input=${1:?}
  26. local expected_out=${2:?}
  27. local cdiff_opt=${3:-""}
  28. echo -n "Test option '$cdiff_opt' with input '$input' ... "
  29. if $PYTHON $CDIFF $cdiff_opt $input 2>/dev/null \
  30. | diff -ubq $expected_out - >& /dev/null; then
  31. pass
  32. return 0
  33. else
  34. fail "(expected output: '$expected_out')"
  35. return 1
  36. fi
  37. }
  38. function main()
  39. {
  40. local rc=0
  41. local d
  42. for d in $SELF_DIR/*/; do
  43. cmpOutput "${d}in.diff" ${d}out.normal "-c always" || rc=1
  44. cmpOutput "${d}in.diff" ${d}out.side-by-side "-c always -s" || rc=1
  45. cmpOutput "${d}in.diff" ${d}out.w70 "-c always -s -w70" || rc=1
  46. cmpOutput "${d}in.diff" "${d}in.diff" "-c auto" || rc=1
  47. cmpOutput "${d}in.diff" "${d}in.diff" "-c auto -s" || rc=1
  48. cmpOutput "${d}in.diff" "${d}in.diff" "-c auto -s -w70" || rc=1
  49. done
  50. return $rc
  51. }
  52. main "$@"
  53. # vim:set et sts=4 sw=4: