#!/bin/sh
# Copyright (c) 2001-2005, 2008 Joe Orton <https://github.com/notroj/litmus>

prefix=/usr
exec_prefix=/usr
libexecdir=${exec_prefix}/libexec
datadir=${datarootdir}
datarootdir=${prefix}/share

TESTROOT=${TESTROOT-"${exec_prefix}/libexec/litmus"}
TESTS=${TESTS-"basic copymove props locks http"}

usage() {
    cat <<EOF
litmus: Usage: $0 [OPTIONS] URL [USERNAME PASSWORD]

Options:
 -k, --keep-going           continue testing even if one suite fails
 -p, --proxy=URL            use given proxy server URL
 -s, --system-proxy         use proxy server configuration from system
 -c, --client-cert=CERT     use given PKCS#12 client cert
 -u, --client-cert-uri=URI  use given client cert URI
 -i, --insecure             ignore TLS certificate verification failures
 -q, --quiet                use abbreviated output
 -n, --no-colour            disable colour in output
 -o, --colour               enable colour in output
 
Significant environment variables:

    \$TESTS     - specify test programs to run
        default: "basic copymove props locks http"
    \$TESTROOT  - specify alternate program directory
        default: ${exec_prefix}/libexec/litmus

Feedback via <https://github.com/notroj/litmus>
EOF
    exit 1
}

nofail=0

case $1 in
--help|-h) usage ;;
--keep-going|-k) nofail=1; shift ;;
--version) echo litmus 0.17; exit 0 ;;
esac

test "$#" = "0" && usage

for t in $TESTS; do
    tprog="${TESTROOT}/${t}"
    if test -x ${tprog}; then
	if ${tprog} "$@"; then
	    : pass
	elif test $nofail -eq 0; then
	    echo "See debug.log for network/debug traces."
	    exit 1
	fi
    else
	echo "ERROR: Could not find ${tprog}"
	exit 1
    fi
done
