#!/usr/bin/sh
#
# Copyright (c) 2006 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# Author: David Malcolm

# Run all tests in a test package

usage() {
	echo "Usage:  rhts-run-package PACKAGEFILE"
	echo "Locally runs all tests found in the package"
}

if [ -z $1 ]; then
	usage
	exit 1	
fi

RPM=$1
EXTRACTION_PATH=`mktemp -d /mnt/testarea/rhts-run-package-XXXXXXXX`
OPATH=$(pwd)
pushd $EXTRACTION_PATH
rpm2cpio $OPATH/$RPM | cpio -i --make-directories > /dev/null || exit 1
cd mnt/tests
for i in `find -type d`; do 
	pushd $i
	if [ -e Makefile ]; then
			make run || exit 1
	fi
	popd
done
popd

