#!/bin/sh
set -eu

repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
package=./...
run=
race=false

while [ "$#" -gt 0 ]; do
  case "$1" in
    --package) package=$2; shift 2 ;;
    --run) run=$2; shift 2 ;;
    --race) race=true; shift ;;
    *) echo "usage: scripts/test-unit [--package PATTERN] [--run REGEXP] [--race]" >&2; exit 2 ;;
  esac
done

set -- go test -shuffle=on
if [ "$race" = true ]; then set -- "$@" -race; fi
if [ -n "$run" ]; then set -- "$@" -run "$run"; fi
set -- "$@" "$package"

cd "$repo_root"
exec docker compose -f deploy/compose.yaml run --rm toolchain "$@"

