summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorSilvan Mosberger <infinisil@icloud.com>2019-10-12 20:37:21 +0200
committerSilvan Mosberger <contact@infinisil.com>2020-01-10 16:20:31 +0100
commitab10e874141503cee57a4e4e92d4e3c31be2a2a3 (patch)
tree5b2b219e64393ca740b83d73d436fa015be3f518 /lib
parentb48717d1eb9d4d9d60f3460274e7d9a961a402df (diff)
downloadnixpkgs-ab10e874141503cee57a4e4e92d4e3c31be2a2a3.tar
nixpkgs-ab10e874141503cee57a4e4e92d4e3c31be2a2a3.tar.gz
nixpkgs-ab10e874141503cee57a4e4e92d4e3c31be2a2a3.tar.bz2
nixpkgs-ab10e874141503cee57a4e4e92d4e3c31be2a2a3.tar.lz
nixpkgs-ab10e874141503cee57a4e4e92d4e3c31be2a2a3.tar.xz
nixpkgs-ab10e874141503cee57a4e4e92d4e3c31be2a2a3.tar.zst
nixpkgs-ab10e874141503cee57a4e4e92d4e3c31be2a2a3.zip
lib/tests: Add tests for attrsOf and lazyAttrsOf
Diffstat (limited to 'lib')
-rwxr-xr-xlib/tests/modules.sh9
-rw-r--r--lib/tests/modules/attrsOf-conditional-check.nix7
-rw-r--r--lib/tests/modules/attrsOf-lazy-check.nix7
-rw-r--r--lib/tests/modules/declare-attrsOf.nix6
-rw-r--r--lib/tests/modules/declare-lazyAttrsOf.nix6
5 files changed, 35 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 79d90670fb5..c8340ff7f15 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 00000000000..0f00ebca155
--- /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 00000000000..ec5b418b15a
--- /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 00000000000..b3999de7e5f
--- /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 00000000000..1d9fec25f90
--- /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 = {};
+  };
+}