run_tests 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env bash
  2. #
  3. # run_tests
  4. #
  5. export PATH="$PATH:$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
  6. export PATH="$PATH:./buildroot/bin"
  7. # exit on first failure
  8. set -e
  9. exec_test () {
  10. printf "\n\033[0;32m[Test $2] \033[0m$3...\n"
  11. if build_marlin_pio $1 "-e $2"; then
  12. printf "\033[0;32mPassed\033[0m\n"
  13. return 0
  14. else
  15. env_restore
  16. printf "\033[0;31mFailed!\033[0m\n"
  17. return 1
  18. fi
  19. }
  20. export -f exec_test
  21. printf "Running \033[0;32m$2\033[0m Tests\n"
  22. if [[ $3 = "--deep-clean" ]]; then
  23. echo "Deleting all PlatformIO caches, downloads and installed packages..."
  24. env_clean --deep
  25. fi
  26. if [[ $2 = "ALL" ]]; then
  27. dir_list=("$(dirname "${BASH_SOURCE[0]}")"/*)
  28. declare -a tests=(${dir_list[@]/*run_tests/})
  29. for f in "${tests[@]}"; do
  30. env_backup
  31. testenv=$(basename $f | cut -d"-" -f1)
  32. printf "Running \033[0;32m$f\033[0m Tests\n"
  33. exec_test $1 "$testenv --target clean" "Setup Build Environment"
  34. $f $1 $testenv
  35. env_restore
  36. done
  37. else
  38. env_backup
  39. exec_test $1 "$2 --target clean" "Setup Build Environment"
  40. $2-tests $1 $2
  41. env_restore
  42. fi
  43. printf "\033[0;32mAll tests completed successfully\033[0m\n"