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 declare -ar disabledTests 5 declare -a disabledTestPaths 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 function pytestCheckPhase() { 31 echo "Executing pytestCheckPhase" 32 runHook preCheck ··· 34 # Compose arguments 35 args=" -m pytest" 36 if [ -n "$disabledTests" ]; then 37 - disabledTestsString=$(_pytestComputeDisabledTestsString "${disabledTests[@]}") 38 args+=" -k \""$disabledTestsString"\"" 39 fi 40
··· 4 declare -ar disabledTests 5 declare -a disabledTestPaths 6 7 function pytestCheckPhase() { 8 echo "Executing pytestCheckPhase" 9 runHook preCheck ··· 11 # Compose arguments 12 args=" -m pytest" 13 if [ -n "$disabledTests" ]; then 14 + disabledTestsString="not $(concatStringsSep " and not " disabledTests)" 15 args+=" -k \""$disabledTestsString"\"" 16 fi 17
+12 -3
pkgs/stdenv/generic/setup.sh
··· 432 # $ flags=("lorem ipsum" "dolor" "sit amet") 433 # $ concatStringsSep ";" flags 434 # lorem ipsum;dolor;sit amet 435 concatStringsSep() { 436 local sep="$1" 437 local name="$2" ··· 443 echo "concatStringsSep(): ERROR: trying to use concatStringsSep on an associative array." >&2 444 return 1 ;; 445 -a*) 446 - local IFS="$sep" 447 - echo -n "${nameref[*]}" ;; 448 *) 449 - echo -n "${nameref// /"${sep}"}" ;; 450 esac 451 fi 452 } 453
··· 432 # $ flags=("lorem ipsum" "dolor" "sit amet") 433 # $ concatStringsSep ";" flags 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 440 concatStringsSep() { 441 local sep="$1" 442 local name="$2" ··· 448 echo "concatStringsSep(): ERROR: trying to use concatStringsSep on an associative array." >&2 449 return 1 ;; 450 -a*) 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' ;; 454 *) 455 + local IFS=" " ;; 456 + 457 esac 458 + local ifs_separated="${nameref[*]}" 459 + echo -n "${ifs_separated//"$IFS"/"$sep"}" 460 fi 461 } 462
+8
pkgs/test/stdenv/default.nix
··· 161 arrayWithSep="$(concatStringsSep "&" array)" 162 [[ "$arrayWithSep" == "lorem ipsum&dolor&sit amet" ]] || (echo "'\$arrayWithSep' was not 'lorem ipsum&dolor&sit amet'" && false) 163 164 touch $out 165 ''; 166 };
··· 161 arrayWithSep="$(concatStringsSep "&" array)" 162 [[ "$arrayWithSep" == "lorem ipsum&dolor&sit amet" ]] || (echo "'\$arrayWithSep' was not 'lorem ipsum&dolor&sit amet'" && false) 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 + 172 touch $out 173 ''; 174 };