lib/tests: Add tests for emptyValue

Changed files
+45
lib
tests
+9
lib/tests/modules.sh
···
checkConfigOutput '^"a y z"$' config.resultFooBar ./declare-variants.nix ./define-variant.nix
checkConfigOutput '^"a b c"$' config.resultFooFoo ./declare-variants.nix ./define-variant.nix
cat <<EOF
====== module tests ======
$pass Pass
···
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
+36
lib/tests/modules/emptyValues.nix
···
···
+
{ 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;
+
};
+
+
}