#!/bin/sh
# =============================================================================
# freebsd-test.sh — runs INSIDE the FreeBSD VM (vmactions/freebsd-vm `run`).
# =============================================================================
# Role: run cargo fmt / clippy / test natively on FreeBSD for THIS crate.
# audio-clock-bsd is pure Rust, so this also succeeds on a Linux host, but the
# native FreeBSD run catches std/libc divergence early per the CI policy.
#
# Arg:  $1 = ci_type (default|quick|full). `full` additionally builds docs.
# Exit: non-zero on the first failing check (set -e).
# Portability: /bin/sh on FreeBSD (no bashisms).
# =============================================================================
set -eu

ci_type="${1:-default}"

if [ -f "$HOME/.cargo/env" ]; then
  # shellcheck disable=SC1091
  . "$HOME/.cargo/env"
fi

echo "============================================================"
echo "  audio-clock-bsd  (ci_type=$ci_type, $(uname -sr))"
echo "============================================================"

echo "--- cargo fmt --check ---"
cargo fmt --check

echo "--- cargo clippy --all-targets -- -D warnings ---"
cargo clippy --all-targets -- -D warnings

echo "--- cargo test (native FreeBSD) ---"
cargo test

case "$ci_type" in
  full)
    echo "--- cargo doc --no-deps ---"
    cargo doc --no-deps
    ;;
esac

echo "============================================================"
echo "  RESULT: passed (ci_type=$ci_type)"
echo "============================================================"
