stdenv: support multi-char separators in concatStringsSep

One prominent use-case for this is pytestCheckHook. This will help
making it work with structuredAttrs in the future.
This commit is contained in:
Wolfgang Walther
2024-11-30 16:38:02 +01:00
parent eba4fcfde2
commit 56b09628e3
3 changed files with 21 additions and 27 deletions
@@ -4,29 +4,6 @@ echo "Sourcing pytest-check-hook"
declare -ar disabledTests
declare -a disabledTestPaths
function _concatSep {
local result
local sep="$1"
local -n arr=$2
for index in ${!arr[*]}; do
if [ $index -eq 0 ]; then
result="${arr[index]}"
else
result+=" $sep ${arr[index]}"
fi
done
echo "$result"
}
function _pytestComputeDisabledTestsString() {
declare -a tests
local tests=($1)
local prefix="not "
prefixed=("${tests[@]/#/$prefix}")
result=$(_concatSep "and" prefixed)
echo "$result"
}
function pytestCheckPhase() {
echo "Executing pytestCheckPhase"
runHook preCheck
@@ -34,7 +11,7 @@ function pytestCheckPhase() {
# Compose arguments
args=" -m pytest"
if [ -n "$disabledTests" ]; then
disabledTestsString=$(_pytestComputeDisabledTestsString "${disabledTests[@]}")
disabledTestsString="not $(concatStringsSep " and not " disabledTests)"
args+=" -k \""$disabledTestsString"\""
fi