#!/bin/sh
# Run upstream's suite against the installed package.
#
# installwatch excludes /tmp and /var/tmp, so the suite refuses to run from
# either, and AUTOPKGTEST_TMP is usually under /tmp. Copy the tests somewhere
# else and run them from there.
set -e

for candidate in "${AUTOPKGTEST_TMP:-}" /var/local "$HOME" ; do
	case $candidate in
		""|/tmp/*|/var/tmp/*) continue ;;
	esac
	[ -d "$candidate" ] && [ -w "$candidate" ] || continue
	work=$(mktemp -d "$candidate/checkinstall-test.XXXXXX") && break
done
[ -n "${work:-}" ] || { echo "no writable directory outside /tmp to work in"; exit 1; }
trap 'rm -rf "$work"' EXIT
echo "working in $work"

src=$(pwd)
cp -a "$src/tests" "$work/tests"

# The suite finds /usr/bin/checkinstall and /etc/checkinstallrc by itself.
# CHECKINSTALL_SRC only supplies test-installwatch.c for 01; everything under
# test comes from the package.
CHECKINSTALL_INSTALLED=1 CHECKINSTALL_SRC="$src" "$work/tests/run-tests.sh"
