lib/tests: More functionTo tests

+6 -2
lib/tests/modules.sh
···
checkConfigOutput 1 config.value.nested.foo ./types-anything/mk-mods.nix
checkConfigOutput baz config.value.nested.bar.baz ./types-anything/mk-mods.nix
-
# Check the merge behaviour of the functionTo type.
-
checkConfigOutput "a b" config.result ./functionTo.nix
+
## types.functionTo
+
checkConfigOutput "input is input" config.result ./functionTo/trivial.nix
+
checkConfigOutput "a b" config.result ./functionTo/merging-list.nix
+
checkConfigError 'A definition for option .fun.\[function body\]. is not of type .string.. Definition values:\n- In .*wrong-type.nix' config.result ./functionTo/wrong-type.nix
+
checkConfigOutput "b a" config.result ./functionTo/list-order.nix
+
checkConfigOutput "a c" config.result ./functionTo/merging-attrs.nix
cat <<EOF
====== module tests ======
-29
lib/tests/modules/functionTo.nix
···
-
{ lib, config, ... }:
-
-
with lib;
-
-
{
-
options = {
-
selector = mkOption {
-
default = _pkgs : [];
-
type = with types; functionTo (listOf str);
-
description = ''
-
Some descriptive text
-
'';
-
};
-
-
result = mkOption {
-
type = types.str;
-
default = toString (config.selector {
-
a = "a";
-
b = "b";
-
c = "c";
-
});
-
};
-
};
-
-
config = lib.mkMerge [
-
{ selector = pkgs: [ pkgs.a ]; }
-
{ selector = pkgs: [ pkgs.b ]; }
-
];
-
}
+25
lib/tests/modules/functionTo/list-order.nix
···
+
+
{ lib, config, ... }:
+
let
+
inherit (lib) types;
+
in {
+
options = {
+
fun = lib.mkOption {
+
type = types.functionTo (types.listOf types.str);
+
};
+
+
result = lib.mkOption {
+
type = types.str;
+
default = toString (config.fun {
+
a = "a";
+
b = "b";
+
c = "c";
+
});
+
};
+
};
+
+
config.fun = lib.mkMerge [
+
(input: lib.mkAfter [ input.a ])
+
(input: [ input.b ])
+
];
+
}
+27
lib/tests/modules/functionTo/merging-attrs.nix
···
+
{ lib, config, ... }:
+
let
+
inherit (lib) types;
+
in {
+
options = {
+
fun = lib.mkOption {
+
type = types.functionTo (types.attrsOf types.str);
+
};
+
+
result = lib.mkOption {
+
type = types.str;
+
default = toString (lib.attrValues (config.fun {
+
a = "a";
+
b = "b";
+
c = "c";
+
}));
+
};
+
};
+
+
config.fun = lib.mkMerge [
+
(input: { inherit (input) a; })
+
(input: { inherit (input) b; })
+
(input: {
+
b = lib.mkForce input.c;
+
})
+
];
+
}
+24
lib/tests/modules/functionTo/merging-list.nix
···
+
{ lib, config, ... }:
+
let
+
inherit (lib) types;
+
in {
+
options = {
+
fun = lib.mkOption {
+
type = types.functionTo (types.listOf types.str);
+
};
+
+
result = lib.mkOption {
+
type = types.str;
+
default = toString (config.fun {
+
a = "a";
+
b = "b";
+
c = "c";
+
});
+
};
+
};
+
+
config.fun = lib.mkMerge [
+
(input: [ input.a ])
+
(input: [ input.b ])
+
];
+
}
+17
lib/tests/modules/functionTo/trivial.nix
···
+
{ lib, config, ... }:
+
let
+
inherit (lib) types;
+
in {
+
options = {
+
fun = lib.mkOption {
+
type = types.functionTo types.str;
+
};
+
+
result = lib.mkOption {
+
type = types.str;
+
default = config.fun "input";
+
};
+
};
+
+
config.fun = input: "input is ${input}";
+
}
+18
lib/tests/modules/functionTo/wrong-type.nix
···
+
+
{ lib, config, ... }:
+
let
+
inherit (lib) types;
+
in {
+
options = {
+
fun = lib.mkOption {
+
type = types.functionTo types.str;
+
};
+
+
result = lib.mkOption {
+
type = types.str;
+
default = config.fun 0;
+
};
+
};
+
+
config.fun = input: input + 1;
+
}