regression.sh 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. set -o errexit
  3. SELF_DIR=$(cd $(dirname $0) && pwd) || exit 1
  4. CDIFF=$SELF_DIR/../cdiff
  5. function pass()
  6. {
  7. if [[ -t 1 ]]; then
  8. echo -e "\x1b[01;32mPASS\x1b[0m" "$*"
  9. else
  10. echo "PASS" "$*"
  11. fi
  12. }
  13. function fail()
  14. {
  15. if [[ -t 1 ]]; then
  16. echo -e "\x1b[01;31mFAIL\x1b[0m" "$*"
  17. else
  18. echo "FAIL" "$*"
  19. fi
  20. }
  21. function cmpOutput()
  22. {
  23. local input=${1:?}
  24. local expected_out=${2:?}
  25. local cdiff_opt=${3:-""}
  26. echo -n "Test option '$cdiff_opt' with input '$input' ... "
  27. if $CDIFF $cdiff_opt $input 2>/dev/null \
  28. | diff -ubq $expected_out - >& /dev/null; then
  29. pass
  30. return 0
  31. else
  32. fail "(expected output: '$expected_out')"
  33. return 1
  34. fi
  35. }
  36. function main()
  37. {
  38. local rc=0
  39. local d
  40. for d in $SELF_DIR/*/; do
  41. cmpOutput "${d}in.diff" ${d}out.normal "-c always" || rc=1
  42. cmpOutput "${d}in.diff" ${d}out.side-by-side "-c always -s" || rc=1
  43. cmpOutput "${d}in.diff" ${d}out.w70 "-c always -s -w70" || rc=1
  44. cmpOutput "${d}in.diff" "${d}in.diff" "-c auto" || rc=1
  45. cmpOutput "${d}in.diff" "${d}in.diff" "-c auto -s" || rc=1
  46. cmpOutput "${d}in.diff" "${d}in.diff" "-c auto -s -w70" || rc=1
  47. done
  48. return $rc
  49. }
  50. main "$@"
  51. # vim:set et sts=4 sw=4: