about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorNikolay Amiantov2017-02-02 01:52:40 +0300
committerNikolay Amiantov2017-02-02 01:53:00 +0300
commitfcb20b9feecb33c60d15a98766f7fd1bfbeae13e (patch)
treecf931d81c3ce283925cde26274ccfcd0f21bafeb /lib
parent5cbcd3af69d859a6d919ad26261c57649e9c888f (diff)
module tests: add tests for coercedTo
Diffstat (limited to 'lib')
-rwxr-xr-xlib/tests/modules.sh5
-rw-r--r--lib/tests/modules/declare-coerced-value.nix10
-rw-r--r--lib/tests/modules/define-value-list.nix3
-rw-r--r--lib/tests/modules/define-value-string.nix3
4 files changed, 21 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 65de8e378c7e..e0774383720b 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -115,6 +115,11 @@ set -- config.enable ./declare-enable.nix ./define-enable.nix ./define-loaOfSub-
 checkConfigError 'The option .* defined in .* does not exist.' "$@"
 checkConfigOutput "true" "$@" ./define-module-check.nix
 
+# Check coerced value.
+checkConfigOutput "\"42\"" config.value ./declare-coerced-value.nix
+checkConfigOutput "\"24\"" config.value ./declare-coerced-value.nix ./define-value-string.nix
+checkConfigError 'The option value .* in .* is not a coercedTo.' config.value ./declare-coerced-value.nix ./define-value-list.nix
+
 cat <<EOF
 ====== module tests ======
 $pass Pass
diff --git a/lib/tests/modules/declare-coerced-value.nix b/lib/tests/modules/declare-coerced-value.nix
new file mode 100644
index 000000000000..76b12ad53f00
--- /dev/null
+++ b/lib/tests/modules/declare-coerced-value.nix
@@ -0,0 +1,10 @@
+{ lib, ... }:
+
+{
+  options = {
+    value = lib.mkOption {
+      default = 42;
+      type = lib.types.coercedTo lib.types.int builtins.toString lib.types.str;
+    };
+  };
+}
diff --git a/lib/tests/modules/define-value-list.nix b/lib/tests/modules/define-value-list.nix
new file mode 100644
index 000000000000..4831c1cc09ba
--- /dev/null
+++ b/lib/tests/modules/define-value-list.nix
@@ -0,0 +1,3 @@
+{
+  value = [];
+}
diff --git a/lib/tests/modules/define-value-string.nix b/lib/tests/modules/define-value-string.nix
new file mode 100644
index 000000000000..e7a166965a7a
--- /dev/null
+++ b/lib/tests/modules/define-value-string.nix
@@ -0,0 +1,3 @@
+{
+  value = "24";
+}