summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohannes Kirschbauer <hsjobeki@gmail.com>2026-01-08 11:02:11 +0100
committerJohannes Kirschbauer <hsjobeki@gmail.com>2026-01-20 21:26:05 +0100
commitf4d45cdced8644ef0e928f925610fb3add96d5e4 (patch)
tree478577f4f6f8b16fca9fee1ef0240b9a46980852 /lib
parentlib/tests: add strict option to checkConfigOutput (diff)
downloadnixpkgs-f4d45cdced8644ef0e928f925610fb3add96d5e4.tar.gz
lib/types: add tests for types.mkStructuredType
Diffstat (limited to 'lib')
-rwxr-xr-xlib/tests/modules.sh13
-rw-r--r--lib/tests/modules/types.nix32
2 files changed, 45 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 68645394e314..d148cd1839da 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -254,6 +254,19 @@ checkConfigError 'A definition for option .* is not of type .fileset.. Definitio
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err3 ./fileset.nix
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err4 ./fileset.nix
+# types.serializableValueWith
+checkConfigOutput '^null$' config.nullableValue.null ./types.nix
+checkConfigOutput '^true$' config.nullableValue.bool ./types.nix
+checkConfigOutput '^1$' config.nullableValue.int ./types.nix
+checkConfigOutput '^1.1$' config.nullableValue.float ./types.nix
+checkConfigOutput '^"foo"$' config.nullableValue.str ./types.nix
+checkConfigOutput '^".*/store.*"$' config.nullableValue.path ./types.nix
+STRICT_EVAL=1 checkConfigOutput '^\{"foo":1\}$' config.nullableValue.attrs ./types.nix
+STRICT_EVAL=1 checkConfigOutput '^\[\{"bar":\[1\]\}\]$' config.nullableValue.list ./types.nix
+
+checkConfigError 'A definition for option .* is not of type .VAL value.. .*' config.nullableValue.lambda ./types.nix
+checkConfigError 'A definition for option .* is not of type .VAL value.. .*' config.structuredValue.null ./types.nix
+
# Check boolean option.
checkConfigOutput '^false$' config.enable ./declare-enable.nix
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix
diff --git a/lib/tests/modules/types.nix b/lib/tests/modules/types.nix
index 0a566ea960c4..e12591d27e1f 100644
--- a/lib/tests/modules/types.nix
+++ b/lib/tests/modules/types.nix
@@ -16,6 +16,19 @@ in
options = {
pathInStore = mkOption { type = types.lazyAttrsOf types.pathInStore; };
externalPath = mkOption { type = types.lazyAttrsOf types.externalPath; };
+ # serializableValueWith
+ nullableValue = mkOption {
+ type = types.attrsOf (types.serializableValueWith { typeName = "VAL"; });
+ };
+ structuredValue = mkOption {
+ type = types.attrsOf (
+ types.serializableValueWith {
+ typeName = "VAL";
+ nullable = false;
+ }
+ );
+ };
+
assertions = mkOption { };
};
config = {
@@ -35,6 +48,22 @@ in
externalPath.ok1 = "/foo/bar";
externalPath.ok2 = "/";
+ # serializableValueWith { nullable = true; }
+ nullableValue.null = null; # null
+ nullableValue.bool = true; # bool
+ nullableValue.int = 1; # int
+ nullableValue.float = 1.1; # float
+ nullableValue.str = "foo"; # str
+ nullableValue.path = ./.; # path
+ nullableValue.attrs = {
+ foo = 1;
+ };
+ nullableValue.list = [ { bar = [ 1 ]; } ]; # list
+ nullableValue.lambda = x: x; # Error
+
+ # serializableValueWith { nullable = false; }
+ structuredValue.null = null; # Error
+
assertions =
with lib.types;
@@ -486,6 +515,9 @@ in
assert (unique { message = "custom"; } (listOf str)).description == "list of string";
assert (unique { message = "test"; } (either int str)).description == "signed integer or string";
assert (unique { message = "test"; } (listOf str)).description == "list of string";
+ # json & toml
+ assert json.description == "JSON value";
+ assert toml.description == "TOML value";
# done
"ok";
};