mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
tests: Reduce the number of calls to mkTestDerivationFromNixvimModule
This commit is contained in:
parent
71126bfebe
commit
50d865275d
2 changed files with 44 additions and 26 deletions
|
@ -17,30 +17,51 @@ let
|
|||
};
|
||||
|
||||
exampleFiles = {
|
||||
example =
|
||||
name = "examples";
|
||||
cases =
|
||||
let
|
||||
config = import ../example.nix { inherit pkgs; };
|
||||
in
|
||||
builtins.removeAttrs config.programs.nixvim [
|
||||
# This is not available to standalone modules, only HM & NixOS Modules
|
||||
"enable"
|
||||
# This is purely an example, it does not reflect a real usage
|
||||
"extraConfigLua"
|
||||
"extraConfigVim"
|
||||
[
|
||||
{
|
||||
name = "main";
|
||||
case = builtins.removeAttrs config.programs.nixvim [
|
||||
# This is not available to standalone modules, only HM & NixOS Modules
|
||||
"enable"
|
||||
# This is purely an example, it does not reflect a real usage
|
||||
"extraConfigLua"
|
||||
"extraConfigVim"
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# We attempt to build & execute all configurations
|
||||
derivationList = pkgs.lib.mapAttrsToList (name: def: {
|
||||
inherit name;
|
||||
path = mkTestDerivationFromNixvimModule {
|
||||
inherit name;
|
||||
# The module can either be the actual definition,
|
||||
derivationList = builtins.map (
|
||||
{ name, cases }:
|
||||
let
|
||||
# The test case can either be the actual definition,
|
||||
# or a child attr named `module`.
|
||||
module = def.module or (lib.removeAttrs def [ "tests" ]);
|
||||
dontRun = def.tests.dontRun or false;
|
||||
pkgs = pkgsUnfree;
|
||||
};
|
||||
}) (testFiles // exampleFiles);
|
||||
prepareModule = case: case.module or (lib.removeAttrs case [ "tests" ]);
|
||||
dontRunModule = case: case.tests.dontRun or false;
|
||||
in
|
||||
{
|
||||
inherit name;
|
||||
path = mkTestDerivationFromNixvimModule {
|
||||
inherit name;
|
||||
tests = builtins.map (
|
||||
{ name, case }:
|
||||
{
|
||||
inherit name;
|
||||
module = prepareModule case;
|
||||
dontRun = dontRunModule case;
|
||||
}
|
||||
) cases;
|
||||
# Use the global dontRun only if we don't have a list of modules
|
||||
dontRun = dontRunModule cases;
|
||||
pkgs = pkgsUnfree;
|
||||
};
|
||||
}
|
||||
) (testFiles ++ [ exampleFiles ]);
|
||||
in
|
||||
pkgs.linkFarm "nixvim-tests" derivationList
|
||||
|
|
|
@ -62,13 +62,10 @@ let
|
|||
# handled by mkTestDerivation
|
||||
handleTestFile =
|
||||
{ namespace, cases }:
|
||||
lib.attrsets.mapAttrs' (case: config: {
|
||||
name = lib.strings.concatStringsSep "-" (namespace ++ [ case ]);
|
||||
value = config;
|
||||
}) cases;
|
||||
|
||||
# Helper function that calls `//` for each attrset of a list
|
||||
concatMany = lib.lists.foldr lib.mergeAttrs { };
|
||||
{
|
||||
name = lib.strings.concatStringsSep "-" namespace;
|
||||
cases = lib.mapAttrsToList (name: case: { inherit case name; }) cases;
|
||||
};
|
||||
in
|
||||
# An attrset of 'test-name' -> 'test-config'
|
||||
concatMany (builtins.map handleTestFile testsListEvaluated)
|
||||
# A list of the form [ { name = "..."; modules = [ /* test cases */ ]; } ]
|
||||
builtins.map handleTestFile testsListEvaluated
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue