stdenv: support multi-char separators in concatStringsSep (#360466)

authored by philiptaron.tngl.sh and committed by GitHub 815e9265 aa14d2c5

+21 -27
+1 -24
pkgs/development/interpreters/python/hooks/pytest-check-hook.sh
··· 4 4 declare -ar disabledTests 5 5 declare -a disabledTestPaths 6 6 7 - function _concatSep { 8 - local result 9 - local sep="$1" 10 - local -n arr=$2 11 - for index in ${!arr[*]}; do 12 - if [ $index -eq 0 ]; then 13 - result="${arr[index]}" 14 - else 15 - result+=" $sep ${arr[index]}" 16 - fi 17 - done 18 - echo "$result" 19 - } 20 - 21 - function _pytestComputeDisabledTestsString() { 22 - declare -a tests 23 - local tests=($1) 24 - local prefix="not " 25 - prefixed=("${tests[@]/#/$prefix}") 26 - result=$(_concatSep "and" prefixed) 27 - echo "$result" 28 - } 29 - 30 7 function pytestCheckPhase() { 31 8 echo "Executing pytestCheckPhase" 32 9 runHook preCheck ··· 34 11 # Compose arguments 35 12 args=" -m pytest" 36 13 if [ -n "$disabledTests" ]; then 37 - disabledTestsString=$(_pytestComputeDisabledTestsString "${disabledTests[@]}") 14 + disabledTestsString="not $(concatStringsSep " and not " disabledTests)" 38 15 args+=" -k \""$disabledTestsString"\"" 39 16 fi 40 17
+12 -3
pkgs/stdenv/generic/setup.sh
··· 432 432 # $ flags=("lorem ipsum" "dolor" "sit amet") 433 433 # $ concatStringsSep ";" flags 434 434 # lorem ipsum;dolor;sit amet 435 + # 436 + # Also supports multi-character separators; 437 + # $ flags=("lorem ipsum" "dolor" "sit amet") 438 + # $ concatStringsSep " and " flags 439 + # lorem ipsum and dolor and sit amet 435 440 concatStringsSep() { 436 441 local sep="$1" 437 442 local name="$2" ··· 443 448 echo "concatStringsSep(): ERROR: trying to use concatStringsSep on an associative array." >&2 444 449 return 1 ;; 445 450 -a*) 446 - local IFS="$sep" 447 - echo -n "${nameref[*]}" ;; 451 + # \036 is the "record separator" character. We assume that this will never need to be part of 452 + # an argument string we create here. If anyone ever hits this limitation: Feel free to refactor. 453 + local IFS=$'\036' ;; 448 454 *) 449 - echo -n "${nameref// /"${sep}"}" ;; 455 + local IFS=" " ;; 456 + 450 457 esac 458 + local ifs_separated="${nameref[*]}" 459 + echo -n "${ifs_separated//"$IFS"/"$sep"}" 451 460 fi 452 461 } 453 462
+8
pkgs/test/stdenv/default.nix
··· 161 161 arrayWithSep="$(concatStringsSep "&" array)" 162 162 [[ "$arrayWithSep" == "lorem ipsum&dolor&sit amet" ]] || (echo "'\$arrayWithSep' was not 'lorem ipsum&dolor&sit amet'" && false) 163 163 164 + array=("lorem ipsum" "dolor" "sit amet") 165 + arrayWithSep="$(concatStringsSep "++" array)" 166 + [[ "$arrayWithSep" == "lorem ipsum++dolor++sit amet" ]] || (echo "'\$arrayWithSep' was not 'lorem ipsum++dolor++sit amet'" && false) 167 + 168 + array=("lorem ipsum" "dolor" "sit amet") 169 + arrayWithSep="$(concatStringsSep " and " array)" 170 + [[ "$arrayWithSep" == "lorem ipsum and dolor and sit amet" ]] || (echo "'\$arrayWithSep' was not 'lorem ipsum and dolor and sit amet'" && false) 171 + 164 172 touch $out 165 173 ''; 166 174 };