123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #!/bin/sh
- umask 077
- set -e
- die() { echo "$1" >&2 ; exit 5; }
- abspath() {
- f=$@
- if [ -d "$f" ]; then
- dir="$f"
- base=""
- else
- dir="$(dirname "$f")"
- base="/$(basename "$f")"
- fi
- dir="$(cd "$dir" && pwd)"
- echo "$dir$base"
- }
- if [ $# -ge 1 ]; then
- TOR_BINARY="${1}"
- shift
- else
- TOR_BINARY="${TESTING_TOR_BINARY:-./src/app/tor}"
- fi
- TOR_BINARY="$(abspath "$TOR_BINARY")"
- DATA_DIR=$(mktemp -d -t tor_parseconf_tests.XXXXXX)
- trap 'rm -rf "$DATA_DIR"' 0
- touch "${DATA_DIR}/EMPTY" || die "Couldn't create empty file."
- EXAMPLEDIR="$(dirname "$0")"/conf_examples
- case "$(uname -s)" in
- CYGWIN*) WINDOWS=1;;
- MINGW*) WINDOWS=1;;
- MSYS*) WINDOWS=1;;
- *) WINDOWS=0;;
- esac
- if test "$WINDOWS" = 1; then
- FILTER="dos2unix"
- else
- FILTER="cat"
- fi
- for dir in "${EXAMPLEDIR}"/*; do
- if ! test -d "${dir}"; then
-
- continue
- fi
- testname="$(basename "${dir}")"
-
- printf "%s: " "$testname"
- PREV_DIR="$(pwd)"
- cd "${dir}"
- if test -f "./torrc.defaults"; then
- DEFAULTS="./torrc.defaults"
- else
- DEFAULTS="${DATA_DIR}/EMPTY"
- fi
- if test -f "./cmdline"; then
- CMDLINE="$(cat ./cmdline)"
- else
- CMDLINE=""
- fi
- 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
- fi
-
- "${TOR_BINARY}" -f "./torrc" \
- --defaults-torrc "${DEFAULTS}" \
- --dump-config short \
- ${CMDLINE} \
- | "${FILTER}" > "${DATA_DIR}/output.${testname}" \
- || die "Failure: Tor exited."
- if cmp "./expected" "${DATA_DIR}/output.${testname}">/dev/null ; then
-
- "${TOR_BINARY}" -f "${DATA_DIR}/output.${testname}" \
- --defaults-torrc "${DATA_DIR}/empty" \
- --dump-config short \
- | "${FILTER}" \
- > "${DATA_DIR}/output_2.${testname}" \
- || die "Failure: Tor exited on round-trip."
- if ! cmp "${DATA_DIR}/output.${testname}" \
- "${DATA_DIR}/output_2.${testname}"; then
- echo "Failure: did not match on round-trip."
- exit 1
- fi
- echo "OK"
- else
- echo "FAIL"
- diff -u "./expected" "${DATA_DIR}/output.${testname}"
- exit 1
- fi
- elif test -f "./error"; then
-
- "${TOR_BINARY}" --verify-config \
- -f ./torrc \
- --defaults-torrc "${DEFAULTS}" \
- ${CMDLINE} \
- > "${DATA_DIR}/output.${testname}" \
- && die "Failure: Tor did not report an error."
- expect_err="$(cat ./error)"
- if grep "${expect_err}" "${DATA_DIR}/output.${testname}" >/dev/null; then
- echo "OK"
- else
- echo "FAIL"
- echo "Expected error: ${expect_err}"
- echo "Tor said:"
- cat "${DATA_DIR}/output.${testname}"
- exit 1
- fi
- else
-
-
- echo "FAIL: Did not find ${dir}/expected or ${dir}/error."
- exit 1
- fi
- cd "${PREV_DIR}"
- done
|