run-tests.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. if [ "$(uname)" = "SerenityOS" ]; then
  3. js_program=/bin/js
  4. else
  5. [ -z "$js_program" ] && js_program="$SERENITY_ROOT/Build/Meta/Lagom/js"
  6. # Enable back traces if sanitizers are enabled
  7. export UBSAN_OPTIONS=print_stacktrace=1
  8. fi
  9. pass_count=0
  10. fail_count=0
  11. count=0
  12. test_count=0
  13. GLOBIGNORE=test-common.js
  14. # FIXME: Support "find -name" in Serenity to remove the file name checks below
  15. test_files=$(find . -type f | cut -b 3- | sort)
  16. for f in $test_files; do
  17. if [ "$f" = "test-common.js" ] || [ "$f" = "run-tests.sh" ]; then
  18. continue
  19. fi
  20. (( ++test_count ))
  21. done
  22. for f in $test_files; do
  23. if [ "$f" = "test-common.js" ] || [ "$f" = "run-tests.sh" ]; then
  24. continue
  25. fi
  26. result="$("$js_program" "$@" -t "$f" 2>/dev/null)"
  27. if [ "$result" = "PASS" ]; then
  28. (( ++pass_count ))
  29. echo -ne " ✅ "
  30. else
  31. echo -ne " ❌ "
  32. (( ++fail_count ))
  33. fi
  34. echo -ne "\033]9;${count};${test_count}\033\\"
  35. echo "$f"
  36. if [ "$result" != "PASS" ]; then
  37. if [ -z "$result" ]; then
  38. echo -e " \033[31;1mNo output. Did you forget 'console.log(\"PASS\");'?\033[0m"
  39. else
  40. readarray -t split_result <<< "$result";
  41. echo -e " \033[31;1mOutput:\033[0m "
  42. for (( i = 0; i < ${#split_result[@]}; i++ )); do
  43. echo " ${split_result[i]}"
  44. done
  45. fi
  46. fi
  47. (( ++count ))
  48. done
  49. echo -e "\033]9;-1\033\\"
  50. pass_color=""
  51. fail_color=""
  52. color_off="\033[0m"
  53. exit_code=0
  54. if (( pass_count > 0 )); then
  55. pass_color="\033[32;1m"
  56. fi
  57. if (( fail_count > 0 )); then
  58. fail_color="\033[31;1m"
  59. exit_code=1
  60. fi
  61. echo
  62. echo -e "Ran $count tests. Passed: ${pass_color}${pass_count}${color_off}, Failed: ${fail_color}${fail_count}${color_off}"
  63. exit $exit_code