lib/tests: Add submoduleWith tests

This commit is contained in:
Silvan Mosberger 2020-01-01 01:11:45 +01:00
parent eec83d41e3
commit cc81320a46
No known key found for this signature in database
GPG key ID: E8F1E9EAD284E17D
8 changed files with 110 additions and 0 deletions

View file

@ -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.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
====== module tests ======
$pass Pass

View 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;
}
];
}

View 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 = {};
};
}

View file

@ -0,0 +1,12 @@
{ lib, ... }: {
options.submodule = lib.mkOption {
type = lib.types.submoduleWith {
modules = [
./declare-enable.nix
];
};
default = {};
};
config.submodule = ./define-enable.nix;
}

View 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 = {};
};
}

View 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 = {};
};
}

View file

@ -0,0 +1,3 @@
{
submodule.config.config = true;
}

View file

@ -0,0 +1,3 @@
{
submodule.config = true;
}