Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions pkgs/development/interpreters/python/hooks/pytest-check-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,14 @@ 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

# Compose arguments
args=" -m pytest"
if [ -n "$disabledTests" ]; then
disabledTestsString=$(_pytestComputeDisabledTestsString "${disabledTests[@]}")
disabledTestsString="not $(concatStringsSep " and not " disabledTests)"
args+=" -k \""$disabledTestsString"\""
fi

Expand Down
15 changes: 12 additions & 3 deletions pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ concatTo() {
# $ flags=("lorem ipsum" "dolor" "sit amet")
# $ concatStringsSep ";" flags
# lorem ipsum;dolor;sit amet
#
# Also supports multi-character separators;
# $ flags=("lorem ipsum" "dolor" "sit amet")
# $ concatStringsSep " and " flags
# lorem ipsum and dolor and sit amet
concatStringsSep() {
local sep="$1"
local name="$2"
Expand All @@ -443,11 +448,15 @@ concatStringsSep() {
echo "concatStringsSep(): ERROR: trying to use concatStringsSep on an associative array." >&2
return 1 ;;
-a*)
local IFS="$sep"
echo -n "${nameref[*]}" ;;
# \036 is the "record separator" character. We assume that this will never need to be part of
# an argument string we create here. If anyone ever hits this limitation: Feel free to refactor.
local IFS=$'\036' ;;
*)
echo -n "${nameref// /"${sep}"}" ;;
local IFS=" " ;;

esac
local ifs_separated="${nameref[*]}"
echo -n "${ifs_separated//"$IFS"/"$sep"}"
fi
}

Expand Down
8 changes: 8 additions & 0 deletions pkgs/test/stdenv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ let
arrayWithSep="$(concatStringsSep "&" array)"
[[ "$arrayWithSep" == "lorem ipsum&dolor&sit amet" ]] || (echo "'\$arrayWithSep' was not 'lorem ipsum&dolor&sit amet'" && false)

array=("lorem ipsum" "dolor" "sit amet")
arrayWithSep="$(concatStringsSep "++" array)"
[[ "$arrayWithSep" == "lorem ipsum++dolor++sit amet" ]] || (echo "'\$arrayWithSep' was not 'lorem ipsum++dolor++sit amet'" && false)

array=("lorem ipsum" "dolor" "sit amet")
arrayWithSep="$(concatStringsSep " and " array)"
[[ "$arrayWithSep" == "lorem ipsum and dolor and sit amet" ]] || (echo "'\$arrayWithSep' was not 'lorem ipsum and dolor and sit amet'" && false)

touch $out
'';
};
Expand Down