lib/types.either: add tests for warning in legacy case
This commit is contained in:
@@ -550,6 +550,28 @@ checkConfigOutput '/freeform-submodules.nix"$' config.fooDeclarations.0 ./freefo
|
||||
checkConfigOutput '^10$' config.free.xxx.foo ./freeform-submodules.nix
|
||||
checkConfigOutput '^10$' config.free.yyy.bar ./freeform-submodules.nix
|
||||
|
||||
# Regression of either, due to freeform not beeing checked previously
|
||||
checkConfigOutput '^"foo"$' config.either.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix
|
||||
NIX_ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.either.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix
|
||||
checkConfigOutput '^"foo"$' config.eitherBehindNullor.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix
|
||||
NIX_ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.eitherBehindNullor.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix
|
||||
checkConfigOutput '^"foo"$' config.oneOf.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix
|
||||
NIX_ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.oneOf.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix
|
||||
checkConfigOutput '^"foo"$' config.number.str ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix
|
||||
NIX_ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.number.str ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix
|
||||
|
||||
checkConfigOutput '^42$' config.either.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix
|
||||
NIX_ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.either.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix
|
||||
checkConfigOutput '^42$' config.eitherBehindNullor.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix
|
||||
NIX_ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.eitherBehindNullor.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix
|
||||
checkConfigOutput '^42$' config.oneOf.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix
|
||||
NIX_ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.oneOf.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix
|
||||
checkConfigOutput '^42$' config.number.str ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix
|
||||
NIX_ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.number.str ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix
|
||||
# Value OK: Fail if a warning is emitted
|
||||
NIX_ABORT_ON_WARN=1 checkConfigOutput "^42$" config.number.int ./freeform-attrsof-either.nix
|
||||
|
||||
|
||||
## types.anything
|
||||
# Check that attribute sets are merged recursively
|
||||
checkConfigOutput '^null$' config.value.foo ./types-anything/nested-attrs.nix
|
||||
|
||||
14
lib/tests/modules/freeform-attrsof-either.nix
Normal file
14
lib/tests/modules/freeform-attrsof-either.nix
Normal file
@@ -0,0 +1,14 @@
|
||||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) types mkOption;
|
||||
in
|
||||
{
|
||||
options.number = mkOption {
|
||||
type = types.submodule ({
|
||||
freeformType = types.attrsOf (types.either types.int types.int);
|
||||
});
|
||||
default = {
|
||||
int = 42;
|
||||
}; # should not emit a warning
|
||||
};
|
||||
}
|
||||
18
lib/tests/modules/freeform-deprecated-malicous-wrong.nix
Normal file
18
lib/tests/modules/freeform-deprecated-malicous-wrong.nix
Normal file
@@ -0,0 +1,18 @@
|
||||
# Obviously wrong typed
|
||||
{
|
||||
config.either = {
|
||||
int = "foo";
|
||||
};
|
||||
|
||||
config.eitherBehindNullor = {
|
||||
int = "foo";
|
||||
};
|
||||
|
||||
config.oneOf = {
|
||||
int = "foo";
|
||||
};
|
||||
|
||||
config.number = {
|
||||
str = "foo";
|
||||
};
|
||||
}
|
||||
19
lib/tests/modules/freeform-deprecated-malicous-wrong2.nix
Normal file
19
lib/tests/modules/freeform-deprecated-malicous-wrong2.nix
Normal file
@@ -0,0 +1,19 @@
|
||||
# freeeformType should have been (attrsOf either)
|
||||
# This should also print the warning
|
||||
{
|
||||
config.either = {
|
||||
int = 42;
|
||||
};
|
||||
|
||||
config.eitherBehindNullor = {
|
||||
int = 42;
|
||||
};
|
||||
|
||||
config.oneOf = {
|
||||
int = 42;
|
||||
};
|
||||
|
||||
config.number = {
|
||||
str = 42;
|
||||
};
|
||||
}
|
||||
34
lib/tests/modules/freeform-deprecated-malicous.nix
Normal file
34
lib/tests/modules/freeform-deprecated-malicous.nix
Normal file
@@ -0,0 +1,34 @@
|
||||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) types mkOption;
|
||||
in
|
||||
{
|
||||
options.either = mkOption {
|
||||
type = types.submodule ({
|
||||
freeformType = (types.either types.int types.int);
|
||||
});
|
||||
};
|
||||
|
||||
options.eitherBehindNullor = mkOption {
|
||||
type = types.submodule ({
|
||||
freeformType = types.nullOr (types.either types.int types.int);
|
||||
});
|
||||
};
|
||||
|
||||
options.oneOf = mkOption {
|
||||
type = types.submodule ({
|
||||
freeformType = (
|
||||
types.oneOf [
|
||||
types.int
|
||||
types.int
|
||||
]
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
options.number = mkOption {
|
||||
type = types.submodule ({
|
||||
freeformType = (types.number); # either int float
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user