summary refs log tree commit diff
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2021-10-15 16:48:38 +0200
committerSilvan Mosberger <contact@infinisil.com>2022-02-17 18:48:30 +0100
commitb333395be54397a62e6befe2bc91664f53306b41 (patch)
tree77b123f84b9a0d9bf0c46412080be8e8130a7360
parent382289027f92ff3973f14d983a55b183c9b1c0bd (diff)
downloadnixpkgs-b333395be54397a62e6befe2bc91664f53306b41.tar
nixpkgs-b333395be54397a62e6befe2bc91664f53306b41.tar.gz
nixpkgs-b333395be54397a62e6befe2bc91664f53306b41.tar.bz2
nixpkgs-b333395be54397a62e6befe2bc91664f53306b41.tar.lz
nixpkgs-b333395be54397a62e6befe2bc91664f53306b41.tar.xz
nixpkgs-b333395be54397a62e6befe2bc91664f53306b41.tar.zst
nixpkgs-b333395be54397a62e6befe2bc91664f53306b41.zip
lib/tests: Add tests for emptyValue
-rwxr-xr-xlib/tests/modules.sh9
-rw-r--r--lib/tests/modules/emptyValues.nix36
2 files changed, 45 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 590937da5b8..88d152d3935 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -284,6 +284,15 @@ checkConfigOutput '^"a b"$' config.resultFoo ./declare-variants.nix ./define-var
 checkConfigOutput '^"a y z"$' config.resultFooBar ./declare-variants.nix ./define-variant.nix
 checkConfigOutput '^"a b c"$' config.resultFooFoo ./declare-variants.nix ./define-variant.nix
 
+## emptyValue's
+checkConfigOutput "[ ]" config.list.a ./emptyValues.nix
+checkConfigOutput "{ }" config.attrs.a ./emptyValues.nix
+checkConfigOutput "null" config.null.a ./emptyValues.nix
+checkConfigOutput "{ }" config.submodule.a ./emptyValues.nix
+# These types don't have empty values
+checkConfigError 'The option .int.a. is used but not defined' config.int.a ./emptyValues.nix
+checkConfigError 'The option .nonEmptyList.a. is used but not defined' config.nonEmptyList.a ./emptyValues.nix
+
 cat <<EOF
 ====== module tests ======
 $pass Pass
diff --git a/lib/tests/modules/emptyValues.nix b/lib/tests/modules/emptyValues.nix
new file mode 100644
index 00000000000..77825de3281
--- /dev/null
+++ b/lib/tests/modules/emptyValues.nix
@@ -0,0 +1,36 @@
+{ lib, ... }:
+let
+  inherit (lib) types;
+in {
+
+  options = {
+    int = lib.mkOption {
+      type = types.lazyAttrsOf types.int;
+    };
+    list = lib.mkOption {
+      type = types.lazyAttrsOf (types.listOf types.int);
+    };
+    nonEmptyList = lib.mkOption {
+      type = types.lazyAttrsOf (types.nonEmptyListOf types.int);
+    };
+    attrs = lib.mkOption {
+      type = types.lazyAttrsOf (types.attrsOf types.int);
+    };
+    null = lib.mkOption {
+      type = types.lazyAttrsOf (types.nullOr types.int);
+    };
+    submodule = lib.mkOption {
+      type = types.lazyAttrsOf (types.submodule {});
+    };
+  };
+
+  config = {
+    int.a = lib.mkIf false null;
+    list.a = lib.mkIf false null;
+    nonEmptyList.a = lib.mkIf false null;
+    attrs.a = lib.mkIf false null;
+    null.a = lib.mkIf false null;
+    submodule.a = lib.mkIf false null;
+  };
+
+}