#!/usr/bin/env bash
set -euo pipefail

echo "Running tests..."
# No `--workspace`: test `[workspace.default-members]` (defaults to ALL
# when not set). Mirrors bin/check-lint so wasm-only crates excluded
# from default-members are excluded from both clippy AND tests. See
# release#128.
#
# `--all-features` exercises every feature-gated path that clippy lints.
#
# `"$@"` forwards extra args to nextest/cargo, e.g.:
#   bin/check-tests --nocapture
#   bin/check-tests -p mycrate test_name
# `--no-tests=pass` (nextest) so a workspace with zero tests on a fresh
# repo doesn't fail the umbrella check. Tests proper still fail loudly
# when present.
if command -v cargo-nextest &>/dev/null; then
    cargo nextest run --all-features --no-tests=pass "$@"
else
    # cargo test exits 0 when there are no tests anyway.
    cargo test --all-features "$@"
fi
echo "Tests OK"
