test_practracker.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. --include-dir "" \
  23. --max-file-size=0 \
  24. --max-function-size=0 \
  25. --max-h-file-size=0 \
  26. --max-h-include-count=0 \
  27. --max-include-count=0 \
  28. --terse \
  29. "${DATA}/" "$@";
  30. }
  31. compare() {
  32. # we can't use cmp because we need to use -b for windows
  33. diff -b -u "$@" > "${TMPDIR}/test-diff"
  34. if test -z "$(cat "${TMPDIR}"/test-diff)"; then
  35. echo "OK"
  36. else
  37. cat "${TMPDIR}/test-diff"
  38. echo "FAILED"
  39. exit 1
  40. fi
  41. }
  42. echo "unit tests:"
  43. "${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker_tests.py" || exit 1
  44. echo "ex0:"
  45. run_practracker --exceptions "${DATA}/ex0.txt" > "${TMPDIR}/ex0-received.txt"
  46. compare "${TMPDIR}/ex0-received.txt" "${DATA}/ex0-expected.txt"
  47. echo "ex1:"
  48. run_practracker --exceptions "${DATA}/ex1.txt" > "${TMPDIR}/ex1-received.txt"
  49. compare "${TMPDIR}/ex1-received.txt" "${DATA}/ex1-expected.txt"
  50. echo "ex1.overbroad:"
  51. run_practracker --exceptions "${DATA}/ex1.txt" --list-overbroad > "${TMPDIR}/ex1-overbroad-received.txt"
  52. compare "${TMPDIR}/ex1-overbroad-received.txt" "${DATA}/ex1-overbroad-expected.txt"