#!/bin/sh

set -e

ME=$(basename $0)
RUNNER=$(readlink -f ../../../build-tools/pkgos-run-tests)
FIXTURES=$(readlink -f ./fixtures)

# Without PKGOS_RUN_TESTS_FIXTURE set, every fixture passes, the
# output of passing tests is not printed, and the runner exits 0.
# -c 1 also exercises the concurrency option.
set +e
OUT=$("${RUNNER}" -c 1 "${FIXTURES}" 2>&1)
RC=$?
set -e

case "${OUT}" in
*"Successfully ran 4 tests :)"*) ;;
*)
	echo "${ME}: expected a successful run of 4 tests, got rc=${RC}:"
	echo "${OUT}"
	exit 1
;;
esac
if [ "${RC}" != "0" ] ; then
	echo "${ME}: runner must exit 0 when every test passes, got ${RC}"
	exit 1
fi
case "${OUT}" in
*"A line of output from a passing test."*)
	echo "${ME}: the output of a passing test must not be printed"
	exit 1
;;
esac

exit 0
