2022-12-07 03:55:45 +00:00
|
|
|
# To run these tests:
|
|
|
|
# nix-build -A tests.stdenv
|
|
|
|
|
|
|
|
{ stdenv
|
|
|
|
, pkgs
|
|
|
|
, lib
|
2023-01-15 19:54:48 +00:00
|
|
|
, testers
|
2022-12-07 03:55:45 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2022-12-11 10:57:16 +00:00
|
|
|
# early enough not to rebuild gcc but late enough to have patchelf
|
|
|
|
earlyPkgs = stdenv.__bootPackages.stdenv.__bootPackages;
|
2023-03-02 12:40:45 +00:00
|
|
|
earlierPkgs = stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages;
|
2022-12-07 03:55:45 +00:00
|
|
|
# use a early stdenv so when hacking on stdenv this test can be run quickly
|
|
|
|
bootStdenv = stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv;
|
|
|
|
pkgsStructured = import pkgs.path { config = { structuredAttrsByDefault = true; }; inherit (stdenv.hostPlatform) system; };
|
|
|
|
bootStdenvStructuredAttrsByDefault = pkgsStructured.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv;
|
|
|
|
|
2023-03-02 12:40:45 +00:00
|
|
|
runCommand = earlierPkgs.runCommand;
|
|
|
|
|
2022-12-07 03:55:45 +00:00
|
|
|
|
2022-12-09 18:07:12 +00:00
|
|
|
ccWrapperSubstitutionsTest = { name, stdenv', extraAttrs ? { } }:
|
2022-12-07 03:55:45 +00:00
|
|
|
|
2022-12-09 18:07:12 +00:00
|
|
|
stdenv'.cc.overrideAttrs (previousAttrs: ({
|
|
|
|
inherit name;
|
2022-12-07 03:55:45 +00:00
|
|
|
|
|
|
|
postFixup = previousAttrs.postFixup + ''
|
|
|
|
declare -p wrapperName
|
|
|
|
echo "env.wrapperName = $wrapperName"
|
2022-12-09 20:22:31 +00:00
|
|
|
[[ $wrapperName == "CC_WRAPPER" ]] || (echo "'\$wrapperName' was not 'CC_WRAPPER'" && false)
|
2022-12-07 03:55:45 +00:00
|
|
|
declare -p suffixSalt
|
|
|
|
echo "env.suffixSalt = $suffixSalt"
|
2022-12-09 20:22:31 +00:00
|
|
|
[[ $suffixSalt == "${stdenv'.cc.suffixSalt}" ]] || (echo "'\$suffxSalt' was not '${stdenv'.cc.suffixSalt}'" && false)
|
2022-12-07 03:55:45 +00:00
|
|
|
|
|
|
|
grep -q "@out@" $out/bin/cc || echo "@out@ in $out/bin/cc was substituted"
|
|
|
|
grep -q "@suffixSalt@" $out/bin/cc && (echo "$out/bin/cc contains unsubstituted variables" && false)
|
|
|
|
|
|
|
|
touch $out
|
|
|
|
'';
|
2022-12-09 18:07:12 +00:00
|
|
|
} // extraAttrs));
|
|
|
|
|
|
|
|
testEnvAttrset = { name, stdenv', extraAttrs ? { } }:
|
|
|
|
stdenv'.mkDerivation
|
|
|
|
({
|
|
|
|
inherit name;
|
|
|
|
env = {
|
|
|
|
string = "testing-string";
|
|
|
|
};
|
|
|
|
|
|
|
|
passAsFile = [ "buildCommand" ];
|
|
|
|
buildCommand = ''
|
|
|
|
declare -p string
|
|
|
|
echo "env.string = $string"
|
2022-12-09 20:22:31 +00:00
|
|
|
[[ $string == "testing-string" ]] || (echo "'\$string' was not 'testing-string'" && false)
|
2022-12-15 05:16:18 +00:00
|
|
|
[[ "$(declare -p string)" == 'declare -x string="testing-string"' ]] || (echo "'\$string' was not exported" && false)
|
2022-12-09 20:22:31 +00:00
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
} // extraAttrs);
|
|
|
|
|
|
|
|
testPrependAndAppendToVar = { name, stdenv', extraAttrs ? { } }:
|
|
|
|
stdenv'.mkDerivation
|
|
|
|
({
|
|
|
|
inherit name;
|
|
|
|
env = {
|
|
|
|
string = "testing-string";
|
|
|
|
};
|
|
|
|
|
|
|
|
passAsFile = [ "buildCommand" ] ++ lib.optionals (extraAttrs ? extraTest) [ "extraTest" ];
|
|
|
|
buildCommand = ''
|
|
|
|
declare -p string
|
|
|
|
appendToVar string hello
|
|
|
|
# test that quoted strings work
|
|
|
|
prependToVar string "world"
|
|
|
|
declare -p string
|
|
|
|
|
2022-12-09 23:09:40 +00:00
|
|
|
declare -A associativeArray=(["X"]="Y")
|
2024-08-02 19:52:55 +00:00
|
|
|
[[ $(appendToVar associativeArray "fail" 2>&1) =~ "trying to use" ]] || (echo "appendToVar did not throw appending to associativeArray" && false)
|
|
|
|
[[ $(prependToVar associativeArray "fail" 2>&1) =~ "trying to use" ]] || (echo "prependToVar did not throw prepending associativeArray" && false)
|
2022-12-09 23:09:40 +00:00
|
|
|
|
2022-12-09 20:22:31 +00:00
|
|
|
[[ $string == "world testing-string hello" ]] || (echo "'\$string' was not 'world testing-string hello'" && false)
|
|
|
|
|
2022-12-09 23:09:40 +00:00
|
|
|
# test appending to a unset variable
|
|
|
|
appendToVar nonExistant created hello
|
2024-08-02 19:52:55 +00:00
|
|
|
declare -p nonExistant
|
2022-12-09 23:09:40 +00:00
|
|
|
if [[ -n $__structuredAttrs ]]; then
|
|
|
|
[[ "''${nonExistant[@]}" == "created hello" ]]
|
|
|
|
else
|
|
|
|
# there's a extra " " in front here and a extra " " in the end of prependToVar
|
2024-08-02 19:52:55 +00:00
|
|
|
# shouldn't matter because these functions will mostly be used for $*Flags and the Flag variable will in most cases already exist
|
2022-12-09 23:09:40 +00:00
|
|
|
[[ "$nonExistant" == " created hello" ]]
|
|
|
|
fi
|
|
|
|
|
2022-12-09 20:22:31 +00:00
|
|
|
eval "$extraTest"
|
|
|
|
|
2022-12-09 18:07:12 +00:00
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
} // extraAttrs);
|
|
|
|
|
2024-06-09 10:24:21 +00:00
|
|
|
testConcatTo = { name, stdenv', extraAttrs ? { } }:
|
|
|
|
stdenv'.mkDerivation
|
|
|
|
({
|
|
|
|
inherit name;
|
|
|
|
|
2024-08-24 21:26:56 +00:00
|
|
|
string = "a *";
|
2024-06-09 10:24:21 +00:00
|
|
|
list = ["c" "d"];
|
|
|
|
|
|
|
|
passAsFile = [ "buildCommand" ] ++ lib.optionals (extraAttrs ? extraTest) [ "extraTest" ];
|
|
|
|
buildCommand = ''
|
|
|
|
declare -A associativeArray=(["X"]="Y")
|
|
|
|
[[ $(concatTo nowhere associativeArray 2>&1) =~ "trying to use" ]] || (echo "concatTo did not throw concatenating associativeArray" && false)
|
|
|
|
|
2024-08-23 19:34:11 +00:00
|
|
|
empty_array=()
|
|
|
|
empty_string=""
|
|
|
|
|
2024-06-09 10:24:21 +00:00
|
|
|
declare -a flagsArray
|
2024-08-23 19:34:11 +00:00
|
|
|
concatTo flagsArray string list notset=e=f empty_array=g empty_string=h
|
2024-06-09 10:24:21 +00:00
|
|
|
declare -p flagsArray
|
|
|
|
[[ "''${flagsArray[0]}" == "a" ]] || (echo "'\$flagsArray[0]' was not 'a'" && false)
|
2024-08-24 21:26:56 +00:00
|
|
|
[[ "''${flagsArray[1]}" == "*" ]] || (echo "'\$flagsArray[1]' was not '*'" && false)
|
2024-06-09 10:24:21 +00:00
|
|
|
[[ "''${flagsArray[2]}" == "c" ]] || (echo "'\$flagsArray[2]' was not 'c'" && false)
|
|
|
|
[[ "''${flagsArray[3]}" == "d" ]] || (echo "'\$flagsArray[3]' was not 'd'" && false)
|
2024-08-23 19:34:11 +00:00
|
|
|
[[ "''${flagsArray[4]}" == "e=f" ]] || (echo "'\$flagsArray[4]' was not 'e=f'" && false)
|
|
|
|
[[ "''${flagsArray[5]}" == "g" ]] || (echo "'\$flagsArray[5]' was not 'g'" && false)
|
|
|
|
[[ "''${flagsArray[6]}" == "h" ]] || (echo "'\$flagsArray[6]' was not 'h'" && false)
|
2024-06-09 10:24:21 +00:00
|
|
|
|
|
|
|
# test concatenating to unset variable
|
2024-08-23 19:34:11 +00:00
|
|
|
concatTo nonExistant string list notset=e=f empty_array=g empty_string=h
|
2024-06-09 10:24:21 +00:00
|
|
|
declare -p nonExistant
|
|
|
|
[[ "''${nonExistant[0]}" == "a" ]] || (echo "'\$nonExistant[0]' was not 'a'" && false)
|
2024-08-24 21:26:56 +00:00
|
|
|
[[ "''${nonExistant[1]}" == "*" ]] || (echo "'\$nonExistant[1]' was not '*'" && false)
|
2024-06-09 10:24:21 +00:00
|
|
|
[[ "''${nonExistant[2]}" == "c" ]] || (echo "'\$nonExistant[2]' was not 'c'" && false)
|
|
|
|
[[ "''${nonExistant[3]}" == "d" ]] || (echo "'\$nonExistant[3]' was not 'd'" && false)
|
2024-08-23 19:34:11 +00:00
|
|
|
[[ "''${nonExistant[4]}" == "e=f" ]] || (echo "'\$nonExistant[4]' was not 'e=f'" && false)
|
|
|
|
[[ "''${nonExistant[5]}" == "g" ]] || (echo "'\$nonExistant[5]' was not 'g'" && false)
|
|
|
|
[[ "''${nonExistant[6]}" == "h" ]] || (echo "'\$nonExistant[6]' was not 'h'" && false)
|
2024-06-09 10:24:21 +00:00
|
|
|
|
|
|
|
eval "$extraTest"
|
|
|
|
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
} // extraAttrs);
|
|
|
|
|
2024-06-12 19:14:27 +00:00
|
|
|
testConcatStringsSep = { name, stdenv' }:
|
|
|
|
stdenv'.mkDerivation
|
|
|
|
{
|
|
|
|
inherit name;
|
|
|
|
|
2024-08-11 14:42:42 +00:00
|
|
|
# NOTE: Testing with "&" as separator is intentional, because unquoted
|
|
|
|
# "&" has a special meaning in the "${var//pattern/replacement}" syntax.
|
|
|
|
# Cf. https://github.com/NixOS/nixpkgs/pull/318614#discussion_r1706191919
|
2024-06-12 19:14:27 +00:00
|
|
|
passAsFile = [ "buildCommand" ];
|
|
|
|
buildCommand = ''
|
|
|
|
declare -A associativeArray=(["X"]="Y")
|
|
|
|
[[ $(concatStringsSep ";" associativeArray 2>&1) =~ "trying to use" ]] || (echo "concatStringsSep did not throw concatenating associativeArray" && false)
|
|
|
|
|
|
|
|
string="lorem ipsum dolor sit amet"
|
2024-08-11 14:42:42 +00:00
|
|
|
stringWithSep="$(concatStringsSep "&" string)"
|
|
|
|
[[ "$stringWithSep" == "lorem&ipsum&dolor&sit&amet" ]] || (echo "'\$stringWithSep' was not 'lorem&ipsum&dolor&sit&amet'" && false)
|
2024-06-12 19:14:27 +00:00
|
|
|
|
|
|
|
array=("lorem ipsum" "dolor" "sit amet")
|
2024-08-11 14:42:42 +00:00
|
|
|
arrayWithSep="$(concatStringsSep "&" array)"
|
|
|
|
[[ "$arrayWithSep" == "lorem ipsum&dolor&sit amet" ]] || (echo "'\$arrayWithSep' was not 'lorem ipsum&dolor&sit amet'" && false)
|
2024-06-12 19:14:27 +00:00
|
|
|
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
};
|
2022-12-09 18:07:12 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2024-06-13 17:38:40 +00:00
|
|
|
# Disable on Darwin due to assumptions with __bootPackages
|
|
|
|
__attrsFailEvaluation = stdenv.hostPlatform.isDarwin;
|
|
|
|
|
2022-12-11 11:31:50 +00:00
|
|
|
# tests for hooks in `stdenv.defaultNativeBuildInputs`
|
2023-01-17 02:20:36 +00:00
|
|
|
hooks = lib.recurseIntoAttrs (import ./hooks.nix { stdenv = bootStdenv; pkgs = earlyPkgs; inherit lib; });
|
2022-12-11 11:31:50 +00:00
|
|
|
|
2023-01-15 19:54:48 +00:00
|
|
|
outputs-no-out = runCommand "outputs-no-out-assert" {
|
2023-03-02 12:40:45 +00:00
|
|
|
result = earlierPkgs.testers.testBuildFailure (bootStdenv.mkDerivation {
|
2023-01-15 19:54:48 +00:00
|
|
|
NIX_DEBUG = 1;
|
|
|
|
name = "outputs-no-out";
|
|
|
|
outputs = ["foo"];
|
|
|
|
buildPhase = ":";
|
|
|
|
installPhase = ''
|
|
|
|
touch $foo
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
|
|
|
# Assumption: the first output* variable to be configured is
|
|
|
|
# _overrideFirst outputDev "dev" "out"
|
2023-03-02 12:42:16 +00:00
|
|
|
expectedMsg = "error: _assignFirst: could not find a non-empty variable whose name to assign to outputDev.\n The following variables were all unset or empty:\n dev out";
|
2023-01-15 19:54:48 +00:00
|
|
|
} ''
|
|
|
|
grep -F "$expectedMsg" $result/testBuildFailure.log >/dev/null
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
|
2022-12-09 18:07:12 +00:00
|
|
|
test-env-attrset = testEnvAttrset { name = "test-env-attrset"; stdenv' = bootStdenv; };
|
|
|
|
|
2022-12-13 17:12:04 +00:00
|
|
|
# Test compatibility with derivations using `env` as a regular variable.
|
|
|
|
test-env-derivation = bootStdenv.mkDerivation rec {
|
|
|
|
name = "test-env-derivation";
|
|
|
|
env = bootStdenv.mkDerivation {
|
|
|
|
name = "foo";
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir "$out"
|
|
|
|
touch "$out/bar"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
passAsFile = [ "buildCommand" ];
|
|
|
|
buildCommand = ''
|
|
|
|
declare -p env
|
|
|
|
[[ $env == "${env}" ]]
|
|
|
|
touch "$out"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-09-14 17:30:52 +00:00
|
|
|
# Check that mkDerivation rejects MD5 hashes
|
|
|
|
rejectedHashes = lib.recurseIntoAttrs {
|
|
|
|
md5 =
|
|
|
|
let drv = runCommand "md5 outputHash rejected" {
|
|
|
|
outputHash = "md5-fPt7dxVVP7ffY3MxkQdwVw==";
|
|
|
|
} "true";
|
|
|
|
in assert !(builtins.tryEval drv).success; {};
|
|
|
|
};
|
|
|
|
|
2023-05-09 14:01:03 +00:00
|
|
|
test-inputDerivation = let
|
|
|
|
inherit (stdenv.mkDerivation {
|
|
|
|
dep1 = derivation { name = "dep1"; builder = "/bin/sh"; args = [ "-c" ": > $out" ]; system = builtins.currentSystem; };
|
|
|
|
dep2 = derivation { name = "dep2"; builder = "/bin/sh"; args = [ "-c" ": > $out" ]; system = builtins.currentSystem; };
|
|
|
|
passAsFile = [ "dep2" ];
|
|
|
|
}) inputDerivation;
|
|
|
|
in
|
|
|
|
runCommand "test-inputDerivation" {
|
|
|
|
exportReferencesGraph = [ "graph" inputDerivation ];
|
|
|
|
} ''
|
|
|
|
grep ${inputDerivation.dep1} graph
|
|
|
|
grep ${inputDerivation.dep2} graph
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
|
2024-04-15 07:50:38 +00:00
|
|
|
test-inputDerivation-fixed-output = let
|
|
|
|
inherit (stdenv.mkDerivation {
|
|
|
|
dep1 = derivation { name = "dep1"; builder = "/bin/sh"; args = [ "-c" ": > $out" ]; system = builtins.currentSystem; };
|
|
|
|
dep2 = derivation { name = "dep2"; builder = "/bin/sh"; args = [ "-c" ": > $out" ]; system = builtins.currentSystem; };
|
|
|
|
name = "meow";
|
|
|
|
outputHash = "sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=";
|
|
|
|
outputHashMode = "flat";
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
buildCommand = ''
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
passAsFile = [ "dep2" ];
|
|
|
|
}) inputDerivation;
|
|
|
|
in
|
|
|
|
runCommand "test-inputDerivation" {
|
|
|
|
exportReferencesGraph = [ "graph" inputDerivation ];
|
|
|
|
} ''
|
|
|
|
grep ${inputDerivation.dep1} graph
|
|
|
|
grep ${inputDerivation.dep2} graph
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
|
2022-12-09 20:22:31 +00:00
|
|
|
test-prepend-append-to-var = testPrependAndAppendToVar {
|
|
|
|
name = "test-prepend-append-to-var";
|
|
|
|
stdenv' = bootStdenv;
|
|
|
|
};
|
2022-12-09 18:07:12 +00:00
|
|
|
|
2024-06-09 10:24:21 +00:00
|
|
|
test-concat-to = testConcatTo {
|
|
|
|
name = "test-concat-to";
|
|
|
|
stdenv' = bootStdenv;
|
|
|
|
};
|
|
|
|
|
2024-06-12 19:14:27 +00:00
|
|
|
test-concat-strings-sep = testConcatStringsSep {
|
|
|
|
name = "test-concat-strings-sep";
|
|
|
|
stdenv' = bootStdenv;
|
|
|
|
};
|
|
|
|
|
2022-12-09 20:22:31 +00:00
|
|
|
test-structured-env-attrset = testEnvAttrset {
|
|
|
|
name = "test-structured-env-attrset";
|
|
|
|
stdenv' = bootStdenv;
|
|
|
|
extraAttrs = { __structuredAttrs = true; };
|
|
|
|
};
|
2022-12-09 18:07:12 +00:00
|
|
|
|
2022-12-09 20:22:31 +00:00
|
|
|
test-cc-wrapper-substitutions = ccWrapperSubstitutionsTest {
|
|
|
|
name = "test-cc-wrapper-substitutions";
|
|
|
|
stdenv' = bootStdenv;
|
|
|
|
};
|
2022-12-09 18:07:12 +00:00
|
|
|
|
2022-12-09 20:22:31 +00:00
|
|
|
structuredAttrsByDefault = lib.recurseIntoAttrs {
|
2022-12-11 11:31:50 +00:00
|
|
|
|
2023-01-17 02:20:36 +00:00
|
|
|
hooks = lib.recurseIntoAttrs (import ./hooks.nix { stdenv = bootStdenvStructuredAttrsByDefault; pkgs = earlyPkgs; inherit lib; });
|
2022-12-11 11:31:50 +00:00
|
|
|
|
2022-12-09 20:22:31 +00:00
|
|
|
test-cc-wrapper-substitutions = ccWrapperSubstitutionsTest {
|
|
|
|
name = "test-cc-wrapper-substitutions-structuredAttrsByDefault";
|
|
|
|
stdenv' = bootStdenvStructuredAttrsByDefault;
|
|
|
|
};
|
|
|
|
|
|
|
|
test-structured-env-attrset = testEnvAttrset {
|
|
|
|
name = "test-structured-env-attrset-structuredAttrsByDefault";
|
|
|
|
stdenv' = bootStdenvStructuredAttrsByDefault;
|
|
|
|
};
|
|
|
|
|
|
|
|
test-prepend-append-to-var = testPrependAndAppendToVar {
|
|
|
|
name = "test-prepend-append-to-var-structuredAttrsByDefault";
|
|
|
|
stdenv' = bootStdenvStructuredAttrsByDefault;
|
|
|
|
extraAttrs = {
|
|
|
|
# will be a bash indexed array in attrs.sh
|
|
|
|
# declare -a list=('a' 'b' )
|
|
|
|
# and a json array in attrs.json
|
|
|
|
# "list":["a","b"]
|
|
|
|
list = [ "a" "b" ];
|
|
|
|
# will be a bash associative array(dictionary) in attrs.sh
|
|
|
|
# declare -A array=(['a']='1' ['b']='2' )
|
|
|
|
# and a json object in attrs.json
|
|
|
|
# {"array":{"a":"1","b":"2"}
|
|
|
|
array = { a = "1"; b = "2"; };
|
|
|
|
extraTest = ''
|
|
|
|
declare -p array
|
|
|
|
array+=(["c"]="3")
|
|
|
|
declare -p array
|
|
|
|
|
|
|
|
[[ "''${array[c]}" == "3" ]] || (echo "c element of '\$array' was not '3'" && false)
|
|
|
|
|
|
|
|
declare -p list
|
|
|
|
prependToVar list hello
|
|
|
|
# test that quoted strings work
|
|
|
|
appendToVar list "world"
|
|
|
|
declare -p list
|
|
|
|
|
|
|
|
[[ "''${list[0]}" == "hello" ]] || (echo "first element of '\$list' was not 'hello'" && false)
|
|
|
|
[[ "''${list[1]}" == "a" ]] || (echo "first element of '\$list' was not 'a'" && false)
|
|
|
|
[[ "''${list[-1]}" == "world" ]] || (echo "last element of '\$list' was not 'world'" && false)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2022-12-11 10:57:16 +00:00
|
|
|
|
2024-06-09 10:24:21 +00:00
|
|
|
test-concat-to = testConcatTo {
|
|
|
|
name = "test-concat-to-structuredAttrsByDefault";
|
|
|
|
stdenv' = bootStdenvStructuredAttrsByDefault;
|
|
|
|
extraAttrs = {
|
|
|
|
# test that whitespace is kept in the bash array for structuredAttrs
|
|
|
|
listWithSpaces = [ "c c" "d d" ];
|
|
|
|
extraTest = ''
|
|
|
|
declare -a flagsWithSpaces
|
|
|
|
concatTo flagsWithSpaces string listWithSpaces
|
|
|
|
declare -p flagsWithSpaces
|
|
|
|
[[ "''${flagsWithSpaces[0]}" == "a" ]] || (echo "'\$flagsWithSpaces[0]' was not 'a'" && false)
|
2024-08-24 21:26:56 +00:00
|
|
|
[[ "''${flagsWithSpaces[1]}" == "*" ]] || (echo "'\$flagsWithSpaces[1]' was not '*'" && false)
|
2024-06-09 10:24:21 +00:00
|
|
|
[[ "''${flagsWithSpaces[2]}" == "c c" ]] || (echo "'\$flagsWithSpaces[2]' was not 'c c'" && false)
|
|
|
|
[[ "''${flagsWithSpaces[3]}" == "d d" ]] || (echo "'\$flagsWithSpaces[3]' was not 'd d'" && false)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-06-12 19:14:27 +00:00
|
|
|
test-concat-strings-sep = testConcatStringsSep {
|
|
|
|
name = "test-concat-strings-sep-structuredAttrsByDefault";
|
|
|
|
stdenv' = bootStdenvStructuredAttrsByDefault;
|
|
|
|
};
|
|
|
|
|
2022-12-11 10:57:16 +00:00
|
|
|
test-golden-example-structuredAttrs =
|
|
|
|
let
|
|
|
|
goldenSh = earlyPkgs.writeText "goldenSh" ''
|
|
|
|
declare -A EXAMPLE_ATTRS=(['foo']='bar' )
|
|
|
|
declare EXAMPLE_BOOL_FALSE=
|
|
|
|
declare EXAMPLE_BOOL_TRUE=1
|
|
|
|
declare EXAMPLE_INT=123
|
|
|
|
declare EXAMPLE_INT_NEG=-123
|
|
|
|
declare -a EXAMPLE_LIST=('foo' 'bar' )
|
|
|
|
declare EXAMPLE_STR='foo bar'
|
|
|
|
'';
|
|
|
|
goldenJson = earlyPkgs.writeText "goldenSh" ''
|
|
|
|
{
|
|
|
|
"EXAMPLE_ATTRS": {
|
|
|
|
"foo": "bar"
|
|
|
|
},
|
|
|
|
"EXAMPLE_BOOL_FALSE": false,
|
|
|
|
"EXAMPLE_BOOL_TRUE": true,
|
|
|
|
"EXAMPLE_INT": 123,
|
|
|
|
"EXAMPLE_INT_NEG": -123,
|
|
|
|
"EXAMPLE_LIST": [
|
|
|
|
"foo",
|
|
|
|
"bar"
|
|
|
|
],
|
|
|
|
"EXAMPLE_NESTED_ATTRS": {
|
|
|
|
"foo": {
|
|
|
|
"bar": "baz"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"EXAMPLE_NESTED_LIST": [
|
|
|
|
[
|
|
|
|
"foo",
|
|
|
|
"bar"
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"baz"
|
|
|
|
]
|
|
|
|
],
|
|
|
|
"EXAMPLE_STR": "foo bar"
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
bootStdenvStructuredAttrsByDefault.mkDerivation {
|
|
|
|
name = "test-golden-example-structuredAttrsByDefault";
|
|
|
|
nativeBuildInputs = [ earlyPkgs.jq ];
|
|
|
|
|
|
|
|
EXAMPLE_BOOL_TRUE = true;
|
|
|
|
EXAMPLE_BOOL_FALSE = false;
|
|
|
|
EXAMPLE_INT = 123;
|
|
|
|
EXAMPLE_INT_NEG = -123;
|
|
|
|
EXAMPLE_STR = "foo bar";
|
|
|
|
EXAMPLE_LIST = [ "foo" "bar" ];
|
|
|
|
EXAMPLE_NESTED_LIST = [ [ "foo" "bar" ] [ "baz" ] ];
|
|
|
|
EXAMPLE_ATTRS = { foo = "bar"; };
|
|
|
|
EXAMPLE_NESTED_ATTRS = { foo.bar = "baz"; };
|
|
|
|
|
|
|
|
inherit goldenSh;
|
|
|
|
inherit goldenJson;
|
|
|
|
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out
|
|
|
|
cat $NIX_ATTRS_SH_FILE | grep "EXAMPLE" | grep -v -E 'installPhase|jq' > $out/sh
|
|
|
|
jq 'with_entries(select(.key|match("EXAMPLE")))' $NIX_ATTRS_JSON_FILE > $out/json
|
|
|
|
diff $out/sh $goldenSh
|
|
|
|
diff $out/json $goldenJson
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-12-07 03:55:45 +00:00
|
|
|
};
|
|
|
|
}
|