mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 13:15:30 +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 '^false$' config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
|
||||||
checkConfigOutput '^"empty"$' config.value.foo ./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
|
# 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 .*' \
|
checkConfigError 'A definition for option .* is not of type .*' \
|
||||||
|
@ -575,8 +579,6 @@ checkConfigOutput '^38|27$' options.submoduleLine38.declarationPositions.1.line
|
||||||
# nested options work
|
# nested options work
|
||||||
checkConfigOutput '^34$' options.nested.nestedLine34.declarationPositions.0.line ./declaration-positions.nix
|
checkConfigOutput '^34$' options.nested.nestedLine34.declarationPositions.0.line ./declaration-positions.nix
|
||||||
|
|
||||||
# AttrsWith tests
|
|
||||||
checkConfigOutput '^11$' config.result ./lazy-attrsWith.nix
|
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
====== module tests ======
|
====== module tests ======
|
||||||
|
|
|
@ -2,6 +2,21 @@
|
||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) types mkOption;
|
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
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
|
@ -9,26 +24,18 @@ in
|
||||||
(
|
(
|
||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
options.mergedLazy = mkOption {
|
options.mergedLazyLazy = lazyAttrsOf;
|
||||||
# Same as lazyAttrsOf
|
options.mergedLazyNonLazy = lazyAttrsOf;
|
||||||
type = types.attrsWith {
|
options.mergedNonLazyNonLazy = attrsOf;
|
||||||
lazy = true;
|
|
||||||
elemType = types.int;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
# Module B
|
# Module B
|
||||||
(
|
(
|
||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
options.mergedLazy = lib.mkOption {
|
options.mergedLazyLazy = lazyAttrsOf;
|
||||||
# Same as lazyAttrsOf
|
options.mergedLazyNonLazy = attrsOf;
|
||||||
type = types.attrsWith {
|
options.mergedNonLazyNonLazy = attrsOf;
|
||||||
lazy = true;
|
|
||||||
elemType = types.int;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
# Result
|
# Result
|
||||||
|
@ -36,9 +43,14 @@ in
|
||||||
{ config, ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
# Can only evaluate if lazy
|
# Can only evaluate if lazy
|
||||||
config.mergedLazy.bar = config.mergedLazy.baz + 1;
|
config.mergedLazyLazy.bar = config.mergedLazyLazy.baz + 1;
|
||||||
config.mergedLazy.baz = 10;
|
config.mergedLazyLazy.baz = 10;
|
||||||
options.result = mkOption { default = config.mergedLazy.bar; };
|
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;
|
getSubModules = elemType.getSubModules;
|
||||||
substSubModules = m: attrsWith { elemType = elemType.substSubModules m; inherit lazy; };
|
substSubModules = m: attrsWith { elemType = elemType.substSubModules m; inherit lazy; };
|
||||||
functor = defaultFunctor "attrsWith" // {
|
functor = defaultFunctor "attrsWith" // {
|
||||||
wrapped = elemType;
|
# TODO: This breaks stuff
|
||||||
|
# wrapped = elemType;
|
||||||
payload = {
|
payload = {
|
||||||
# Important!: Add new function attributes here in case of future changes
|
# Important!: Add new function attributes here in case of future changes
|
||||||
inherit elemType lazy;
|
inherit elemType lazy;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue