lib/tests: Add tests for attrsOf and lazyAttrsOf
This commit is contained in:
parent
b48717d1eb
commit
ab10e87414
5 changed files with 35 additions and 0 deletions
|
@ -186,6 +186,15 @@ checkConfigError 'The option .* defined in .* does not exist' config.enable ./di
|
|||
# Check that imports can depend on derivations
|
||||
checkConfigOutput "true" config.enable ./import-from-store.nix
|
||||
|
||||
# Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only
|
||||
# attrsOf should work with conditional definitions
|
||||
# In addition, lazyAttrsOf should honor an options emptyValue
|
||||
checkConfigError "is not lazy" config.isLazy ./declare-attrsOf.nix ./attrsOf-lazy-check.nix
|
||||
checkConfigOutput "true" config.isLazy ./declare-lazyAttrsOf.nix ./attrsOf-lazy-check.nix
|
||||
checkConfigOutput "true" config.conditionalWorks ./declare-attrsOf.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
|
||||
|
||||
cat <<EOF
|
||||
====== module tests ======
|
||||
$pass Pass
|
||||
|
|
7
lib/tests/modules/attrsOf-conditional-check.nix
Normal file
7
lib/tests/modules/attrsOf-conditional-check.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{ lib, config, ... }: {
|
||||
options.conditionalWorks = lib.mkOption {
|
||||
default = ! config.value ? foo;
|
||||
};
|
||||
|
||||
config.value.foo = lib.mkIf false "should not be defined";
|
||||
}
|
7
lib/tests/modules/attrsOf-lazy-check.nix
Normal file
7
lib/tests/modules/attrsOf-lazy-check.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{ lib, config, ... }: {
|
||||
options.isLazy = lib.mkOption {
|
||||
default = ! config.value ? foo;
|
||||
};
|
||||
|
||||
config.value.bar = throw "is not lazy";
|
||||
}
|
6
lib/tests/modules/declare-attrsOf.nix
Normal file
6
lib/tests/modules/declare-attrsOf.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
{ lib, ... }: {
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.str;
|
||||
default = {};
|
||||
};
|
||||
}
|
6
lib/tests/modules/declare-lazyAttrsOf.nix
Normal file
6
lib/tests/modules/declare-lazyAttrsOf.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
{ lib, ... }: {
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.lazyAttrsOf (lib.types.str // { emptyValue.value = "empty"; });
|
||||
default = {};
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue