run_all.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # This script is intended to be used either by the CI or by a developer that
  3. # wants to check that no unit tests have been broken to ensure there are no
  4. # regressions. At the end, it reports how many tests were successful. However,
  5. # using grep we can easily filter out everything except for those tests that
  6. # time out. e.g. ./run_all.sh | grep -i timeout -B1
  7. set -u -o pipefail
  8. readonly SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
  9. readonly GRAVITY_BIN=$SCRIPT_DIR/../../gravity
  10. files=$(find $SCRIPT_DIR -iname "*.gravity" | grep -v disabled)
  11. tests_total=$(echo "$files" | wc -l)
  12. tests_success=0
  13. tests_fail=0
  14. tests_timeout=0
  15. i=1
  16. for test in $files; do
  17. echo "Testing $i/$tests_total - $test..."
  18. # Set 0.1s by default, but fallback to 10s in case of memory or recursion test
  19. timeout=0.1
  20. if [[ "$test" =~ "mem" || "$test" =~ "recursion" ]]; then
  21. timeout=10
  22. fi
  23. timeout $timeout "$GRAVITY_BIN" "$test"
  24. res=$?
  25. if [[ $res -eq 0 ]]; then
  26. tests_success=$(($tests_success+1))
  27. echo "Success!"
  28. elif [[ $res -eq 124 ]]; then
  29. echo "Timeout!"
  30. tests_timeout=$(($tests_timeout+1))
  31. else
  32. echo "Fail!"
  33. tests_fail=$(($tests_fail+1))
  34. fi
  35. i=$(($i+1))
  36. done
  37. echo "Tests run successfully: $tests_success/$tests_total. $tests_fail failed and $tests_timeout timed out"
  38. if [[ $(($tests_fail+$tests_timeout)) -ne 0 ]]; then
  39. exit 1
  40. fi