run_tests 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 platformio run --project-dir $1 -e $2 --silent; then
  12. printf "\033[0;32mPassed\033[0m\n"
  13. return 0
  14. else
  15. git reset --hard HEAD
  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 [[ $2 = "ALL" ]]; then
  23. dir_list=("$(dirname "${BASH_SOURCE[0]}")"/*)
  24. declare -a tests=(${dir_list[@]/*run_tests/})
  25. for f in "${tests[@]}"; do
  26. testenv=$(basename $f | cut -d"-" -f1)
  27. printf "Running \033[0;32m$f\033[0m Tests\n"
  28. exec_test $1 "$testenv --target clean" "Setup Build Environment"
  29. $f $1 $testenv
  30. git reset --hard HEAD
  31. done
  32. else
  33. exec_test $1 "$2 --target clean" "Setup Build Environment"
  34. $2-tests $1 $2
  35. git reset --hard HEAD
  36. fi
  37. printf "\033[0;32mAll tests completed successfully\033[0m\n"