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 = {
|
exampleFiles = {
|
||||||
example =
|
name = "examples";
|
||||||
|
cases =
|
||||||
let
|
let
|
||||||
config = import ../example.nix { inherit pkgs; };
|
config = import ../example.nix { inherit pkgs; };
|
||||||
in
|
in
|
||||||
builtins.removeAttrs config.programs.nixvim [
|
[
|
||||||
# This is not available to standalone modules, only HM & NixOS Modules
|
{
|
||||||
"enable"
|
name = "main";
|
||||||
# This is purely an example, it does not reflect a real usage
|
case = builtins.removeAttrs config.programs.nixvim [
|
||||||
"extraConfigLua"
|
# This is not available to standalone modules, only HM & NixOS Modules
|
||||||
"extraConfigVim"
|
"enable"
|
||||||
|
# This is purely an example, it does not reflect a real usage
|
||||||
|
"extraConfigLua"
|
||||||
|
"extraConfigVim"
|
||||||
|
];
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
# We attempt to build & execute all configurations
|
# We attempt to build & execute all configurations
|
||||||
derivationList = pkgs.lib.mapAttrsToList (name: def: {
|
derivationList = builtins.map (
|
||||||
inherit name;
|
{ name, cases }:
|
||||||
path = mkTestDerivationFromNixvimModule {
|
let
|
||||||
inherit name;
|
# The test case can either be the actual definition,
|
||||||
# The module can either be the actual definition,
|
|
||||||
# or a child attr named `module`.
|
# or a child attr named `module`.
|
||||||
module = def.module or (lib.removeAttrs def [ "tests" ]);
|
prepareModule = case: case.module or (lib.removeAttrs case [ "tests" ]);
|
||||||
dontRun = def.tests.dontRun or false;
|
dontRunModule = case: case.tests.dontRun or false;
|
||||||
pkgs = pkgsUnfree;
|
in
|
||||||
};
|
{
|
||||||
}) (testFiles // exampleFiles);
|
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
|
in
|
||||||
pkgs.linkFarm "nixvim-tests" derivationList
|
pkgs.linkFarm "nixvim-tests" derivationList
|
||||||
|
|
|
@ -62,13 +62,10 @@ let
|
||||||
# handled by mkTestDerivation
|
# handled by mkTestDerivation
|
||||||
handleTestFile =
|
handleTestFile =
|
||||||
{ namespace, cases }:
|
{ namespace, cases }:
|
||||||
lib.attrsets.mapAttrs' (case: config: {
|
{
|
||||||
name = lib.strings.concatStringsSep "-" (namespace ++ [ case ]);
|
name = lib.strings.concatStringsSep "-" namespace;
|
||||||
value = config;
|
cases = lib.mapAttrsToList (name: case: { inherit case name; }) cases;
|
||||||
}) cases;
|
};
|
||||||
|
|
||||||
# Helper function that calls `//` for each attrset of a list
|
|
||||||
concatMany = lib.lists.foldr lib.mergeAttrs { };
|
|
||||||
in
|
in
|
||||||
# An attrset of 'test-name' -> 'test-config'
|
# A list of the form [ { name = "..."; modules = [ /* test cases */ ]; } ]
|
||||||
concatMany (builtins.map handleTestFile testsListEvaluated)
|
builtins.map handleTestFile testsListEvaluated
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue