lol

lib/tests: More functionTo tests

+117 -31
+6 -2
lib/tests/modules.sh
··· 262 262 checkConfigOutput 1 config.value.nested.foo ./types-anything/mk-mods.nix 263 263 checkConfigOutput baz config.value.nested.bar.baz ./types-anything/mk-mods.nix 264 264 265 - # Check the merge behaviour of the functionTo type. 266 - checkConfigOutput "a b" config.result ./functionTo.nix 265 + ## types.functionTo 266 + checkConfigOutput "input is input" config.result ./functionTo/trivial.nix 267 + checkConfigOutput "a b" config.result ./functionTo/merging-list.nix 268 + 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 269 + checkConfigOutput "b a" config.result ./functionTo/list-order.nix 270 + checkConfigOutput "a c" config.result ./functionTo/merging-attrs.nix 267 271 268 272 cat <<EOF 269 273 ====== module tests ======
-29
lib/tests/modules/functionTo.nix
··· 1 - { lib, config, ... }: 2 - 3 - with lib; 4 - 5 - { 6 - options = { 7 - selector = mkOption { 8 - default = _pkgs : []; 9 - type = with types; functionTo (listOf str); 10 - description = '' 11 - Some descriptive text 12 - ''; 13 - }; 14 - 15 - result = mkOption { 16 - type = types.str; 17 - default = toString (config.selector { 18 - a = "a"; 19 - b = "b"; 20 - c = "c"; 21 - }); 22 - }; 23 - }; 24 - 25 - config = lib.mkMerge [ 26 - { selector = pkgs: [ pkgs.a ]; } 27 - { selector = pkgs: [ pkgs.b ]; } 28 - ]; 29 - }
+25
lib/tests/modules/functionTo/list-order.nix
··· 1 + 2 + { lib, config, ... }: 3 + let 4 + inherit (lib) types; 5 + in { 6 + options = { 7 + fun = lib.mkOption { 8 + type = types.functionTo (types.listOf types.str); 9 + }; 10 + 11 + result = lib.mkOption { 12 + type = types.str; 13 + default = toString (config.fun { 14 + a = "a"; 15 + b = "b"; 16 + c = "c"; 17 + }); 18 + }; 19 + }; 20 + 21 + config.fun = lib.mkMerge [ 22 + (input: lib.mkAfter [ input.a ]) 23 + (input: [ input.b ]) 24 + ]; 25 + }
+27
lib/tests/modules/functionTo/merging-attrs.nix
··· 1 + { lib, config, ... }: 2 + let 3 + inherit (lib) types; 4 + in { 5 + options = { 6 + fun = lib.mkOption { 7 + type = types.functionTo (types.attrsOf types.str); 8 + }; 9 + 10 + result = lib.mkOption { 11 + type = types.str; 12 + default = toString (lib.attrValues (config.fun { 13 + a = "a"; 14 + b = "b"; 15 + c = "c"; 16 + })); 17 + }; 18 + }; 19 + 20 + config.fun = lib.mkMerge [ 21 + (input: { inherit (input) a; }) 22 + (input: { inherit (input) b; }) 23 + (input: { 24 + b = lib.mkForce input.c; 25 + }) 26 + ]; 27 + }
+24
lib/tests/modules/functionTo/merging-list.nix
··· 1 + { lib, config, ... }: 2 + let 3 + inherit (lib) types; 4 + in { 5 + options = { 6 + fun = lib.mkOption { 7 + type = types.functionTo (types.listOf types.str); 8 + }; 9 + 10 + result = lib.mkOption { 11 + type = types.str; 12 + default = toString (config.fun { 13 + a = "a"; 14 + b = "b"; 15 + c = "c"; 16 + }); 17 + }; 18 + }; 19 + 20 + config.fun = lib.mkMerge [ 21 + (input: [ input.a ]) 22 + (input: [ input.b ]) 23 + ]; 24 + }
+17
lib/tests/modules/functionTo/trivial.nix
··· 1 + { lib, config, ... }: 2 + let 3 + inherit (lib) types; 4 + in { 5 + options = { 6 + fun = lib.mkOption { 7 + type = types.functionTo types.str; 8 + }; 9 + 10 + result = lib.mkOption { 11 + type = types.str; 12 + default = config.fun "input"; 13 + }; 14 + }; 15 + 16 + config.fun = input: "input is ${input}"; 17 + }
+18
lib/tests/modules/functionTo/wrong-type.nix
··· 1 + 2 + { lib, config, ... }: 3 + let 4 + inherit (lib) types; 5 + in { 6 + options = { 7 + fun = lib.mkOption { 8 + type = types.functionTo types.str; 9 + }; 10 + 11 + result = lib.mkOption { 12 + type = types.str; 13 + default = config.fun 0; 14 + }; 15 + }; 16 + 17 + config.fun = input: input + 1; 18 + }