#!/usr/bin/env bash
# --------------------( LICENSE                            )--------------------
# Copyright 2014-2019 by Alexis Pietak & Cecil Curry.
# See "LICENSE" for further details.
#
# --------------------( SYNOPSIS                           )--------------------
# This Bash shell script is a simple wrapper around this application's
# py.test-based and setuptools-driven test suite. All arguments passed to this
# script are passed "as is" to that test suite.
#
# This script is defined as a Bash rather than Bourne script purely for the
# canonical ${BASH_SOURCE} string global, reliably providing the absolute path
# of this script and hence this script's directory.

# ....................{ PATHS                              }....................
# string canonicalize_path(string pathname)
#
# Canonicalize the passed pathname. The "readlink" command's GNU-specific "-f"
# option would be preferable but is unsupported by OS X's NetBSD-specific
# version of "readlink". Instead, just defer to Python.
function canonicalize_path() {
    python -c "
import os, sys
print(os.path.realpath(os.path.expanduser(sys.argv[1])))" "${1}"
}

# Absolute or relative path of this script.
script_filename="$(canonicalize_path "${BASH_SOURCE[0]}")"

# Absolute or relative path of this script's directory and hence BETSE's home.
betse_dirname="$(dirname "${script_filename}")"
# echo "BETSE home: ${betse_dirname}"

# ....................{ TESTS                              }....................
# Temoprarily change the current working directory to BETSE's home.
pushd "${betse_dirname}" >/dev/null

# Run BETSE's test suite with all passed arguments.
python3 setup.py test "${@}"

# Revert the current working directory to the prior such directory.
popd >/dev/null
