#!/usr/bin/env bash

# Parse command line arguments.
target=''
quiet=''
getopt=$(getopt --options=wsqh --longoptions=windows,strict,quiet,help -- "$@") || exit
eval set -- "$getopt"
while true; do
    case "$1" in
        -w|--windows)
            target='--target=x86_64-pc-windows-gnu --no-run'
            shift
            ;;
        -s|--strict)
            export RUSTFLAGS='-D warnings'
            shift
            ;;
        -q|--quiet)
            quiet='--quiet'
            shift
            ;;
        -h|--help)
            cat <<EOF
Build Rust test target
Syntax: $(basename "$0") [options]
  -w|--windows ... Build for Windows
  -s|--strict .... Warnings as errors
  -q|--quiet ..... Quiet log messages
  -h|--help ...... Show help text
EOF
            exit 1
            ;;
        --)
            shift
            break
            ;;
        *)
            exit 1
            ;;
    esac
done

# Build Rust test target.
cargo test $target $quiet --release --lib -- --exact "$@" || exit
