mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
tests: simplify fetch-tests slightly
Simplify by reducing the number of transformations done to the test-files' test-case modules attr. Since `pkgs.linkFarm` can accept _either_ a list or an attrset, we don't need to transform the attrset into a list.
This commit is contained in:
parent
1c879ec3aa
commit
975af6a498
2 changed files with 23 additions and 30 deletions
|
@ -9,14 +9,11 @@ let
|
|||
test-derivation = import ../lib/tests.nix { inherit pkgs lib; };
|
||||
inherit (test-derivation) mkTestDerivationFromNixvimModule;
|
||||
|
||||
mkTest =
|
||||
{ name, module }:
|
||||
{
|
||||
inherit name;
|
||||
path = mkTestDerivationFromNixvimModule {
|
||||
inherit name module;
|
||||
pkgs = pkgsUnfree;
|
||||
};
|
||||
moduleToTest =
|
||||
name: module:
|
||||
mkTestDerivationFromNixvimModule {
|
||||
inherit name module;
|
||||
pkgs = pkgsUnfree;
|
||||
};
|
||||
|
||||
# List of files containing configurations
|
||||
|
@ -27,29 +24,27 @@ let
|
|||
|
||||
exampleFiles = {
|
||||
name = "examples";
|
||||
modules =
|
||||
file = ../example.nix;
|
||||
cases =
|
||||
let
|
||||
config = import ../example.nix { inherit pkgs; };
|
||||
in
|
||||
[
|
||||
{
|
||||
name = "main";
|
||||
module = 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"
|
||||
];
|
||||
}
|
||||
];
|
||||
{
|
||||
main = 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"
|
||||
];
|
||||
};
|
||||
};
|
||||
in
|
||||
# We attempt to build & execute all configurations
|
||||
lib.pipe (testFiles ++ [ exampleFiles ]) [
|
||||
(builtins.map (file: {
|
||||
inherit (file) name;
|
||||
path = pkgs.linkFarm file.name (builtins.map mkTest file.modules);
|
||||
path = pkgs.linkFarm file.name (builtins.mapAttrs moduleToTest file.cases);
|
||||
}))
|
||||
(helpers.groupListBySize 10)
|
||||
(lib.imap1 (
|
||||
|
|
|
@ -5,26 +5,25 @@
|
|||
helpers,
|
||||
}:
|
||||
let
|
||||
# Import a test file into the form { name = ""; file = ""; modules = []; }
|
||||
# Import a test file into the form { name = ""; file = ""; cases = {}; }
|
||||
handleTestFile =
|
||||
file: namespace:
|
||||
let
|
||||
fnOrAttrs = import file;
|
||||
in
|
||||
{
|
||||
inherit file;
|
||||
name = lib.strings.concatStringsSep "-" namespace;
|
||||
cases =
|
||||
if builtins.isFunction fnOrAttrs then
|
||||
# Call the function
|
||||
fnOrAttrs { inherit pkgs lib helpers; }
|
||||
else
|
||||
fnOrAttrs;
|
||||
in
|
||||
{
|
||||
inherit file;
|
||||
name = lib.strings.concatStringsSep "-" namespace;
|
||||
modules = lib.mapAttrsToList (name: module: { inherit name module; }) cases;
|
||||
};
|
||||
|
||||
# Recurse into all directories, extracting files as we find them.
|
||||
# This returns a list of { name; file; modules; } attrsets.
|
||||
# This returns a list of { name; file; cases; } attrsets.
|
||||
fetchTests =
|
||||
path: namespace:
|
||||
let
|
||||
|
@ -50,5 +49,4 @@ let
|
|||
builtins.concatLists
|
||||
];
|
||||
in
|
||||
# A list of the form [ { name = "..."; modules = [ /* test case modules */ ]; } ]
|
||||
fetchTests root [ ]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue