diff options
author | Silvan Mosberger <infinisil@icloud.com> | 2019-10-12 20:37:21 +0200 |
---|---|---|
committer | Silvan Mosberger <contact@infinisil.com> | 2020-01-10 16:20:31 +0100 |
commit | ab10e874141503cee57a4e4e92d4e3c31be2a2a3 (patch) | |
tree | 5b2b219e64393ca740b83d73d436fa015be3f518 | |
parent | b48717d1eb9d4d9d60f3460274e7d9a961a402df (diff) |
lib/tests: Add tests for attrsOf and lazyAttrsOf
-rwxr-xr-x | lib/tests/modules.sh | 9 | ||||
-rw-r--r-- | lib/tests/modules/attrsOf-conditional-check.nix | 7 | ||||
-rw-r--r-- | lib/tests/modules/attrsOf-lazy-check.nix | 7 | ||||
-rw-r--r-- | lib/tests/modules/declare-attrsOf.nix | 6 | ||||
-rw-r--r-- | lib/tests/modules/declare-lazyAttrsOf.nix | 6 |
5 files changed, 35 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 79d90670fb53..c8340ff7f157 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -186,6 +186,15 @@ checkConfigError 'The option .* defined in .* does not exist' config.enable ./di # Check that imports can depend on derivations checkConfigOutput "true" config.enable ./import-from-store.nix +# Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only +# attrsOf should work with conditional definitions +# In addition, lazyAttrsOf should honor an options emptyValue +checkConfigError "is not lazy" config.isLazy ./declare-attrsOf.nix ./attrsOf-lazy-check.nix +checkConfigOutput "true" config.isLazy ./declare-lazyAttrsOf.nix ./attrsOf-lazy-check.nix +checkConfigOutput "true" config.conditionalWorks ./declare-attrsOf.nix ./attrsOf-conditional-check.nix +checkConfigOutput "false" config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix +checkConfigOutput "empty" config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix + cat <<EOF ====== module tests ====== $pass Pass diff --git a/lib/tests/modules/attrsOf-conditional-check.nix b/lib/tests/modules/attrsOf-conditional-check.nix new file mode 100644 index 000000000000..0f00ebca1559 --- /dev/null +++ b/lib/tests/modules/attrsOf-conditional-check.nix @@ -0,0 +1,7 @@ +{ lib, config, ... }: { + options.conditionalWorks = lib.mkOption { + default = ! config.value ? foo; + }; + + config.value.foo = lib.mkIf false "should not be defined"; +} diff --git a/lib/tests/modules/attrsOf-lazy-check.nix b/lib/tests/modules/attrsOf-lazy-check.nix new file mode 100644 index 000000000000..ec5b418b15aa --- /dev/null +++ b/lib/tests/modules/attrsOf-lazy-check.nix @@ -0,0 +1,7 @@ +{ lib, config, ... }: { + options.isLazy = lib.mkOption { + default = ! config.value ? foo; + }; + + config.value.bar = throw "is not lazy"; +} diff --git a/lib/tests/modules/declare-attrsOf.nix b/lib/tests/modules/declare-attrsOf.nix new file mode 100644 index 000000000000..b3999de7e5fb --- /dev/null +++ b/lib/tests/modules/declare-attrsOf.nix @@ -0,0 +1,6 @@ +{ lib, ... }: { + options.value = lib.mkOption { + type = lib.types.attrsOf lib.types.str; + default = {}; + }; +} diff --git a/lib/tests/modules/declare-lazyAttrsOf.nix b/lib/tests/modules/declare-lazyAttrsOf.nix new file mode 100644 index 000000000000..1d9fec25f908 --- /dev/null +++ b/lib/tests/modules/declare-lazyAttrsOf.nix @@ -0,0 +1,6 @@ +{ lib, ... }: { + options.value = lib.mkOption { + type = lib.types.lazyAttrsOf (lib.types.str // { emptyValue.value = "empty"; }); + default = {}; + }; +} |