#!/usr/bin/env bash
set -euo pipefail
export PATH="$HOME/.local/bin:$PATH"

BRANCH="${1:?Usage: test_all_impls.sh <branch>}"
cd ~/rich
git checkout "$BRANCH"

PYTHONS=(
    "$HOME/.local/bin/python3.9"
    "$HOME/.local/bin/python3.10"
    "$HOME/.local/bin/python3.11"
    "$HOME/.local/bin/python3.12"
    "$HOME/.local/bin/python3.13"
    "$HOME/.local/bin/python3.14"
    "$HOME/.local/bin/pypy3.10"
)

for PYTHON in "${PYTHONS[@]}"; do
    IMPL=$($PYTHON -c "import platform; print(f'{platform.python_implementation()} {platform.python_version()}')")
    echo ""
    echo "=== $IMPL ==="

    VENV_DIR="/tmp/rich-test-$(basename $PYTHON)"
    rm -rf "$VENV_DIR"
    uv venv --python "$PYTHON" "$VENV_DIR" 2>/dev/null
    VENV_PY="$VENV_DIR/bin/python"

    uv pip install --python "$VENV_PY" -e . pytest attrs 2>/dev/null

    $VENV_PY -m pytest tests/ -x -q 2>&1 | tail -3
done
