mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 19:13:26 +03:00
lib/types: Test attrsWith type merging
Co-Authored-By: @hsjobeki
This commit is contained in:
parent
5b7a21358d
commit
bd353d322c
3 changed files with 35 additions and 20 deletions
|
@ -386,6 +386,10 @@ checkConfigOutput '^true$' config.conditionalWorks ./declare-attrsOf.nix ./attrs
|
|||
checkConfigOutput '^false$' config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
|
||||
checkConfigOutput '^"empty"$' config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
|
||||
|
||||
# Check attrsWith type merging
|
||||
checkConfigError 'The option `mergedLazyNonLazy'\'' in `.*'\'' is already declared in `.*'\''\.' options.mergedLazyNonLazy ./lazy-attrsWith.nix
|
||||
checkConfigOutput '^11$' config.lazyResult ./lazy-attrsWith.nix
|
||||
checkConfigError 'infinite recursion encountered' config.nonLazyResult ./lazy-attrsWith.nix
|
||||
|
||||
# Even with multiple assignments, a type error should be thrown if any of them aren't valid
|
||||
checkConfigError 'A definition for option .* is not of type .*' \
|
||||
|
@ -575,8 +579,6 @@ checkConfigOutput '^38|27$' options.submoduleLine38.declarationPositions.1.line
|
|||
# nested options work
|
||||
checkConfigOutput '^34$' options.nested.nestedLine34.declarationPositions.0.line ./declaration-positions.nix
|
||||
|
||||
# AttrsWith tests
|
||||
checkConfigOutput '^11$' config.result ./lazy-attrsWith.nix
|
||||
|
||||
cat <<EOF
|
||||
====== module tests ======
|
||||
|
|
|
@ -2,6 +2,21 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) types mkOption;
|
||||
|
||||
lazyAttrsOf = mkOption {
|
||||
# Same as lazyAttrsOf
|
||||
type = types.attrsWith {
|
||||
lazy = true;
|
||||
elemType = types.int;
|
||||
};
|
||||
};
|
||||
|
||||
attrsOf = mkOption {
|
||||
# Same as lazyAttrsOf
|
||||
type = types.attrsWith {
|
||||
elemType = types.int;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
|
@ -9,26 +24,18 @@ in
|
|||
(
|
||||
{ ... }:
|
||||
{
|
||||
options.mergedLazy = mkOption {
|
||||
# Same as lazyAttrsOf
|
||||
type = types.attrsWith {
|
||||
lazy = true;
|
||||
elemType = types.int;
|
||||
};
|
||||
};
|
||||
options.mergedLazyLazy = lazyAttrsOf;
|
||||
options.mergedLazyNonLazy = lazyAttrsOf;
|
||||
options.mergedNonLazyNonLazy = attrsOf;
|
||||
}
|
||||
)
|
||||
# Module B
|
||||
(
|
||||
{ ... }:
|
||||
{
|
||||
options.mergedLazy = lib.mkOption {
|
||||
# Same as lazyAttrsOf
|
||||
type = types.attrsWith {
|
||||
lazy = true;
|
||||
elemType = types.int;
|
||||
};
|
||||
};
|
||||
options.mergedLazyLazy = lazyAttrsOf;
|
||||
options.mergedLazyNonLazy = attrsOf;
|
||||
options.mergedNonLazyNonLazy = attrsOf;
|
||||
}
|
||||
)
|
||||
# Result
|
||||
|
@ -36,9 +43,14 @@ in
|
|||
{ config, ... }:
|
||||
{
|
||||
# Can only evaluate if lazy
|
||||
config.mergedLazy.bar = config.mergedLazy.baz + 1;
|
||||
config.mergedLazy.baz = 10;
|
||||
options.result = mkOption { default = config.mergedLazy.bar; };
|
||||
config.mergedLazyLazy.bar = config.mergedLazyLazy.baz + 1;
|
||||
config.mergedLazyLazy.baz = 10;
|
||||
options.lazyResult = mkOption { default = config.mergedLazyLazy.bar; };
|
||||
|
||||
# Can not only evaluate if not lazy
|
||||
config.mergedNonLazyNonLazy.bar = config.mergedNonLazyNonLazy.baz + 1;
|
||||
config.mergedNonLazyNonLazy.baz = 10;
|
||||
options.nonLazyResult = mkOption { default = config.mergedNonLazyNonLazy.bar; };
|
||||
}
|
||||
)
|
||||
];
|
||||
|
|
|
@ -630,7 +630,8 @@ rec {
|
|||
getSubModules = elemType.getSubModules;
|
||||
substSubModules = m: attrsWith { elemType = elemType.substSubModules m; inherit lazy; };
|
||||
functor = defaultFunctor "attrsWith" // {
|
||||
wrapped = elemType;
|
||||
# TODO: This breaks stuff
|
||||
# wrapped = elemType;
|
||||
payload = {
|
||||
# Important!: Add new function attributes here in case of future changes
|
||||
inherit elemType lazy;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue