You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.0 KiB
Plaintext
78 lines
2.0 KiB
Plaintext
6 years ago
|
#!/usr/bin/env bash
|
||
6 years ago
|
#
|
||
|
# run_tests
|
||
|
#
|
||
4 years ago
|
HERE="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
|
||
|
TESTS="$HERE/../tests"
|
||
|
export PATH="$HERE:$TESTS:$PATH"
|
||
6 years ago
|
|
||
|
# exit on first failure
|
||
|
set -e
|
||
|
|
||
6 years ago
|
exec_test () {
|
||
6 years ago
|
printf "\n\033[0;32m[Test $2] \033[0m$3...\n"
|
||
4 years ago
|
# Check to see if we should skip tests
|
||
|
if [[ -n "$4" ]] ; then
|
||
|
if [[ ! "$3" =~ $4 ]] ; then
|
||
|
printf "\033[1;33mSkipped\033[0m\n"
|
||
|
return 0
|
||
|
fi
|
||
|
fi
|
||
|
if [[ -z "$VERBOSE_PLATFORMIO" ]] ; then
|
||
|
silent="--silent"
|
||
|
else
|
||
4 years ago
|
silent="-v"
|
||
4 years ago
|
fi
|
||
|
if platformio run --project-dir $1 -e $2 $silent; then
|
||
6 years ago
|
printf "\033[0;32mPassed\033[0m\n"
|
||
|
return 0
|
||
|
else
|
||
4 years ago
|
if [[ -n $GIT_RESET_HARD ]]; then
|
||
|
git reset --hard HEAD
|
||
|
else
|
||
|
restore_configs
|
||
|
fi
|
||
6 years ago
|
printf "\033[0;31mFailed!\033[0m\n"
|
||
|
return 1
|
||
|
fi
|
||
|
}
|
||
|
export -f exec_test
|
||
|
|
||
6 years ago
|
printf "Running \033[0;32m$2\033[0m Tests\n"
|
||
|
|
||
6 years ago
|
if [[ $2 = "ALL" ]]; then
|
||
4 years ago
|
tests=("$TESTS"/*)
|
||
6 years ago
|
for f in "${tests[@]}"; do
|
||
4 years ago
|
testenv=$(basename $f)
|
||
6 years ago
|
printf "Running \033[0;32m$f\033[0m Tests\n"
|
||
|
exec_test $1 "$testenv --target clean" "Setup Build Environment"
|
||
4 years ago
|
if [[ $GIT_RESET_HARD == "true" ]]; then
|
||
|
git reset --hard HEAD
|
||
|
else
|
||
|
restore_configs
|
||
|
fi
|
||
6 years ago
|
done
|
||
|
else
|
||
|
exec_test $1 "$2 --target clean" "Setup Build Environment"
|
||
4 years ago
|
test_name="$3"
|
||
|
# If the test name is 1 or 2 digits, treat it as an index
|
||
|
if [[ "$test_name" =~ ^[0-9][0-9]?$ ]] ; then
|
||
|
# Find the test name that corresponds to that index
|
||
4 years ago
|
test_name="$(cat $TESTS/$2 | grep -e '^exec_test' | sed -n "$3p" | sed "s/.*\$1 \$2 \"\([^\"]*\).*/\1/g")"
|
||
4 years ago
|
if [[ -z "$test_name" ]] ; then
|
||
|
# Fail if none matches
|
||
4 years ago
|
printf "\033[0;31mCould not find test \033[0m#$3\033[0;31m in \033[0mbuildroot/tests/$2\n"
|
||
4 years ago
|
exit 1
|
||
|
else
|
||
|
printf "\033[0;32mMatching test \033[0m#$3\033[0;32m: '\033[0m$test_name\033[0;32m'\n"
|
||
|
fi
|
||
|
fi
|
||
4 years ago
|
$TESTS/$2 $1 $2 "$test_name"
|
||
4 years ago
|
if [[ $GIT_RESET_HARD == "true" ]]; then
|
||
|
git reset --hard HEAD
|
||
|
else
|
||
|
restore_configs
|
||
|
fi
|
||
6 years ago
|
fi
|
||
|
printf "\033[0;32mAll tests completed successfully\033[0m\n"
|