#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
FILES=$(find e2e -name 'test_*' -type f -not -path "*/.rtx/*" | sort)
test_count=0
for f in $FILES; do
  # split tests into two tranches to reduce test time
  if [ -n "${TEST_TRANCHE_COUNT:-}" ]; then
    char_count=${#f}
    if [[ $((char_count % "$TEST_TRANCHE_COUNT")) -ne "$TEST_TRANCHE" ]]; then
      continue
    fi
  fi
  "$ROOT/e2e/run_test" "$f"
  echo
  test_count=$((test_count + 1))
done

echo "e2e: $test_count tests passed"
