mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-29 06:45:54 +03:00
tests.stdenv: add test-golden-example-structuredAttrs
examples copied from https://nixos.mayflower.consulting/blog/2020/01/20/structured-attrs/ nix has tests for structuredAttrs but i figured it'd be good to have a golden test here too https://github.com/NixOS/nix/blob/master/tests/structured-attrs.nix https://github.com/NixOS/nix/blob/master/tests/structured-attrs-shell.nix
This commit is contained in:
parent
aae20cf5c0
commit
84a7cadfd2
@ -8,6 +8,8 @@
|
|||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
# early enough not to rebuild gcc but late enough to have patchelf
|
||||||
|
earlyPkgs = stdenv.__bootPackages.stdenv.__bootPackages;
|
||||||
# use a early stdenv so when hacking on stdenv this test can be run quickly
|
# 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;
|
bootStdenv = stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv;
|
||||||
pkgsStructured = import pkgs.path { config = { structuredAttrsByDefault = true; }; inherit (stdenv.hostPlatform) system; };
|
pkgsStructured = import pkgs.path { config = { structuredAttrsByDefault = true; }; inherit (stdenv.hostPlatform) system; };
|
||||||
@ -155,5 +157,74 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user