#!/bin/bash
#

# set -x

function usage () {
    echo "$(basename $0)   <testset 1> [<testset 2> ... <testset N>]"
    echo ""
    echo "  Runs a set of tests identified in one or more testset files."
    echo "  Each testset file named on the command line should contain a list"
    echo "  of tests (or test globs) to run.  These are used as arguments"
    echo "  to the runtests script to execute the tests.  Test set files can"
    echo "  contain comments (lines starting with '#') and blank lines."
}

if [ $# -eq 0 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
    usage
    exit 1
fi

while [ $# -gt 0 ]; do
    # If the user passed a bad file name, error.
    if ! [ -e $1 ]; then
        echo "Testset file $1 doesn't exist"
        usage
        exit 1
    fi

    # Iterate over non-comment lines, adding them to the TESTS string
    while read LINE; do
        # Append this test name/glob to the list of tests to run.
        TESTS="${TESTS+$TESTS }$LINE"
    done <<< $(grep -v "^#" $1)
    shift 1
done

# Run all the tests specified in all of the testset files.
exec $(dirname $0)/runtests $TESTS
