lib/tests: More functionTo tests
This commit is contained in:
parent
e9101d4a3b
commit
c2f3556dc7
@ -262,8 +262,12 @@ 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
|
||||
|
||||
# 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 ======
|
||||
|
@ -1,29 +0,0 @@
|
||||
{ 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
Normal file
25
lib/tests/modules/functionTo/list-order.nix
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
{ 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
Normal file
27
lib/tests/modules/functionTo/merging-attrs.nix
Normal file
@ -0,0 +1,27 @@
|
||||
{ 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
Normal file
24
lib/tests/modules/functionTo/merging-list.nix
Normal file
@ -0,0 +1,24 @@
|
||||
{ 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
Normal file
17
lib/tests/modules/functionTo/trivial.nix
Normal file
@ -0,0 +1,17 @@
|
||||
{ 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
Normal file
18
lib/tests/modules/functionTo/wrong-type.nix
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
{ 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user