mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 07:07:52 +01:00
test_parseconf: run each test from inside its directory.
We need this to test includes and relative paths.
This commit is contained in:
parent
98ab3817a8
commit
28025698a1
1 changed files with 33 additions and 12 deletions
|
@ -41,6 +41,20 @@ umask 077
|
||||||
set -e
|
set -e
|
||||||
die() { echo "$1" >&2 ; exit 5; }
|
die() { echo "$1" >&2 ; exit 5; }
|
||||||
|
|
||||||
|
# emulate realpath(), in case coreutils or equivalent is not installed.
|
||||||
|
abspath() {
|
||||||
|
f=$@
|
||||||
|
if [ -d "$f" ]; then
|
||||||
|
dir="$f"
|
||||||
|
base=""
|
||||||
|
else
|
||||||
|
dir="$(dirname "$f")"
|
||||||
|
base="/$(basename "$f")"
|
||||||
|
fi
|
||||||
|
dir="$(cd "$dir" && pwd)"
|
||||||
|
echo "$dir$base"
|
||||||
|
}
|
||||||
|
|
||||||
# find the tor binary
|
# find the tor binary
|
||||||
if [ $# -ge 1 ]; then
|
if [ $# -ge 1 ]; then
|
||||||
TOR_BINARY="${1}"
|
TOR_BINARY="${1}"
|
||||||
|
@ -49,6 +63,8 @@ else
|
||||||
TOR_BINARY="${TESTING_TOR_BINARY:-./src/app/tor}"
|
TOR_BINARY="${TESTING_TOR_BINARY:-./src/app/tor}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
TOR_BINARY="$(abspath "$TOR_BINARY")"
|
||||||
|
|
||||||
# make a safe space for temporary files
|
# make a safe space for temporary files
|
||||||
DATA_DIR=$(mktemp -d -t tor_parseconf_tests.XXXXXX)
|
DATA_DIR=$(mktemp -d -t tor_parseconf_tests.XXXXXX)
|
||||||
trap 'rm -rf "$DATA_DIR"' 0
|
trap 'rm -rf "$DATA_DIR"' 0
|
||||||
|
@ -80,20 +96,23 @@ for dir in "${EXAMPLEDIR}"/*; do
|
||||||
# We use printf since "echo -n" is not standard
|
# We use printf since "echo -n" is not standard
|
||||||
printf "%s: " "$testname"
|
printf "%s: " "$testname"
|
||||||
|
|
||||||
if test -f "${dir}/torrc.defaults"; then
|
PREV_DIR="$(pwd)"
|
||||||
DEFAULTS="${dir}/torrc.defaults"
|
cd "${dir}"
|
||||||
|
|
||||||
|
if test -f "./torrc.defaults"; then
|
||||||
|
DEFAULTS="./torrc.defaults"
|
||||||
else
|
else
|
||||||
DEFAULTS="${DATA_DIR}/EMPTY"
|
DEFAULTS="${DATA_DIR}/EMPTY"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -f "${dir}/cmdline"; then
|
if test -f "./cmdline"; then
|
||||||
CMDLINE="$(cat "${dir}"/cmdline)"
|
CMDLINE="$(cat ./cmdline)"
|
||||||
else
|
else
|
||||||
CMDLINE=""
|
CMDLINE=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -f "${dir}/expected"; then
|
if test -f "./expected"; then
|
||||||
if test -f "${dir}/error"; then
|
if test -f "./error"; then
|
||||||
echo "FAIL: Found both ${dir}/expected and ${dir}/error."
|
echo "FAIL: Found both ${dir}/expected and ${dir}/error."
|
||||||
echo "(Only one of these files should exist.)"
|
echo "(Only one of these files should exist.)"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -101,14 +120,14 @@ for dir in "${EXAMPLEDIR}"/*; do
|
||||||
|
|
||||||
# This case should succeed: run dump-config and see if it does.
|
# This case should succeed: run dump-config and see if it does.
|
||||||
|
|
||||||
"${TOR_BINARY}" -f "${dir}"/torrc \
|
"${TOR_BINARY}" -f "./torrc" \
|
||||||
--defaults-torrc "${DEFAULTS}" \
|
--defaults-torrc "${DEFAULTS}" \
|
||||||
--dump-config short \
|
--dump-config short \
|
||||||
${CMDLINE} \
|
${CMDLINE} \
|
||||||
| "${FILTER}" > "${DATA_DIR}/output.${testname}" \
|
| "${FILTER}" > "${DATA_DIR}/output.${testname}" \
|
||||||
|| die "Failure: Tor exited."
|
|| die "Failure: Tor exited."
|
||||||
|
|
||||||
if cmp "${dir}/expected" "${DATA_DIR}/output.${testname}">/dev/null ; then
|
if cmp "./expected" "${DATA_DIR}/output.${testname}">/dev/null ; then
|
||||||
# Check round-trip.
|
# Check round-trip.
|
||||||
"${TOR_BINARY}" -f "${DATA_DIR}/output.${testname}" \
|
"${TOR_BINARY}" -f "${DATA_DIR}/output.${testname}" \
|
||||||
--defaults-torrc "${DATA_DIR}/empty" \
|
--defaults-torrc "${DATA_DIR}/empty" \
|
||||||
|
@ -126,21 +145,21 @@ for dir in "${EXAMPLEDIR}"/*; do
|
||||||
echo "OK"
|
echo "OK"
|
||||||
else
|
else
|
||||||
echo "FAIL"
|
echo "FAIL"
|
||||||
diff -u "${dir}/expected" "${DATA_DIR}/output.${testname}"
|
diff -u "./expected" "${DATA_DIR}/output.${testname}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
elif test -f "${dir}/error"; then
|
elif test -f "./error"; then
|
||||||
# This case should fail: run verify-config and see if it does.
|
# This case should fail: run verify-config and see if it does.
|
||||||
|
|
||||||
"${TOR_BINARY}" --verify-config \
|
"${TOR_BINARY}" --verify-config \
|
||||||
-f "${dir}"/torrc \
|
-f ./torrc \
|
||||||
--defaults-torrc "${DEFAULTS}" \
|
--defaults-torrc "${DEFAULTS}" \
|
||||||
${CMDLINE} \
|
${CMDLINE} \
|
||||||
> "${DATA_DIR}/output.${testname}" \
|
> "${DATA_DIR}/output.${testname}" \
|
||||||
&& die "Failure: Tor did not report an error."
|
&& die "Failure: Tor did not report an error."
|
||||||
|
|
||||||
expect_err="$(cat "${dir}"/error)"
|
expect_err="$(cat ./error)"
|
||||||
if grep "${expect_err}" "${DATA_DIR}/output.${testname}" >/dev/null; then
|
if grep "${expect_err}" "${DATA_DIR}/output.${testname}" >/dev/null; then
|
||||||
echo "OK"
|
echo "OK"
|
||||||
else
|
else
|
||||||
|
@ -159,4 +178,6 @@ for dir in "${EXAMPLEDIR}"/*; do
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cd "${PREV_DIR}"
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
Loading…
Add table
Reference in a new issue