mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-09 12:18:04 +03:00
lib/tests: Add tests for freeform modules
This commit is contained in:
parent
2d45a62899
commit
446d80d28d
@ -210,6 +210,27 @@ checkConfigOutput "empty" config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-c
|
||||
checkConfigError 'The option value .* in .* is not of type .*' \
|
||||
config.value ./declare-int-unsigned-value.nix ./define-value-list.nix ./define-value-int-positive.nix
|
||||
|
||||
## Freeform modules
|
||||
# Assigning without a declared option should work
|
||||
checkConfigOutput 24 config.value ./freeform-attrsOf.nix ./define-value-string.nix
|
||||
# but only if the type matches
|
||||
checkConfigError 'The option value .* in .* is not of type .*' config.value ./freeform-attrsOf.nix ./define-value-list.nix
|
||||
# and properties should be applied
|
||||
checkConfigOutput yes config.value ./freeform-attrsOf.nix ./define-value-string-properties.nix
|
||||
# Options should still be declarable, and be able to have a type that doesn't match the freeform type
|
||||
checkConfigOutput false config.enable ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix
|
||||
checkConfigOutput 24 config.value ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix
|
||||
# and this should work too with nested values
|
||||
checkConfigOutput false config.nest.foo ./freeform-attrsOf.nix ./freeform-nested.nix
|
||||
checkConfigOutput bar config.nest.bar ./freeform-attrsOf.nix ./freeform-nested.nix
|
||||
# Check whether a declared option can depend on an freeform-typed one
|
||||
checkConfigOutput null config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix
|
||||
checkConfigOutput 24 config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix ./define-value-string.nix
|
||||
# Check whether an freeform-typed value can depend on a declared option, this can only work with lazyAttrsOf
|
||||
checkConfigError 'infinite recursion encountered' config.foo ./freeform-attrsOf.nix ./freeform-unstr-dep-str.nix
|
||||
checkConfigError 'The option .* is used but not defined' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix
|
||||
checkConfigOutput 24 config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix ./define-value-string.nix
|
||||
|
||||
cat <<EOF
|
||||
====== module tests ======
|
||||
$pass Pass
|
||||
|
12
lib/tests/modules/define-value-string-properties.nix
Normal file
12
lib/tests/modules/define-value-string-properties.nix
Normal file
@ -0,0 +1,12 @@
|
||||
{ lib, ... }: {
|
||||
|
||||
imports = [{
|
||||
value = lib.mkDefault "def";
|
||||
}];
|
||||
|
||||
value = lib.mkMerge [
|
||||
(lib.mkIf false "nope")
|
||||
"yes"
|
||||
];
|
||||
|
||||
}
|
3
lib/tests/modules/freeform-attrsOf.nix
Normal file
3
lib/tests/modules/freeform-attrsOf.nix
Normal file
@ -0,0 +1,3 @@
|
||||
{ lib, ... }: {
|
||||
config._module.freeformType = with lib.types; attrsOf (either str (attrsOf str));
|
||||
}
|
3
lib/tests/modules/freeform-lazyAttrsOf.nix
Normal file
3
lib/tests/modules/freeform-lazyAttrsOf.nix
Normal file
@ -0,0 +1,3 @@
|
||||
{ lib, ... }: {
|
||||
config._module.freeformType = with lib.types; lazyAttrsOf (either str (lazyAttrsOf str));
|
||||
}
|
7
lib/tests/modules/freeform-nested.nix
Normal file
7
lib/tests/modules/freeform-nested.nix
Normal file
@ -0,0 +1,7 @@
|
||||
{ lib, ... }: {
|
||||
options.nest.foo = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
config.nest.bar = "bar";
|
||||
}
|
8
lib/tests/modules/freeform-str-dep-unstr.nix
Normal file
8
lib/tests/modules/freeform-str-dep-unstr.nix
Normal file
@ -0,0 +1,8 @@
|
||||
{ lib, config, ... }: {
|
||||
options.foo = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
|
||||
config.foo = lib.mkIf (config ? value) config.value;
|
||||
}
|
8
lib/tests/modules/freeform-unstr-dep-str.nix
Normal file
8
lib/tests/modules/freeform-unstr-dep-str.nix
Normal file
@ -0,0 +1,8 @@
|
||||
{ lib, config, ... }: {
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
|
||||
config.foo = lib.mkIf (config.value != null) config.value;
|
||||
}
|
Loading…
Reference in New Issue
Block a user