#!/usr/bin/env bash

exit_codes=()

TESTS=()
for scenario in $(find . -maxdepth 1 -mindepth 1 -type d ! -name script_context); do
  ./run $scenario &
  TESTS+=("$!")
done

for p in ${TESTS[@]}; do
  wait $p
  exit_codes+=("$?")
done

for lang in $(ls script_context); do
  for interaction in $(find script_context/$lang/validators -type f); do
    title=$(basename $interaction)
    title="${title%.*}"
    cd script_context/$lang && ./test.sh $title
    exit_codes+=("$?")
    cd -
  done
done

for code in ${exit_codes[@]}; do
  if [ $code -ne 0 ]; then
    echo "Some test returned non-zero code: $code"
    exit $code
  fi
done
