lib/tests: Add tests for module-builtin assertions

This commit is contained in:
Silvan Mosberger
2020-09-02 22:34:13 +02:00
parent 900c4a5abd
commit 3e39d6efdf
13 changed files with 197 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
{
_module.assertions.test = {
enable = false;
message = "Assertion failed";
};
}

View File

@@ -0,0 +1,17 @@
{ lib, ... }: {
options.foo = lib.mkOption {
default = true;
};
options.bar = lib.mkOption {
default = true;
};
config._module.assertions.test = {
enable = throw "enable evaluated";
message = "Assertion failed";
triggerPath = [ "foo" ];
};
}

View File

@@ -0,0 +1,23 @@
{
_module.assertions = {
test1 = {
enable = true;
message = "Assertion 1 failed";
};
test2 = {
enable = true;
message = "Assertion 2 failed";
};
test3 = {
enable = true;
message = "Warning 3 failed";
type = "warning";
};
test4 = {
enable = true;
message = "Warning 4 failed";
type = "warning";
};
};
}

View File

@@ -0,0 +1,17 @@
{ lib, config, ... }: {
options.foo = lib.mkOption {
default = true;
};
options.bar = lib.mkOption {
default = config.foo;
};
config._module.assertions.foo = {
enable = true;
message = "Foo assertion";
triggerPath = [ "foo" ];
};
}

View File

@@ -0,0 +1,6 @@
{
_module.assertions.test = {
enable = true;
message = "Assertion failed";
};
}

View File

@@ -0,0 +1,13 @@
{ lib, ... }: {
options.foo = lib.mkOption {
default = { bar.baz = {}; };
type = lib.types.attrsOf (lib.types.attrsOf (lib.types.submodule {
_module.assertions.test = {
enable = true;
message = "Assertion failed";
};
}));
};
}

View File

@@ -0,0 +1,13 @@
{ lib, ... }: {
options.foo = lib.mkOption {
default = { bar = {}; };
type = lib.types.attrsOf (lib.types.submodule {
_module.assertions.test = {
enable = true;
message = "Assertion failed";
};
});
};
}

View File

@@ -0,0 +1,13 @@
{ lib, ... }: {
options.foo = lib.mkOption {
default = {};
type = lib.types.submodule {
_module.assertions.test = {
enable = true;
message = "Assertion failed";
};
};
};
}

View File

@@ -0,0 +1,15 @@
{ lib, ... }: {
options.foo = lib.mkOption {
default = true;
};
options.bar = lib.mkOption {
default = true;
};
config._module.assertions.test = {
enable = true;
message = "Assertion failed";
triggerPath = [ "foo" ];
};
}

View File

@@ -0,0 +1,18 @@
{ lib, ... }: {
options.foo = lib.mkOption {
default = { bar = {}; };
type = lib.types.attrsOf (lib.types.submodule {
options.baz = lib.mkOption {
default = true;
};
});
};
config._module.assertions.test = {
enable = true;
message = "Assertion failed";
triggerPath = [ "foo" "bar" "baz" ];
};
}

View File

@@ -0,0 +1,8 @@
{
_module.assertions._test = {
enable = true;
message = "Assertion failed";
};
}

View File

@@ -0,0 +1,9 @@
{
_module.assertions.test = {
enable = true;
type = "warning";
message = "Warning message";
};
}