mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 19:13:26 +03:00
lib.packagesFromDirectoryRecursive: add tests for nested scopes
This commit is contained in:
parent
6b7576b0cf
commit
41f219d1d9
12 changed files with 58 additions and 0 deletions
|
@ -2687,4 +2687,38 @@ runTests {
|
|||
checkC = false;
|
||||
};
|
||||
};
|
||||
|
||||
# Check that `packagesFromDirectoryRecursive` can be used to create scopes
|
||||
# for sub-directories
|
||||
testPackagesFromDirectoryNestedScopes = let
|
||||
inherit (lib) makeScope recurseIntoAttrs;
|
||||
emptyScope = makeScope lib.callPackageWith (_: {});
|
||||
in {
|
||||
expr = lib.filterAttrsRecursive (name: value: !lib.elem name [ "callPackage" "newScope" "overrideScope" "packages" ]) (packagesFromDirectoryRecursive {
|
||||
inherit (emptyScope) callPackage newScope;
|
||||
recurseIntoDirectory = f: { newScope, ... }@args:
|
||||
recurseIntoAttrs (makeScope newScope (self:
|
||||
f (args // {
|
||||
inherit (self) callPackage newScope;
|
||||
})
|
||||
));
|
||||
directory = ./packages-from-directory/scope;
|
||||
});
|
||||
expected = lib.recurseIntoAttrs {
|
||||
a = "a";
|
||||
b = "b";
|
||||
# Note: Other files/directories in `./test-data/c/` are ignored and can be
|
||||
# used by `package.nix`.
|
||||
c = "c";
|
||||
my-namespace = lib.recurseIntoAttrs {
|
||||
d = "d";
|
||||
e = "e";
|
||||
f = "f";
|
||||
my-sub-namespace = lib.recurseIntoAttrs {
|
||||
g = "g";
|
||||
h = "h";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
1
lib/tests/packages-from-directory/scope/a.nix
Normal file
1
lib/tests/packages-from-directory/scope/a.nix
Normal file
|
@ -0,0 +1 @@
|
|||
{ }: "a"
|
3
lib/tests/packages-from-directory/scope/b.nix
Normal file
3
lib/tests/packages-from-directory/scope/b.nix
Normal file
|
@ -0,0 +1,3 @@
|
|||
{ a }:
|
||||
assert a == "a";
|
||||
"b"
|
|
@ -0,0 +1 @@
|
|||
{ }
|
1
lib/tests/packages-from-directory/scope/c/package.nix
Normal file
1
lib/tests/packages-from-directory/scope/c/package.nix
Normal file
|
@ -0,0 +1 @@
|
|||
{ }: "c"
|
|
@ -0,0 +1 @@
|
|||
{ }
|
|
@ -0,0 +1,5 @@
|
|||
{ a, e }:
|
||||
# Check we can get parameter from the parent scope(s) as well as the current one
|
||||
assert a == "a";
|
||||
assert e == "e";
|
||||
"d"
|
|
@ -0,0 +1,3 @@
|
|||
{ d }:
|
||||
# Check that mutual recursion is possible
|
||||
"e"
|
|
@ -0,0 +1 @@
|
|||
{ }: "f"
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
a,
|
||||
d,
|
||||
h,
|
||||
}:
|
||||
# Check we can get parameters from ancestral scopes (e.g. the scope's grandparent)
|
||||
"g"
|
|
@ -0,0 +1 @@
|
|||
{ }: "h"
|
Loading…
Add table
Add a link
Reference in a new issue