aboutsummaryrefslogtreecommitdiff
path: root/lib/tests
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-09-04 15:27:26 +0200
committerSilvan Mosberger <contact@infinisil.com>2020-09-15 21:06:05 +0200
commit6a7d250007baedeb4de34e8ce490d49160cb63a8 (patch)
tree482da5dd8e8bee9e53ee66a72a9aea1048bfdd8b /lib/tests
parent67551f46fbc20b3b96ff27503b659a8f3fedb421 (diff)
lib/tests: Add tests for types.anything
Diffstat (limited to 'lib/tests')
-rwxr-xr-xlib/tests/modules.sh29
-rw-r--r--lib/tests/modules/types-anything/attrs-coercible.nix12
-rw-r--r--lib/tests/modules/types-anything/equal-atoms.nix26
-rw-r--r--lib/tests/modules/types-anything/functions.nix17
-rw-r--r--lib/tests/modules/types-anything/lists.nix16
-rw-r--r--lib/tests/modules/types-anything/mk-mods.nix44
-rw-r--r--lib/tests/modules/types-anything/nested-attrs.nix22
7 files changed, 166 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 943deebe3c09..cfe474d4ded2 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -233,6 +233,35 @@ checkConfigError 'infinite recursion encountered' config.foo ./freeform-attrsOf.
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
+## types.anything
+# Check that attribute sets are merged recursively
+checkConfigOutput null config.value.foo ./types-anything/nested-attrs.nix
+checkConfigOutput null config.value.l1.foo ./types-anything/nested-attrs.nix
+checkConfigOutput null config.value.l1.l2.foo ./types-anything/nested-attrs.nix
+checkConfigOutput null config.value.l1.l2.l3.foo ./types-anything/nested-attrs.nix
+# Attribute sets that are coercible to strings shouldn't be recursed into
+checkConfigOutput foo config.value.outPath ./types-anything/attrs-coercible.nix
+# Multiple lists aren't concatenated together
+checkConfigError 'The option .* has conflicting definitions' config.value ./types-anything/lists.nix
+# Check that all equalizable atoms can be used as long as all definitions are equal
+checkConfigOutput 0 config.value.int ./types-anything/equal-atoms.nix
+checkConfigOutput false config.value.bool ./types-anything/equal-atoms.nix
+checkConfigOutput '""' config.value.string ./types-anything/equal-atoms.nix
+checkConfigOutput / config.value.path ./types-anything/equal-atoms.nix
+checkConfigOutput null config.value.null ./types-anything/equal-atoms.nix
+checkConfigOutput 0.1 config.value.float ./types-anything/equal-atoms.nix
+# Functions can't be merged together
+checkConfigError "The option .* has conflicting definitions" config.value.multiple-lambdas ./types-anything/functions.nix
+checkConfigOutput '<LAMBDA>' config.value.single-lambda ./types-anything/functions.nix
+# Check that all mk* modifiers are applied
+checkConfigError 'attribute .* not found' config.value.mkiffalse ./types-anything/mk-mods.nix
+checkConfigOutput '{ }' config.value.mkiftrue ./types-anything/mk-mods.nix
+checkConfigOutput 1 config.value.mkdefault ./types-anything/mk-mods.nix
+checkConfigOutput '{ }' config.value.mkmerge ./types-anything/mk-mods.nix
+checkConfigOutput true config.value.mkbefore ./types-anything/mk-mods.nix
+checkConfigOutput 1 config.value.nested.foo ./types-anything/mk-mods.nix
+checkConfigOutput baz config.value.nested.bar.baz ./types-anything/mk-mods.nix
+
cat <<EOF
====== module tests ======
$pass Pass
diff --git a/lib/tests/modules/types-anything/attrs-coercible.nix b/lib/tests/modules/types-anything/attrs-coercible.nix
new file mode 100644
index 000000000000..085cbd638f17
--- /dev/null
+++ b/lib/tests/modules/types-anything/attrs-coercible.nix
@@ -0,0 +1,12 @@
+{ lib, ... }: {
+
+ options.value = lib.mkOption {
+ type = lib.types.anything;
+ };
+
+ config.value = {
+ outPath = "foo";
+ err = throw "err";
+ };
+
+}
diff --git a/lib/tests/modules/types-anything/equal-atoms.nix b/lib/tests/modules/types-anything/equal-atoms.nix
new file mode 100644
index 000000000000..972711201a09
--- /dev/null
+++ b/lib/tests/modules/types-anything/equal-atoms.nix
@@ -0,0 +1,26 @@
+{ lib, ... }: {
+
+ options.value = lib.mkOption {
+ type = lib.types.anything;
+ };
+
+ config = lib.mkMerge [
+ {
+ value.int = 0;
+ value.bool = false;
+ value.string = "";
+ value.path = /.;
+ value.null = null;
+ value.float = 0.1;
+ }
+ {
+ value.int = 0;
+ value.bool = false;
+ value.string = "";
+ value.path = /.;
+ value.null = null;
+ value.float = 0.1;
+ }
+ ];
+
+}
diff --git a/lib/tests/modules/types-anything/functions.nix b/lib/tests/modules/types-anything/functions.nix
new file mode 100644
index 000000000000..079518913918
--- /dev/null
+++ b/lib/tests/modules/types-anything/functions.nix
@@ -0,0 +1,17 @@
+{ lib, ... }: {
+
+ options.value = lib.mkOption {
+ type = lib.types.anything;
+ };
+
+ config = lib.mkMerge [
+ {
+ value.single-lambda = x: x;
+ value.multiple-lambdas = x: x;
+ }
+ {
+ value.multiple-lambdas = x: x;
+ }
+ ];
+
+}
diff --git a/lib/tests/modules/types-anything/lists.nix b/lib/tests/modules/types-anything/lists.nix
new file mode 100644
index 000000000000..bd846afd3d18
--- /dev/null
+++ b/lib/tests/modules/types-anything/lists.nix
@@ -0,0 +1,16 @@
+{ lib, ... }: {
+
+ options.value = lib.mkOption {
+ type = lib.types.anything;
+ };
+
+ config = lib.mkMerge [
+ {
+ value = [ null ];
+ }
+ {
+ value = [ null ];
+ }
+ ];
+
+}
diff --git a/lib/tests/modules/types-anything/mk-mods.nix b/lib/tests/modules/types-anything/mk-mods.nix
new file mode 100644
index 000000000000..f84ad01df017
--- /dev/null
+++ b/lib/tests/modules/types-anything/mk-mods.nix
@@ -0,0 +1,44 @@
+{ lib, ... }: {
+
+ options.value = lib.mkOption {
+ type = lib.types.anything;
+ };
+
+ config = lib.mkMerge [
+ {
+ value.mkiffalse = lib.mkIf false {};
+ }
+ {
+ value.mkiftrue = lib.mkIf true {};
+ }
+ {
+ value.mkdefault = lib.mkDefault 0;
+ }
+ {
+ value.mkdefault = 1;
+ }
+ {
+ value.mkmerge = lib.mkMerge [
+ {}
+ ];
+ }
+ {
+ value.mkbefore = lib.mkBefore true;
+ }
+ {
+ value.nested = lib.mkMerge [
+ {
+ foo = lib.mkDefault 0;
+ bar = lib.mkIf false 0;
+ }
+ (lib.mkIf true {
+ foo = lib.mkIf true (lib.mkForce 1);
+ bar = {
+ baz = lib.mkDefault "baz";
+ };
+ })
+ ];
+ }
+ ];
+
+}
diff --git a/lib/tests/modules/types-anything/nested-attrs.nix b/lib/tests/modules/types-anything/nested-attrs.nix
new file mode 100644
index 000000000000..e57d33ef8717
--- /dev/null
+++ b/lib/tests/modules/types-anything/nested-attrs.nix
@@ -0,0 +1,22 @@
+{ lib, ... }: {
+
+ options.value = lib.mkOption {
+ type = lib.types.anything;
+ };
+
+ config = lib.mkMerge [
+ {
+ value.foo = null;
+ }
+ {
+ value.l1.foo = null;
+ }
+ {
+ value.l1.l2.foo = null;
+ }
+ {
+ value.l1.l2.l3.foo = null;
+ }
+ ];
+
+}