#!/bin/bash
# ffoo test framework
# See LICENSE file for copyright and license details.

export TF_VERSION="0.0.4"

die() {
    echo "$@" && exit 9
}

export LC_ALL=C
export TF_DIR=${TF_DIR:-$(dirname "$0")}
export TF_SUITE="${TF_SUITE:-tests}"
export TF_ARTIFACTS="${TF_ARTIFACTS:-tfkit-artifacts}"
export TF_COLLECT="${TF_COLLECT:-auto}"


usage() {
    echo "usage: $(basename "$0") [-c|-C] [-t tests_re] [-s subtest_re] [-p binpath] [-v] [-d]" >&2
    exit 2
}

version() {
    echo "TFKit (A trivial test kit) $TF_VERSION"
    exit 0
}

while true; do case "$1" in
    -c|--collect)           TF_COLLECT=always; shift ;;
    -C|--no-collect)        TF_COLLECT=never; shift ;;
    -t|--filter-test)       export TF_FILTER_TEST="$2"; shift 2 ;;
    -s|--filter-subtest)    export TF_FILTER_SUBTEST="$2"; shift 2 ;;
    -p|--prefix)            export PATH="$(readlink -f "$2")/bin:$PATH"; shift 2 ;;
    -d|--debug)             export TF_DEBUG=true; shift ;;
    -v|--verbose)           export TF_VERBOSE=true; shift ;;
    --version)              version ;;
    --version-semver)       echo "$TF_VERSION"; exit 0 ;;
    "") break ;;
    *)  usage ;;
esac done

. "$TF_DIR/include/harness.sh" \
 || die "cannot import harness; is TF_DIR set properly?: $TF_DIR"

time tf_run_tests