#!/usr/bin/env bash
# Run the juanita test suite from this checkout, using fades.
#
# Like bin/run_dev, fades creates/reuses a managed virtualenv with this project
# installed editable (`-e .`), so src/ edits are picked up on the next run. The
# `-d pytest` pulls pytest into that venv; any extra args are forwarded to
# pytest.
#
# Usage:
#   bin/run_tests                      # run everything (pytest config lives in pyproject.toml)
#   bin/run_tests tests/test_push.py   # a single file
#   bin/run_tests -k linking -x        # filter + stop on first failure
#
# Added a new dependency to pyproject.toml? Force a fresh venv so it gets
# installed: FADES_REBUILD=1 bin/run_tests
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"

if ! command -v fades >/dev/null 2>&1; then
    echo "error: fades is not installed. See https://github.com/PyAr/fades" >&2
    exit 1
fi

pip_options="-e ."
if [[ "${FADES_REBUILD:-}" == "1" ]]; then
    pip_options="-e . --force-reinstall"
fi

exec fades -d pytest --pip-options="$pip_options" -x pytest -v -- "$@"
