#!/usr/bin/env bash
# Run Raku tests via prove6. Used by pre-commit and for local runs.
set -euo pipefail

if ! command -v prove6 &>/dev/null; then
    RAKU_PREFIX=$(raku -e 'print $*EXECUTABLE.resolve.parent.parent')
    export PATH="${HOME}/.raku/share/perl6/site/bin:${RAKU_PREFIX}/share/perl6/site/bin:${RAKU_PREFIX}/bin:${PATH}"
fi

if command -v prove6 &>/dev/null; then
    exec prove6 -Ilib t/
fi

# Fallback when App::Prove6 is not installed (e.g. system raku on PATH).
for test in t/*.rakutest t/*.t; do
    [[ -e "$test" ]] || continue
    raku -Ilib "$test"
done
