Loading lib/tests/modules.sh +13 −0 Original line number Diff line number Diff line Loading @@ -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 Loading lib/tests/modules/types.nix +32 −0 Original line number Diff line number Diff line Loading @@ -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 = { Loading @@ -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; Loading Loading @@ -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"; }; Loading Loading
lib/tests/modules.sh +13 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
lib/tests/modules/types.nix +32 −0 Original line number Diff line number Diff line Loading @@ -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 = { Loading @@ -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; Loading Loading @@ -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"; }; Loading