#!/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, including its `dev` extra (`-e .[dev]`, which pulls in
# pytest, httpx, and the `web` extra so tests/test_web.py can import FastAPI),
# so src/ edits are picked up on the next run. 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? It's picked up automatically (see
# _fades_common.sh); force it manually with 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

source "$repo_root/bin/_fades_common.sh"
_fades_ensure_fresh_venv tests -d pytest

exec fades -d pytest --pip-options="-e .[dev]" -x pytest -v -- "$@"
