test_practracker.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. umask 077
  3. TMPDIR=""
  4. clean () {
  5. if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
  6. rm -rf "$TMPDIR"
  7. fi
  8. }
  9. trap clean EXIT HUP INT TERM
  10. if test "${PRACTRACKER_DIR}" = "" ||
  11. test ! -e "${PRACTRACKER_DIR}/practracker.py" ; then
  12. PRACTRACKER_DIR=$(dirname "$0")
  13. fi
  14. TMPDIR="$(mktemp -d -t pracktracker.test.XXXXXX)"
  15. if test -z "${TMPDIR}" || test ! -d "${TMPDIR}" ; then
  16. echo >&2 "mktemp failed."
  17. exit 1;
  18. fi
  19. DATA="${PRACTRACKER_DIR}/testdata"
  20. run_practracker() {
  21. "${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker.py" \
  22. --max-include-count=0 --max-file-size=0 --max-function-size=0 --terse \
  23. "${DATA}/" "$@";
  24. }
  25. compare() {
  26. # we can't use cmp because we need to use -b for windows
  27. diff -b -u "$@" > "${TMPDIR}/test-diff"
  28. if test -z "$(cat "${TMPDIR}"/test-diff)"; then
  29. echo "OK"
  30. else
  31. cat "${TMPDIR}/test-diff"
  32. echo "FAILED"
  33. exit 1
  34. fi
  35. }
  36. echo "unit tests:"
  37. "${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker_tests.py" || exit 1
  38. echo "ex0:"
  39. run_practracker --exceptions "${DATA}/ex0.txt" > "${TMPDIR}/ex0-received.txt"
  40. compare "${TMPDIR}/ex0-received.txt" "${DATA}/ex0-expected.txt"
  41. echo "ex1:"
  42. run_practracker --exceptions "${DATA}/ex1.txt" > "${TMPDIR}/ex1-received.txt"
  43. compare "${TMPDIR}/ex1-received.txt" "${DATA}/ex1-expected.txt"