regression.sh 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 | diff -ubq $expected_out - >& /dev/null; then
  28. pass
  29. return 0
  30. else
  31. fail "(expected output: '$expected_out')"
  32. return 1
  33. fi
  34. }
  35. function main()
  36. {
  37. local rc=0
  38. local d
  39. for d in $SELF_DIR/*/; do
  40. cmpOutput "${d}in.diff" ${d}out.normal "-c always" || rc=1
  41. cmpOutput "${d}in.diff" ${d}out.side-by-side "-c always -s" || rc=1
  42. cmpOutput "${d}in.diff" ${d}out.w70 "-c always -s -w70" || rc=1
  43. cmpOutput "${d}in.diff" "${d}in.diff" "-c auto" || rc=1
  44. cmpOutput "${d}in.diff" "${d}in.diff" "-c auto -s" || rc=1
  45. cmpOutput "${d}in.diff" "${d}in.diff" "-c auto -s -w70" || rc=1
  46. done
  47. return $rc
  48. }
  49. main "$@"
  50. # vim:set et sts=4 sw=4: