diff options
author | Silvan Mosberger <contact@infinisil.com> | 2020-03-22 20:55:54 +0100 |
---|---|---|
committer | Silvan Mosberger <contact@infinisil.com> | 2020-08-03 22:37:01 +0200 |
commit | 446d80d28deb9929aca2a70699b3f32c2f1297d5 (patch) | |
tree | f4e752eb936d4a00718f3e79873eae0a4d443caf /lib | |
parent | 2d45a62899d47c109a0b8ce4ca9d33265b8a1a37 (diff) | |
download | nixpkgs-446d80d28deb9929aca2a70699b3f32c2f1297d5.tar nixpkgs-446d80d28deb9929aca2a70699b3f32c2f1297d5.tar.gz nixpkgs-446d80d28deb9929aca2a70699b3f32c2f1297d5.tar.bz2 nixpkgs-446d80d28deb9929aca2a70699b3f32c2f1297d5.tar.lz nixpkgs-446d80d28deb9929aca2a70699b3f32c2f1297d5.tar.xz nixpkgs-446d80d28deb9929aca2a70699b3f32c2f1297d5.tar.zst nixpkgs-446d80d28deb9929aca2a70699b3f32c2f1297d5.zip |
lib/tests: Add tests for freeform modules
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/tests/modules.sh | 21 | ||||
-rw-r--r-- | lib/tests/modules/define-value-string-properties.nix | 12 | ||||
-rw-r--r-- | lib/tests/modules/freeform-attrsOf.nix | 3 | ||||
-rw-r--r-- | lib/tests/modules/freeform-lazyAttrsOf.nix | 3 | ||||
-rw-r--r-- | lib/tests/modules/freeform-nested.nix | 7 | ||||
-rw-r--r-- | lib/tests/modules/freeform-str-dep-unstr.nix | 8 | ||||
-rw-r--r-- | lib/tests/modules/freeform-unstr-dep-str.nix | 8 |
7 files changed, 62 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 6258244457a..848b10e17f6 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -210,6 +210,27 @@ checkConfigOutput "empty" config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-c checkConfigError 'The option value .* in .* is not of type .*' \ config.value ./declare-int-unsigned-value.nix ./define-value-list.nix ./define-value-int-positive.nix +## Freeform modules +# Assigning without a declared option should work +checkConfigOutput 24 config.value ./freeform-attrsOf.nix ./define-value-string.nix +# but only if the type matches +checkConfigError 'The option value .* in .* is not of type .*' config.value ./freeform-attrsOf.nix ./define-value-list.nix +# and properties should be applied +checkConfigOutput yes config.value ./freeform-attrsOf.nix ./define-value-string-properties.nix +# Options should still be declarable, and be able to have a type that doesn't match the freeform type +checkConfigOutput false config.enable ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix +checkConfigOutput 24 config.value ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix +# and this should work too with nested values +checkConfigOutput false config.nest.foo ./freeform-attrsOf.nix ./freeform-nested.nix +checkConfigOutput bar config.nest.bar ./freeform-attrsOf.nix ./freeform-nested.nix +# Check whether a declared option can depend on an freeform-typed one +checkConfigOutput null config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix +checkConfigOutput 24 config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix ./define-value-string.nix +# Check whether an freeform-typed value can depend on a declared option, this can only work with lazyAttrsOf +checkConfigError 'infinite recursion encountered' config.foo ./freeform-attrsOf.nix ./freeform-unstr-dep-str.nix +checkConfigError 'The option .* is used but not defined' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix +checkConfigOutput 24 config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix ./define-value-string.nix + cat <<EOF ====== module tests ====== $pass Pass diff --git a/lib/tests/modules/define-value-string-properties.nix b/lib/tests/modules/define-value-string-properties.nix new file mode 100644 index 00000000000..972304c0112 --- /dev/null +++ b/lib/tests/modules/define-value-string-properties.nix @@ -0,0 +1,12 @@ +{ lib, ... }: { + + imports = [{ + value = lib.mkDefault "def"; + }]; + + value = lib.mkMerge [ + (lib.mkIf false "nope") + "yes" + ]; + +} diff --git a/lib/tests/modules/freeform-attrsOf.nix b/lib/tests/modules/freeform-attrsOf.nix new file mode 100644 index 00000000000..5dbf4a9d307 --- /dev/null +++ b/lib/tests/modules/freeform-attrsOf.nix @@ -0,0 +1,3 @@ +{ lib, ... }: { + config._module.freeformType = with lib.types; attrsOf (either str (attrsOf str)); +} diff --git a/lib/tests/modules/freeform-lazyAttrsOf.nix b/lib/tests/modules/freeform-lazyAttrsOf.nix new file mode 100644 index 00000000000..524efa6bd93 --- /dev/null +++ b/lib/tests/modules/freeform-lazyAttrsOf.nix @@ -0,0 +1,3 @@ +{ lib, ... }: { + config._module.freeformType = with lib.types; lazyAttrsOf (either str (lazyAttrsOf str)); +} diff --git a/lib/tests/modules/freeform-nested.nix b/lib/tests/modules/freeform-nested.nix new file mode 100644 index 00000000000..5da27f5a8b4 --- /dev/null +++ b/lib/tests/modules/freeform-nested.nix @@ -0,0 +1,7 @@ +{ lib, ... }: { + options.nest.foo = lib.mkOption { + type = lib.types.bool; + default = false; + }; + config.nest.bar = "bar"; +} diff --git a/lib/tests/modules/freeform-str-dep-unstr.nix b/lib/tests/modules/freeform-str-dep-unstr.nix new file mode 100644 index 00000000000..a2dfbc80cfa --- /dev/null +++ b/lib/tests/modules/freeform-str-dep-unstr.nix @@ -0,0 +1,8 @@ +{ lib, config, ... }: { + options.foo = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + }; + + config.foo = lib.mkIf (config ? value) config.value; +} diff --git a/lib/tests/modules/freeform-unstr-dep-str.nix b/lib/tests/modules/freeform-unstr-dep-str.nix new file mode 100644 index 00000000000..549d89afeca --- /dev/null +++ b/lib/tests/modules/freeform-unstr-dep-str.nix @@ -0,0 +1,8 @@ +{ lib, config, ... }: { + options.value = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + }; + + config.foo = lib.mkIf (config.value != null) config.value; +} |