From eb6469096af8d114e53b17b609ecb63e3eba96db Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 13 Apr 2020 21:53:10 +0200 Subject: [PATCH] Added the parallel test execution code from @rico-chet See here: https://github.com/rico-chet/bash-it/blob/cd4a039215ae1f1495d72f5a1cbff504f5598efe/test/run#L22 --- test/run | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/run b/test/run index da1aa061..cf71259b 100755 --- a/test/run +++ b/test/run @@ -16,4 +16,26 @@ else test_dirs=( "$1" ) fi -exec $bats_executable ${CI:+--tap} "${test_dirs[@]}" +if command -v parallel &> /dev/null +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[@]}" +else + exec "$bats_executable" ${CI:+--tap} "${test_dirs[@]}" +fi