From 446d80d28deb9929aca2a70699b3f32c2f1297d5 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Sun, 22 Mar 2020 20:55:54 +0100 Subject: lib/tests: Add tests for freeform modules --- lib/tests/modules.sh | 21 +++++++++++++++++++++ .../modules/define-value-string-properties.nix | 12 ++++++++++++ lib/tests/modules/freeform-attrsOf.nix | 3 +++ lib/tests/modules/freeform-lazyAttrsOf.nix | 3 +++ lib/tests/modules/freeform-nested.nix | 7 +++++++ lib/tests/modules/freeform-str-dep-unstr.nix | 8 ++++++++ lib/tests/modules/freeform-unstr-dep-str.nix | 8 ++++++++ 7 files changed, 62 insertions(+) create mode 100644 lib/tests/modules/define-value-string-properties.nix create mode 100644 lib/tests/modules/freeform-attrsOf.nix create mode 100644 lib/tests/modules/freeform-lazyAttrsOf.nix create mode 100644 lib/tests/modules/freeform-nested.nix create mode 100644 lib/tests/modules/freeform-str-dep-unstr.nix create mode 100644 lib/tests/modules/freeform-unstr-dep-str.nix (limited to 'lib/tests') diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 6258244457aa..848b10e17f67 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 < Date: Tue, 4 Aug 2020 00:08:43 +0200 Subject: lib/modules: Fix freeform modules when there's no definitions --- lib/tests/modules.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/tests') diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 848b10e17f67..943deebe3c09 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -213,6 +213,8 @@ checkConfigError 'The option value .* in .* is not of type .*' \ ## Freeform modules # Assigning without a declared option should work checkConfigOutput 24 config.value ./freeform-attrsOf.nix ./define-value-string.nix +# No freeform assigments shouldn't make it error +checkConfigOutput '{ }' config ./freeform-attrsOf.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 -- cgit v1.2.3 From 42cf8130d76ac811f8d1c934f9b44976050cc90f Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 10 Aug 2020 17:25:46 +0200 Subject: lib/modules: Add syntactic sugar for config._module.freeformType This introduces `freeformType` as a top-level module attribute, allowing definitions like { freeformType = ...; options = ...; config = ...; } --- lib/tests/modules/freeform-attrsOf.nix | 2 +- lib/tests/modules/freeform-lazyAttrsOf.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/tests') diff --git a/lib/tests/modules/freeform-attrsOf.nix b/lib/tests/modules/freeform-attrsOf.nix index 5dbf4a9d307c..8cc577f38a6c 100644 --- a/lib/tests/modules/freeform-attrsOf.nix +++ b/lib/tests/modules/freeform-attrsOf.nix @@ -1,3 +1,3 @@ { lib, ... }: { - config._module.freeformType = with lib.types; attrsOf (either str (attrsOf str)); + 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 index 524efa6bd930..36d6c0b13fca 100644 --- a/lib/tests/modules/freeform-lazyAttrsOf.nix +++ b/lib/tests/modules/freeform-lazyAttrsOf.nix @@ -1,3 +1,3 @@ { lib, ... }: { - config._module.freeformType = with lib.types; lazyAttrsOf (either str (lazyAttrsOf str)); + freeformType = with lib.types; lazyAttrsOf (either str (lazyAttrsOf str)); } -- cgit v1.2.3