2023-02-19 04:36:31 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
2023-05-31 01:19:34 -07:00
|
|
|
IFS=$'\n\t'
|
|
|
|
|
2023-09-10 07:34:50 -07:00
|
|
|
print.info() {
|
|
|
|
printf '[INFO] %s\n' "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
print.error() {
|
|
|
|
printf '[ERROR] %s\n' "$1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
repo_dir=$(git rev-parse --show-toplevel)
|
|
|
|
current_dir=$(pwd -P)
|
|
|
|
if [ "$repo_dir" != "$current_dir" ]; then
|
|
|
|
print.error "This scripts requires execution from the repository root directory."
|
|
|
|
printf "\t%s\t%s\n" "Repo root dir:" "$repo_dir"
|
|
|
|
printf "\t%s\t%s\n\n" "Current dir:" "$current_dir"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2023-02-19 04:36:31 -07:00
|
|
|
|
2023-09-10 07:34:50 -07:00
|
|
|
test_directory="./test"
|
2023-02-19 04:36:31 -07:00
|
|
|
bats_options=(--timing --print-output-on-failure)
|
|
|
|
|
|
|
|
if command -v parallel >/dev/null; then
|
2023-09-10 07:34:50 -07:00
|
|
|
# Enable parallel jobs
|
|
|
|
bats_options+=(--jobs 2 --no-parallelize-within-files)
|
2023-02-19 04:36:31 -07:00
|
|
|
elif [[ -n "${CI-}" ]]; then
|
2023-09-10 07:34:50 -07:00
|
|
|
print.error "GNU parallel should be installed in the CI environment. Please install and rerun the test suite."
|
2023-02-19 04:36:31 -07:00
|
|
|
exit 1
|
|
|
|
else
|
2023-09-10 07:34:50 -07:00
|
|
|
print.info "For faster test execution, install GNU parallel."
|
2023-02-19 04:36:31 -07:00
|
|
|
fi
|
|
|
|
|
2023-09-10 07:34:50 -07:00
|
|
|
print.info "Running Bats in directory '${test_directory}' with options:" "${bats_options[@]}"
|
2023-02-19 04:36:31 -07:00
|
|
|
bats "${bats_options[@]}" "${test_directory}"
|