Merge branch 'maint-0.4.8'
[tor.git] / scripts / maint / practracker / test_practracker.sh
blobbb734ad9cd6b246602e889736f395e5fcb3facd5
1 #!/bin/sh
3 # Fail this script if any subprocess fails unexpectedly.
4 set -e
6 umask 077
7 unset TOR_DISABLE_PRACTRACKER
9 TMPDIR=""
10 clean() {
11 if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
12 rm -rf "$TMPDIR"
15 trap clean EXIT HUP INT TERM
17 if test "${PRACTRACKER_DIR}" = "" ||
18 test ! -e "${PRACTRACKER_DIR}/practracker.py" ; then
19 PRACTRACKER_DIR=$(dirname "$0")
22 # Change to the tor directory, and canonicalise PRACTRACKER_DIR,
23 # so paths in practracker output are consistent, even in out-of-tree builds
24 cd "${PRACTRACKER_DIR}"/../../..
25 PRACTRACKER_DIR="scripts/maint/practracker"
27 TMPDIR="$(mktemp -d -t pracktracker.test.XXXXXX)"
28 if test -z "${TMPDIR}" || test ! -d "${TMPDIR}" ; then
29 echo >&2 "mktemp failed."
30 exit 1
33 DATA="${PRACTRACKER_DIR}/testdata"
35 run_practracker() {
36 "${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker.py" \
37 --include-dir "" \
38 --max-file-size=0 \
39 --max-function-size=0 \
40 --max-h-file-size=0 \
41 --max-h-include-count=0 \
42 --max-include-count=0 \
43 --terse \
44 "${DATA}/" "$@" || echo "practracker exit status: $?"
47 compare() {
48 # we can't use cmp because we need to use -b for windows
49 diff -b -u "$@" > "${TMPDIR}/test-diff" || true
50 if test -z "$(cat "${TMPDIR}"/test-diff)"; then
51 echo "OK"
52 else
53 cat "${TMPDIR}/test-diff"
54 echo "FAILED"
55 exit 1
59 echo "unit tests:"
61 "${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker_tests.py"
63 echo "ex0:"
65 run_practracker --exceptions "${DATA}/ex0.txt" \
66 > "${TMPDIR}/ex0-received.txt" 2>&1
68 compare "${TMPDIR}/ex0-received.txt" \
69 "${DATA}/ex0-expected.txt"
71 echo "ex1:"
73 run_practracker --exceptions "${DATA}/ex1.txt" \
74 > "${TMPDIR}/ex1-received.txt" 2>&1
76 compare "${TMPDIR}/ex1-received.txt" \
77 "${DATA}/ex1-expected.txt"
79 echo "ex1.overbroad:"
81 run_practracker --exceptions "${DATA}/ex1.txt" --list-overbroad \
82 > "${TMPDIR}/ex1-overbroad-received.txt" 2>&1
84 compare "${TMPDIR}/ex1-overbroad-received.txt" \
85 "${DATA}/ex1-overbroad-expected.txt"
87 echo "ex1.regen:"
89 cp "${DATA}/ex1.txt" "${TMPDIR}/ex1-copy.txt"
90 run_practracker --exceptions "${TMPDIR}/ex1-copy.txt" --regen >/dev/null 2>&1
91 compare "${TMPDIR}/ex1-copy.txt" "${DATA}/ex1-regen-expected.txt"
93 echo "ex1.regen_overbroad:"
95 cp "${DATA}/ex1.txt" "${TMPDIR}/ex1-copy.txt"
96 run_practracker --exceptions "${TMPDIR}/ex1-copy.txt" --regen-overbroad >/dev/null 2>&1
97 compare "${TMPDIR}/ex1-copy.txt" "${DATA}/ex1-regen-overbroad-expected.txt"