diff --git a/clean_files.txt b/clean_files.txt index 242d7327..ad9a364a 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -122,6 +122,7 @@ plugins/available/zoxide.plugin.bash # tests # test/plugins/alias-completion.plugin.bats +test/run test/test_helper.bash test/test_helper_libs.bash diff --git a/test/run b/test/run index 7999d4fb..14d83950 100755 --- a/test/run +++ b/test/run @@ -4,16 +4,15 @@ bats_executable="${test_directory}/../test_lib/bats-core/bin/bats" git submodule init && git submodule update -if [ -z "${BASH_IT}" ]; then - declare BASH_IT - BASH_IT="$(cd "${test_directory}" && dirname "${PWD}")" - export BASH_IT +if [[ -z "${BASH_IT}" ]]; then + BASH_IT="$(cd "${test_directory}" && dirname "${PWD}")" + export BASH_IT fi -if [ -z "$1" ]; then - test_dirs=( "${test_directory}"/{bash_it,completion,install,lib,plugins,themes} ) +if [[ -z "$1" ]]; then + test_dirs=("${test_directory}"/{bash_it,completion,install,lib,plugins,themes}) else - test_dirs=( "$1" ) + test_dirs=("$1") fi # Make sure that the `parallel` command is installed, @@ -21,28 +20,26 @@ fi # If that is the case, try to guess the number of CPU cores, # so we can run `bats` in parallel processing mode, which is a lot faster. if command -v parallel &> /dev/null \ - && parallel -V &> /dev/null \ - && { parallel -V 2> /dev/null | grep -q '^GNU\>'; } -then - # Expect to run at least on a dual-core CPU; slightly degraded performance - # shouldn't matter otherwise. - declare -i -r test_jobs_default=2 - declare -i -r test_jobs_effective="$( - if [ "${TEST_JOBS:-detect}" = "detect" ] \ - && command -v nproc &> /dev/null - then - nproc - elif [ -n "${TEST_JOBS}" ] \ - && [ "${TEST_JOBS}" != "detect" ] - then - echo "${TEST_JOBS}" - else - echo ${test_jobs_default} - fi - )" - exec "$bats_executable" ${CI:+--tap} --jobs ${test_jobs_effective} \ - "${test_dirs[@]}" + && parallel -V &> /dev/null \ + && { parallel -V 2> /dev/null | grep -q '^GNU\>'; }; then + # Expect to run at least on a dual-core CPU; slightly degraded performance + # shouldn't matter otherwise. + declare -i -r test_jobs_default=2 + # shellcheck disable=SC2155 + declare -i -r test_jobs_effective="$( + if [[ "${TEST_JOBS:-detect}" = "detect" ]] \ + && command -v nproc &> /dev/null; then + nproc + elif [[ -n "${TEST_JOBS}" ]] \ + && [[ "${TEST_JOBS}" != "detect" ]]; then + echo "${TEST_JOBS}" + else + echo "${test_jobs_default}" + fi + )" + exec "$bats_executable" "${CI:+--tap}" --jobs "${test_jobs_effective}" \ + "${test_dirs[@]}" else - # Run `bats` in single-threaded mode. - exec "$bats_executable" ${CI:+--tap} "${test_dirs[@]}" + # Run `bats` in single-threaded mode. + exec "$bats_executable" ${CI:+--tap} "${test_dirs[@]}" fi