mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-04-14 11:57:47 +00:00
lib/tests/modules.sh: Add submodule + class tests
This commit is contained in:
parent
8054785157
commit
7459c02495
@ -362,11 +362,18 @@ checkConfigOutput 'ok' config.freeformItems.foo.bar ./adhoc-freeformType-survive
|
||||
# because of an `extendModules` bug, issue 168767.
|
||||
checkConfigOutput '^1$' config.sub.specialisation.value ./extendModules-168767-imports.nix
|
||||
|
||||
# Class checks
|
||||
# Class checks, evalModules
|
||||
checkConfigOutput '^{ }$' config.ok.config ./class-check.nix
|
||||
checkConfigError 'The module .*/module-class-is-darwin.nix was imported into nixos instead of darwin.' config.fail.config ./class-check.nix
|
||||
checkConfigError 'The module foo.nix#darwinModules.default was imported into nixos instead of darwin.' config.fail-anon.config ./class-check.nix
|
||||
|
||||
# Class checks, submoduleWith
|
||||
checkConfigOutput '^{ }$' config.sub.nixosOk ./class-check.nix
|
||||
checkConfigError 'The module .*/module-class-is-darwin.nix was imported into nixos instead of darwin.' config.sub.nixosFail.config ./class-check.nix
|
||||
|
||||
# submoduleWith type merge with different class
|
||||
checkConfigError 'error: A submoduleWith option is declared multiple times with conflicting class values "darwin" and "nixos".' config.sub.mergeFail.config ./class-check.nix
|
||||
|
||||
# _type check
|
||||
checkConfigError 'Could not load a value as a module, because it is of type "flake", in file .*/module-imports-_type-check.nix' config.ok.config ./module-imports-_type-check.nix
|
||||
checkConfigOutput '^true$' "$@" config.enable ./declare-enable.nix ./define-enable-with-top-level-mkIf.nix
|
||||
|
@ -1,4 +1,43 @@
|
||||
{ lib, ... }: {
|
||||
options = {
|
||||
sub = {
|
||||
nixosOk = lib.mkOption {
|
||||
type = lib.types.submoduleWith {
|
||||
class = "nixos";
|
||||
modules = [ ];
|
||||
};
|
||||
};
|
||||
# Same but will have bad definition
|
||||
nixosFail = lib.mkOption {
|
||||
type = lib.types.submoduleWith {
|
||||
class = "nixos";
|
||||
modules = [ ];
|
||||
};
|
||||
};
|
||||
|
||||
mergeFail = lib.mkOption {
|
||||
type = lib.types.submoduleWith {
|
||||
class = "nixos";
|
||||
modules = [ ];
|
||||
};
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
};
|
||||
imports = [
|
||||
{
|
||||
options = {
|
||||
sub = {
|
||||
mergeFail = lib.mkOption {
|
||||
type = lib.types.submoduleWith {
|
||||
class = "darwin";
|
||||
modules = [ ];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
config = {
|
||||
_module.freeformType = lib.types.anything;
|
||||
ok =
|
||||
@ -31,5 +70,7 @@
|
||||
];
|
||||
};
|
||||
|
||||
sub.nixosOk = { config = {}; class = "nixos"; };
|
||||
sub.nixosFail = { imports = [ ./module-class-is-darwin.nix ]; };
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user