#!/bin/sh
# Runs the full test suite.
# This is run by the fulltest target in obj/
set -e

fail () {
	echo "fulltest error: $@" >&2
	exit 1
}

. /etc/mooix.conf || fail "cannot read /etc/mooix.conf"
if [ ! -e $MOOROOT ]; then
	fail "MOOROOT ($MOOROOT) does not exist. Is mooix installed?"
fi

echo "Closing the moo for testing.."
(eval $STOPHOOK) >/dev/null || fail "is mood running?"

echo "Setting up the test tree.."
sudo -u $MOOADMIN ../utils/testtree setup . $MOOROOT || fail "tree setup failed"

if ! sudo -u $MOOENTRYGROUP ../utils/testobjs \
	`find $MOOROOT -type d -not -name t | grep -v /t/`; then
	fail "Test failures; leaving test setup for post-mortem."
fi

echo "Removing the test tree.."
sudo -u $MOOADMIN ../utils/testtree clean $MOOROOT || fail "failed to clean the tree"

echo "Testing complete, reopening the moo.."
(eval $STARTHOOK) >/dev/null || fail "failed to run starthook"
