#!/bin/bash

# Turn off the annoying ginkgo warning.
# TODO: We should actually upgrade ginkgo!
export ACK_GINKGO_RC=true

if [ -z "$1" ]; then 
	echo "No packages need to be tested"
	exit 0
fi

echo WHAT: $@
echo SKIP: $SKIP
echo GINKGO_ARGS: $GINKGO_ARGS

# We want to run all the tests even if one suite fails. We'll increment this each
# time a suite fails.
RC=0

# Go through each package we've been told to test. If there are actually test files present,
# then run those tests. If the package is included in SKIP, we'll skip them.
for PKG in "$@"; do 
	# Skip any tests we've been told to skip.
	if [[ "$SKIP" == *"$PKG"* ]]; then
	  echo "Skipping tests for package: ${PKG}"
	  continue
	fi

	HAS_TESTS=$(find ${PKG} -name "ut.test")
	if [ ! -z "${HAS_TESTS}" ]; then 
		echo "Running tests for package: ${PKG}";
		${PKG}/ut.test ${GINKGO_ARGS} || ((RC++))
	else 
		echo "WARNING: No tests to run in ${PKG}, skipping"
	fi
done

exit ${RC}
