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"; };