#!/bin/sh

set -e

announce(){
	echo
	echo "============== $*"
	echo
}

announce 'run-gforth-tests starting'

testfiles='checkans.fs coremore.fs dbltest.fs deferred.fs float.fs gforth.fs gforth-nofast.fs libcc.fs other.fs search.fs signals.fs tester.fs ttester.fs'

tester=`dpkg-query -L gforth-common | egrep -e 'test/tester\.fs$'`
if [ -z "$tester" ] || [ ! -f "$tester" ]; then
	echo 'Could not find test/tester.fs in gforth-common' 1>&2
	exit 1
fi
testdir=`dirname -- "$tester"`
cd -- "$testdir"

announce "run-gforth-tests running in $testdir"
for f in $testfiles; do
	announce "testing $f"
	gforth "$f" -e bye
done

announce "testing postpone.fs"
printf 'require tester.fs\nrequire coretest.fs\nrequire postpone.fs\nbye\n' | gforth

announce "looks like we're done"
