PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH

[[ -e .testdir ]] && . .testdir
if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then
   TESTDIR=$(mktemp -d -t dracut-test.XXXXXX)
fi
echo "TESTDIR=\"$TESTDIR\"" > .testdir
export TESTDIR

while (($# > 0)); do
    case $1 in
        --run)
	    echo "TEST RUN: $TEST_DESCRIPTION"
	    test_run
	    exit $?;;
        --setup)
	    echo "TEST SETUP: $TEST_DESCRIPTION"
	    test_setup
	    exit $?;;
        --clean)
	    echo "TEST CLEANUP: $TEST_DESCRIPTION"
	    test_cleanup
	    rm -fr "$TESTDIR"
	    rm -f .testdir
	    exit $?;;
        --all)
	    echo -n "TEST: $TEST_DESCRIPTION ";
	    (
		test_setup && test_run
		ret=$?
		test_cleanup
		rm -fr "$TESTDIR"
		rm -f .testdir
		exit $ret
	    ) </dev/null >test.log 2>&1
	    ret=$?
	    if [ $ret -eq 0 ]; then
               rm test.log
	       echo "[OK]"
	    else
	       echo "[FAILED]"
	       echo "see $(pwd)/test.log"
	    fi
	    exit $ret;;
        *) break ;;
    esac
    shift
done
