#!/bin/bash

OBUILD=$(pwd)/../../dist/build/obuild/obuild

if [ ! -x ${OBUILD} ]; then
	echo "obuild has not been built"
	exit 1
fi

TESTS="simple autogenerated with-c dep-uri autopack autopack2 complex complex2"
if [ $# -gt 0 ]; then
	TESTS="$1"
	DEBUG="--debug+"
else
	DEBUG=""
fi

RED="\033[1;31m"
GREEN="\033[1;32m"
BLUE="\033[1;34m"
WHITE="\033[0m"

for t in ${TESTS}
do
	cd ${t}

	echo -e "$BLUE ==== test ${t} ====${WHITE}"
	${OBUILD} clean
	${OBUILD} --strict configure --enable-library-bytecode --enable-executable-bytecode --enable-library-debugging --enable-library-profiling --enable-executable-profiling --enable-executable-debugging --annot
	if [ $? -ne 0 ]; then
		echo -e "${RED}ERROR${WHITE}: configure failed"
		cd ..
		continue
	fi
	${OBUILD} ${DEBUG} build
	if [ $? -ne 0 ]; then
		echo -e "${RED}ERROR${WHITE}: build failed"
		cd ..
		continue
	fi
	echo -e "${GREEN}SUCCESS${WHITE}: $t passed"
	cd ..
done

for t in ${TESTS}
do
	cd ${t}
	${OBUILD} clean
	cd ..
done
