My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

run_tests 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env bash
  2. #
  3. # run_tests
  4. #
  5. HERE="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
  6. TESTS="$HERE/../tests"
  7. export PATH="$HERE:$TESTS:$PATH"
  8. # exit on first failure
  9. set -e
  10. exec_test () {
  11. printf "\n\033[0;32m[Test $2] \033[0m$3...\n"
  12. # Check to see if we should skip tests
  13. if [[ -n "$4" ]] ; then
  14. if [[ ! "$3" =~ $4 ]] ; then
  15. printf "\033[1;33mSkipped\033[0m\n"
  16. return 0
  17. fi
  18. fi
  19. if [[ -z "$VERBOSE_PLATFORMIO" ]] ; then
  20. silent="--silent"
  21. else
  22. silent="-v"
  23. fi
  24. if platformio run --project-dir $1 -e $2 $silent; then
  25. printf "\033[0;32mPassed\033[0m\n"
  26. return 0
  27. else
  28. if [[ -n $GIT_RESET_HARD ]]; then
  29. git reset --hard HEAD
  30. else
  31. restore_configs
  32. fi
  33. printf "\033[0;31mFailed!\033[0m\n"
  34. return 1
  35. fi
  36. }
  37. export -f exec_test
  38. printf "Running \033[0;32m$2\033[0m Tests\n"
  39. if [[ $2 = "ALL" ]]; then
  40. tests=("$TESTS"/*)
  41. for f in "${tests[@]}"; do
  42. testenv=$(basename $f)
  43. printf "Running \033[0;32m$f\033[0m Tests\n"
  44. exec_test $1 "$testenv --target clean" "Setup Build Environment"
  45. if [[ $GIT_RESET_HARD == "true" ]]; then
  46. git reset --hard HEAD
  47. else
  48. restore_configs
  49. fi
  50. done
  51. else
  52. exec_test $1 "$2 --target clean" "Setup Build Environment"
  53. test_name="$3"
  54. # If the test name is 1 or 2 digits, treat it as an index
  55. if [[ "$test_name" =~ ^[0-9][0-9]?$ ]] ; then
  56. # Find the test name that corresponds to that index
  57. test_name="$(cat $TESTS/$2 | grep -e '^exec_test' | sed -n "$3p" | sed "s/.*\$1 \$2 \"\([^\"]*\).*/\1/g")"
  58. if [[ -z "$test_name" ]] ; then
  59. # Fail if none matches
  60. printf "\033[0;31mCould not find test \033[0m#$3\033[0;31m in \033[0mbuildroot/tests/$2\n"
  61. exit 1
  62. else
  63. printf "\033[0;32mMatching test \033[0m#$3\033[0;32m: '\033[0m$test_name\033[0;32m'\n"
  64. fi
  65. fi
  66. $TESTS/$2 $1 $2 "$test_name"
  67. if [[ $GIT_RESET_HARD == "true" ]]; then
  68. git reset --hard HEAD
  69. else
  70. restore_configs
  71. fi
  72. fi
  73. printf "\033[0;32mAll tests completed successfully\033[0m\n"