#!/bin/sh
set -eu

_usage(){
    echo "Usage: ${0} directory os" >&2
    exit 2
}

[ -z "${1-}" ] && _usage
[ -z "${2-}" ] && _usage

test_dir=$(cd "${1}" && pwd)
host_os="${2}"

if [ ! -f "${test_dir}/testsuite/.setup" ]; then
    rm -rf "${test_dir}/testsuite"
    cp -a testsuite "${test_dir}/"
    rm -f "${test_dir}/testsuite/mdev.tests"
    if [ -f "debian/testsuite-${host_os}.diff" ]; then
        patch -p1 -d "${test_dir}" < "debian/testsuite-${host_os}.diff"
    fi
    touch "${test_dir}/testsuite/.setup"
fi

cd "${test_dir}/testsuite"

export SKIP_KNOWN_BUGS=y
export SKIP_INTERNET_TESTS=y
# Always run tests in UTF8 mode to verify unicode support
export LANG=C.UTF-8 LC_ALL=C.UTF-8
# Required for testsuite/taskset.tests
export SHELL='/bin/sh -e'
#dash echo does not understand -e, bb builds its own in this case
export ECHO=/bin/echo

exec ./runtest
