summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-09-13 16:45:58 -0400
committerNick Mathewson <nickm@torproject.org>2019-09-14 19:00:41 -0400
commit28025698a15e19f0336b48d057177382a5a30b35 (patch)
tree282b85147e4d8babdcaacef38e568068cc441d38
parent98ab3817a86239f9c4888339625a55c55505ede2 (diff)
downloadtor-28025698a15e19f0336b48d057177382a5a30b35.tar.gz
tor-28025698a15e19f0336b48d057177382a5a30b35.zip
test_parseconf: run each test from inside its directory.
We need this to test includes and relative paths.
-rwxr-xr-xsrc/test/test_parseconf.sh45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh
index dc80fc36f6..afac358cbd 100755
--- a/src/test/test_parseconf.sh
+++ b/src/test/test_parseconf.sh
@@ -41,6 +41,20 @@ umask 077
set -e
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
if [ $# -ge 1 ]; then
TOR_BINARY="${1}"
@@ -49,6 +63,8 @@ else
TOR_BINARY="${TESTING_TOR_BINARY:-./src/app/tor}"
fi
+TOR_BINARY="$(abspath "$TOR_BINARY")"
+
# make a safe space for temporary files
DATA_DIR=$(mktemp -d -t tor_parseconf_tests.XXXXXX)
trap 'rm -rf "$DATA_DIR"' 0
@@ -80,20 +96,23 @@ for dir in "${EXAMPLEDIR}"/*; do
# We use printf since "echo -n" is not standard
printf "%s: " "$testname"
- if test -f "${dir}/torrc.defaults"; then
- DEFAULTS="${dir}/torrc.defaults"
+ PREV_DIR="$(pwd)"
+ cd "${dir}"
+
+ if test -f "./torrc.defaults"; then
+ DEFAULTS="./torrc.defaults"
else
DEFAULTS="${DATA_DIR}/EMPTY"
fi
- if test -f "${dir}/cmdline"; then
- CMDLINE="$(cat "${dir}"/cmdline)"
+ if test -f "./cmdline"; then
+ CMDLINE="$(cat ./cmdline)"
else
CMDLINE=""
fi
- if test -f "${dir}/expected"; then
- if test -f "${dir}/error"; then
+ if test -f "./expected"; then
+ if test -f "./error"; then
echo "FAIL: Found both ${dir}/expected and ${dir}/error."
echo "(Only one of these files should exist.)"
exit 1
@@ -101,14 +120,14 @@ for dir in "${EXAMPLEDIR}"/*; do
# This case should succeed: run dump-config and see if it does.
- "${TOR_BINARY}" -f "${dir}"/torrc \
+ "${TOR_BINARY}" -f "./torrc" \
--defaults-torrc "${DEFAULTS}" \
--dump-config short \
${CMDLINE} \
| "${FILTER}" > "${DATA_DIR}/output.${testname}" \
|| 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.
"${TOR_BINARY}" -f "${DATA_DIR}/output.${testname}" \
--defaults-torrc "${DATA_DIR}/empty" \
@@ -126,21 +145,21 @@ for dir in "${EXAMPLEDIR}"/*; do
echo "OK"
else
echo "FAIL"
- diff -u "${dir}/expected" "${DATA_DIR}/output.${testname}"
+ diff -u "./expected" "${DATA_DIR}/output.${testname}"
exit 1
fi
- elif test -f "${dir}/error"; then
+ elif test -f "./error"; then
# This case should fail: run verify-config and see if it does.
"${TOR_BINARY}" --verify-config \
- -f "${dir}"/torrc \
+ -f ./torrc \
--defaults-torrc "${DEFAULTS}" \
${CMDLINE} \
> "${DATA_DIR}/output.${testname}" \
&& 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
echo "OK"
else
@@ -159,4 +178,6 @@ for dir in "${EXAMPLEDIR}"/*; do
exit 1
fi
+ cd "${PREV_DIR}"
+
done