diff options
author | Naïm Favier <n@monade.li> | 2022-04-27 10:02:49 +0200 |
---|---|---|
committer | Naïm Favier <n@monade.li> | 2022-04-27 16:04:17 +0200 |
commit | 226bc996597407aed9fced101234962a542d6bfd (patch) | |
tree | 66eb659558d367195a58c955e0df286679b47e40 /lib/tests | |
parent | 68322e1297ce606a37622186c85c7b60dd336a1c (diff) | |
download | nixlib-226bc996597407aed9fced101234962a542d6bfd.tar nixlib-226bc996597407aed9fced101234962a542d6bfd.tar.gz nixlib-226bc996597407aed9fced101234962a542d6bfd.tar.bz2 nixlib-226bc996597407aed9fced101234962a542d6bfd.tar.lz nixlib-226bc996597407aed9fced101234962a542d6bfd.tar.xz nixlib-226bc996597407aed9fced101234962a542d6bfd.tar.zst nixlib-226bc996597407aed9fced101234962a542d6bfd.zip |
lib/strings: add toShellVars
A straightforward piece of plumbing to safely inject Nix variables into shell scripts: '' ${lib.toShellVars { inherit foo bar; }} cmd "$foo" --bar "$bar" ''
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/misc.nix | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index fcccf89cc888..c5d1d431677a 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -251,6 +251,26 @@ runTests { expected = ""test" 'test' < & >"; }; + testToShellVars = { + expr = '' + ${toShellVars { + STRing01 = "just a 'string'"; + _array_ = [ "with" "more strings" ]; + assoc."with some" = '' + strings + possibly newlines + ''; + }} + ''; + expected = '' + STRing01='just a '\'''string'\'''' + declare -a _array_=('with' 'more strings') + declare -A assoc=(['with some']='strings + possibly newlines + ') + ''; + }; + # LISTS testFilter = { |