diff options
author | Artturin <Artturin@artturin.com> | 2022-12-10 01:09:40 +0200 |
---|---|---|
committer | Artturin <Artturin@artturin.com> | 2022-12-10 04:42:36 +0200 |
commit | 11c3127e38dafdf95ca71a85b1591a29b67e0c09 (patch) | |
tree | dcd6953692543afd53d14e5b640a7c2edcd7889c /pkgs/test/stdenv | |
parent | bf972f18736478dad213ce2c409239af36417787 (diff) | |
download | nixpkgs-11c3127e38dafdf95ca71a85b1591a29b67e0c09.tar nixpkgs-11c3127e38dafdf95ca71a85b1591a29b67e0c09.tar.gz nixpkgs-11c3127e38dafdf95ca71a85b1591a29b67e0c09.tar.bz2 nixpkgs-11c3127e38dafdf95ca71a85b1591a29b67e0c09.tar.lz nixpkgs-11c3127e38dafdf95ca71a85b1591a29b67e0c09.tar.xz nixpkgs-11c3127e38dafdf95ca71a85b1591a29b67e0c09.tar.zst nixpkgs-11c3127e38dafdf95ca71a85b1591a29b67e0c09.zip |
stdenv: detect the type of variable in {prepend,append}ToVar
stdenv: error if using {prepend,append}ToVar on associative array i don't know how to prepend to associative array
Diffstat (limited to 'pkgs/test/stdenv')
-rw-r--r-- | pkgs/test/stdenv/default.nix | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/pkgs/test/stdenv/default.nix b/pkgs/test/stdenv/default.nix index c5af468655f..08e8eed118f 100644 --- a/pkgs/test/stdenv/default.nix +++ b/pkgs/test/stdenv/default.nix @@ -60,10 +60,6 @@ let }; passAsFile = [ "buildCommand" ] ++ lib.optionals (extraAttrs ? extraTest) [ "extraTest" ]; - # FIXME: with structuredAttrs string is converted to a indexed array - # should a/pToVar check if the passed variable is a array or a string? - # declare -x string="testing-string" - # declare -ax string=([0]="world" [1]="testing-string" [2]="hello") buildCommand = '' declare -p string appendToVar string hello @@ -71,8 +67,23 @@ let prependToVar string "world" declare -p string + declare -A associativeArray=(["X"]="Y") + [[ $(appendToVar associativeArray "fail" 2>&1) =~ "trying to use" ]] || (echo "prependToVar did not catch prepending associativeArray" && false) + [[ $(prependToVar associativeArray "fail" 2>&1) =~ "trying to use" ]] || (echo "prependToVar did not catch prepending associativeArray" && false) + [[ $string == "world testing-string hello" ]] || (echo "'\$string' was not 'world testing-string hello'" && false) + # test appending to a unset variable + appendToVar nonExistant created hello + typeset -p nonExistant + if [[ -n $__structuredAttrs ]]; then + [[ "''${nonExistant[@]}" == "created hello" ]] + else + # there's a extra " " in front here and a extra " " in the end of prependToVar + # shouldn't matter because these functions will mostly be used for $*Flags and the Flag variable will in most cases already exit + [[ "$nonExistant" == " created hello" ]] + fi + eval "$extraTest" touch $out |