lib/tests: Add submoduleWith tests

+18
lib/tests/modules.sh
···
checkConfigOutput "false" config.enable ./alias-with-priority-can-override.nix
checkConfigOutput "false" config.enableAlias ./alias-with-priority-can-override.nix
cat <<EOF
====== module tests ======
$pass Pass
···
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
+30
lib/tests/modules/declare-submoduleWith-modules.nix
···
···
+
{ 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
···
···
+
{ 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
···
···
+
{ 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
···
···
+
{ 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
···
···
+
{ 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
···
···
+
{
+
submodule.config.config = true;
+
}
+3
lib/tests/modules/define-submoduleWith-shorthand.nix
···
···
+
{
+
submodule.config = true;
+
}