#!/bin/bash

coverage="false"

for i in "$@"; do
  case "$i" in
  --coverage | -c)
    coverage="true"
    shift
    ;;
  *)
    break
    ;;
  esac
done

declare -a CMD
if ${coverage}; then
  CMD=("python3-coverage" "run")
else
  CMD=("python3" "-B")
fi
# Args: discover every tests/*_test.py, matching pytest's collection so the
# two runners stay in sync (a hardcoded list drifts as tests are renamed/added).
CMD+=("-m" "unittest" "discover" "-s" "tests" "-p" "*_test.py")

"${CMD[@]}"

if ${coverage}; then
  python3-coverage report -m
fi
