2019-07-30 18:07:40 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-08-22 20:36:36 +02:00
|
|
|
# Fail this script if any subprocess fails unexpectedly.
|
2020-01-14 08:20:36 +01:00
|
|
|
set -e
|
|
|
|
|
2019-07-30 18:07:40 +02:00
|
|
|
umask 077
|
2020-01-13 22:17:51 +01:00
|
|
|
unset TOR_DISABLE_PRACTRACKER
|
2019-07-30 18:07:40 +02:00
|
|
|
|
|
|
|
TMPDIR=""
|
2021-08-22 20:36:36 +02:00
|
|
|
clean() {
|
2019-07-30 18:07:40 +02:00
|
|
|
if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
|
2021-08-22 20:36:36 +02:00
|
|
|
rm -rf "$TMPDIR"
|
2019-07-30 18:07:40 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
trap clean EXIT HUP INT TERM
|
|
|
|
|
|
|
|
if test "${PRACTRACKER_DIR}" = "" ||
|
|
|
|
test ! -e "${PRACTRACKER_DIR}/practracker.py" ; then
|
|
|
|
PRACTRACKER_DIR=$(dirname "$0")
|
|
|
|
fi
|
|
|
|
|
2019-12-12 07:15:29 +01:00
|
|
|
# Change to the tor directory, and canonicalise PRACTRACKER_DIR,
|
|
|
|
# so paths in practracker output are consistent, even in out-of-tree builds
|
|
|
|
cd "${PRACTRACKER_DIR}"/../../..
|
|
|
|
PRACTRACKER_DIR="scripts/maint/practracker"
|
|
|
|
|
2019-07-30 18:07:40 +02:00
|
|
|
TMPDIR="$(mktemp -d -t pracktracker.test.XXXXXX)"
|
|
|
|
if test -z "${TMPDIR}" || test ! -d "${TMPDIR}" ; then
|
|
|
|
echo >&2 "mktemp failed."
|
2021-08-22 20:36:36 +02:00
|
|
|
exit 1
|
2019-07-30 18:07:40 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
DATA="${PRACTRACKER_DIR}/testdata"
|
|
|
|
|
|
|
|
run_practracker() {
|
|
|
|
"${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker.py" \
|
2019-09-02 21:31:31 +02:00
|
|
|
--include-dir "" \
|
2019-09-11 14:59:29 +02:00
|
|
|
--max-file-size=0 \
|
|
|
|
--max-function-size=0 \
|
|
|
|
--max-h-file-size=0 \
|
|
|
|
--max-h-include-count=0 \
|
|
|
|
--max-include-count=0 \
|
|
|
|
--terse \
|
2020-01-14 08:23:41 +01:00
|
|
|
"${DATA}/" "$@" || echo "practracker exit status: $?"
|
2019-07-30 18:07:40 +02:00
|
|
|
}
|
2021-08-22 20:36:36 +02:00
|
|
|
|
2019-08-01 21:05:34 +02:00
|
|
|
compare() {
|
|
|
|
# we can't use cmp because we need to use -b for windows
|
2020-01-14 08:20:36 +01:00
|
|
|
diff -b -u "$@" > "${TMPDIR}/test-diff" || true
|
2019-08-01 21:05:34 +02:00
|
|
|
if test -z "$(cat "${TMPDIR}"/test-diff)"; then
|
|
|
|
echo "OK"
|
|
|
|
else
|
|
|
|
cat "${TMPDIR}/test-diff"
|
|
|
|
echo "FAILED"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2019-07-30 18:07:40 +02:00
|
|
|
|
2019-08-01 20:01:43 +02:00
|
|
|
echo "unit tests:"
|
|
|
|
|
2020-01-14 08:20:36 +01:00
|
|
|
"${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker_tests.py"
|
2019-08-01 20:01:43 +02:00
|
|
|
|
2019-07-30 18:07:40 +02:00
|
|
|
echo "ex0:"
|
|
|
|
|
2020-01-14 08:24:11 +01:00
|
|
|
run_practracker --exceptions "${DATA}/ex0.txt" \
|
|
|
|
> "${TMPDIR}/ex0-received.txt" 2>&1
|
2019-07-30 18:07:40 +02:00
|
|
|
|
2020-01-14 08:24:11 +01:00
|
|
|
compare "${TMPDIR}/ex0-received.txt" \
|
|
|
|
"${DATA}/ex0-expected.txt"
|
2019-07-30 18:07:40 +02:00
|
|
|
|
|
|
|
echo "ex1:"
|
|
|
|
|
2020-01-14 08:24:11 +01:00
|
|
|
run_practracker --exceptions "${DATA}/ex1.txt" \
|
|
|
|
> "${TMPDIR}/ex1-received.txt" 2>&1
|
2019-07-30 18:07:40 +02:00
|
|
|
|
2020-01-14 08:24:11 +01:00
|
|
|
compare "${TMPDIR}/ex1-received.txt" \
|
|
|
|
"${DATA}/ex1-expected.txt"
|
2019-09-18 14:53:17 +02:00
|
|
|
|
|
|
|
echo "ex1.overbroad:"
|
|
|
|
|
2020-01-14 08:24:11 +01:00
|
|
|
run_practracker --exceptions "${DATA}/ex1.txt" --list-overbroad \
|
|
|
|
> "${TMPDIR}/ex1-overbroad-received.txt" 2>&1
|
2019-09-18 14:53:17 +02:00
|
|
|
|
2020-01-14 08:24:11 +01:00
|
|
|
compare "${TMPDIR}/ex1-overbroad-received.txt" \
|
|
|
|
"${DATA}/ex1-overbroad-expected.txt"
|
2020-02-03 19:11:58 +01:00
|
|
|
|
|
|
|
echo "ex1.regen:"
|
|
|
|
|
|
|
|
cp "${DATA}/ex1.txt" "${TMPDIR}/ex1-copy.txt"
|
|
|
|
run_practracker --exceptions "${TMPDIR}/ex1-copy.txt" --regen >/dev/null 2>&1
|
|
|
|
compare "${TMPDIR}/ex1-copy.txt" "${DATA}/ex1-regen-expected.txt"
|
|
|
|
|
|
|
|
echo "ex1.regen_overbroad:"
|
|
|
|
|
|
|
|
cp "${DATA}/ex1.txt" "${TMPDIR}/ex1-copy.txt"
|
|
|
|
run_practracker --exceptions "${TMPDIR}/ex1-copy.txt" --regen-overbroad >/dev/null 2>&1
|
|
|
|
compare "${TMPDIR}/ex1-copy.txt" "${DATA}/ex1-regen-overbroad-expected.txt"
|