#!/bin/bash

set -e

tests=(
  default
  default_bytes
  backtrack
  backtrack_utf8bytes
  backtrack_bytes
  nfa
  nfa_utf8bytes
  nfa_bytes
  regex
)
tmpdir=$(mktemp -d)
coveralls_id=

while true; do
  case "$1" in
    --coveralls-id)
      coveralls_id="$2"
      shift 2
      ;;
    *)
      break
      ;;
  esac
done

cargo test --no-run --verbose --jobs 4
for t in ${tests[@]}; do
  kcov \
    --verify \
    --include-pattern '/regex/src/' \
    "$tmpdir/$t" \
    $(find ./target/debug -executable -wholename "./target/debug/$t-*" | head -n1)
done

if [ -n "$coveralls_id" ]; then
  kcov --verify --coveralls-id=$coveralls_id --merge target/cov "$tmpdir"/*
else
  kcov --verify --merge target/cov "$tmpdir"/*
fi
