#!/bin/sh

set -e

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

# Same as test_parallel_reports_failure, but in serial mode: the exit
# code of a test must be reported as a failure too, even though it is
# then known directly, and not through a result file.
PKGOS_RUN_TESTS_FIXTURE=yes
export PKGOS_RUN_TESTS_FIXTURE

set +e
OUT=$("${RUNNER}" --serial "${FIXTURES}" 2>&1)
RC=$?
set -e

if [ "${RC}" = "0" ] ; then
	echo "${ME}: runner must exit non-zero when a test fails"
	exit 1
fi
case "${OUT}" in
*"test_failing: FAILED"*) ;;
*)
	echo "${ME}: the failing test is not reported as FAILED:"
	echo "${OUT}"
	exit 1
;;
esac
case "${OUT}" in
*"Failure while running unit tests :("*) ;;
*)
	echo "${ME}: missing failure summary:"
	echo "${OUT}"
	exit 1
;;
esac

exit 0
