lib/tests: Add submoduleWith tests
This commit is contained in:
parent
eec83d41e3
commit
cc81320a46
8 changed files with 110 additions and 0 deletions
|
@ -164,6 +164,24 @@ checkConfigOutput "true" config.enableAlias ./alias-with-priority.nix
|
||||||
checkConfigOutput "false" config.enable ./alias-with-priority-can-override.nix
|
checkConfigOutput "false" config.enable ./alias-with-priority-can-override.nix
|
||||||
checkConfigOutput "false" config.enableAlias ./alias-with-priority-can-override.nix
|
checkConfigOutput "false" config.enableAlias ./alias-with-priority-can-override.nix
|
||||||
|
|
||||||
|
# submoduleWith
|
||||||
|
|
||||||
|
## specialArgs should work
|
||||||
|
checkConfigOutput "foo" config.submodule.foo ./declare-submoduleWith-special.nix
|
||||||
|
|
||||||
|
## shorthandOnlyDefines config behaves as expected
|
||||||
|
checkConfigOutput "true" config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-shorthand.nix
|
||||||
|
checkConfigError 'is not of type `boolean' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-noshorthand.nix
|
||||||
|
checkConfigError 'value is a boolean while a set was expected' config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-shorthand.nix
|
||||||
|
checkConfigOutput "true" config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-noshorthand.nix
|
||||||
|
|
||||||
|
## submoduleWith should merge all modules in one swoop
|
||||||
|
checkConfigOutput "true" config.submodule.inner ./declare-submoduleWith-modules.nix
|
||||||
|
checkConfigOutput "true" config.submodule.outer ./declare-submoduleWith-modules.nix
|
||||||
|
|
||||||
|
## Paths should be allowed as values and work as expected
|
||||||
|
checkConfigOutput "true" config.submodule.enable ./declare-submoduleWith-path.nix
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
====== module tests ======
|
====== module tests ======
|
||||||
$pass Pass
|
$pass Pass
|
||||||
|
|
30
lib/tests/modules/declare-submoduleWith-modules.nix
Normal file
30
lib/tests/modules/declare-submoduleWith-modules.nix
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
{ lib, ... }: {
|
||||||
|
options.submodule = lib.mkOption {
|
||||||
|
type = lib.types.submoduleWith {
|
||||||
|
modules = [
|
||||||
|
{
|
||||||
|
options.inner = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
{
|
||||||
|
outer = true;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
config.submodule = lib.mkMerge [
|
||||||
|
({ lib, ... }: {
|
||||||
|
options.outer = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = false;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
{
|
||||||
|
inner = true;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
13
lib/tests/modules/declare-submoduleWith-noshorthand.nix
Normal file
13
lib/tests/modules/declare-submoduleWith-noshorthand.nix
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{ lib, ... }: let
|
||||||
|
sub.options.config = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = false;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
options.submodule = lib.mkOption {
|
||||||
|
type = lib.types.submoduleWith {
|
||||||
|
modules = [ sub ];
|
||||||
|
};
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
}
|
12
lib/tests/modules/declare-submoduleWith-path.nix
Normal file
12
lib/tests/modules/declare-submoduleWith-path.nix
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{ lib, ... }: {
|
||||||
|
options.submodule = lib.mkOption {
|
||||||
|
type = lib.types.submoduleWith {
|
||||||
|
modules = [
|
||||||
|
./declare-enable.nix
|
||||||
|
];
|
||||||
|
};
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
config.submodule = ./define-enable.nix;
|
||||||
|
}
|
14
lib/tests/modules/declare-submoduleWith-shorthand.nix
Normal file
14
lib/tests/modules/declare-submoduleWith-shorthand.nix
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{ lib, ... }: let
|
||||||
|
sub.options.config = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = false;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
options.submodule = lib.mkOption {
|
||||||
|
type = lib.types.submoduleWith {
|
||||||
|
modules = [ sub ];
|
||||||
|
shorthandOnlyDefinesConfig = true;
|
||||||
|
};
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
}
|
17
lib/tests/modules/declare-submoduleWith-special.nix
Normal file
17
lib/tests/modules/declare-submoduleWith-special.nix
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{ lib, ... }: {
|
||||||
|
options.submodule = lib.mkOption {
|
||||||
|
type = lib.types.submoduleWith {
|
||||||
|
modules = [
|
||||||
|
({ lib, ... }: {
|
||||||
|
options.foo = lib.mkOption {
|
||||||
|
default = lib.foo;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
specialArgs.lib = lib // {
|
||||||
|
foo = "foo";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
}
|
3
lib/tests/modules/define-submoduleWith-noshorthand.nix
Normal file
3
lib/tests/modules/define-submoduleWith-noshorthand.nix
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
submodule.config.config = true;
|
||||||
|
}
|
3
lib/tests/modules/define-submoduleWith-shorthand.nix
Normal file
3
lib/tests/modules/define-submoduleWith-shorthand.nix
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
submodule.config = true;
|
||||||
|
}
|
Loading…
Reference in a new issue