mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-23 01:08:43 +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; };
|
test-derivation = import ../lib/tests.nix { inherit pkgs lib; };
|
||||||
inherit (test-derivation) mkTestDerivationFromNixvimModule;
|
inherit (test-derivation) mkTestDerivationFromNixvimModule;
|
||||||
|
|
||||||
mkTest =
|
moduleToTest =
|
||||||
{ name, module }:
|
name: module:
|
||||||
{
|
mkTestDerivationFromNixvimModule {
|
||||||
inherit name;
|
inherit name module;
|
||||||
path = mkTestDerivationFromNixvimModule {
|
pkgs = pkgsUnfree;
|
||||||
inherit name module;
|
|
||||||
pkgs = pkgsUnfree;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# List of files containing configurations
|
# List of files containing configurations
|
||||||
|
@ -27,29 +24,27 @@ let
|
||||||
|
|
||||||
exampleFiles = {
|
exampleFiles = {
|
||||||
name = "examples";
|
name = "examples";
|
||||||
modules =
|
file = ../example.nix;
|
||||||
|
cases =
|
||||||
let
|
let
|
||||||
config = import ../example.nix { inherit pkgs; };
|
config = import ../example.nix { inherit pkgs; };
|
||||||
in
|
in
|
||||||
[
|
{
|
||||||
{
|
main = builtins.removeAttrs config.programs.nixvim [
|
||||||
name = "main";
|
# This is not available to standalone modules, only HM & NixOS Modules
|
||||||
module = builtins.removeAttrs config.programs.nixvim [
|
"enable"
|
||||||
# This is not available to standalone modules, only HM & NixOS Modules
|
# This is purely an example, it does not reflect a real usage
|
||||||
"enable"
|
"extraConfigLua"
|
||||||
# This is purely an example, it does not reflect a real usage
|
"extraConfigVim"
|
||||||
"extraConfigLua"
|
];
|
||||||
"extraConfigVim"
|
};
|
||||||
];
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
# We attempt to build & execute all configurations
|
# We attempt to build & execute all configurations
|
||||||
lib.pipe (testFiles ++ [ exampleFiles ]) [
|
lib.pipe (testFiles ++ [ exampleFiles ]) [
|
||||||
(builtins.map (file: {
|
(builtins.map (file: {
|
||||||
inherit (file) name;
|
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)
|
(helpers.groupListBySize 10)
|
||||||
(lib.imap1 (
|
(lib.imap1 (
|
||||||
|
|
|
@ -5,26 +5,25 @@
|
||||||
helpers,
|
helpers,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
# Import a test file into the form { name = ""; file = ""; modules = []; }
|
# Import a test file into the form { name = ""; file = ""; cases = {}; }
|
||||||
handleTestFile =
|
handleTestFile =
|
||||||
file: namespace:
|
file: namespace:
|
||||||
let
|
let
|
||||||
fnOrAttrs = import file;
|
fnOrAttrs = import file;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit file;
|
||||||
|
name = lib.strings.concatStringsSep "-" namespace;
|
||||||
cases =
|
cases =
|
||||||
if builtins.isFunction fnOrAttrs then
|
if builtins.isFunction fnOrAttrs then
|
||||||
# Call the function
|
# Call the function
|
||||||
fnOrAttrs { inherit pkgs lib helpers; }
|
fnOrAttrs { inherit pkgs lib helpers; }
|
||||||
else
|
else
|
||||||
fnOrAttrs;
|
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.
|
# 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 =
|
fetchTests =
|
||||||
path: namespace:
|
path: namespace:
|
||||||
let
|
let
|
||||||
|
@ -50,5 +49,4 @@ let
|
||||||
builtins.concatLists
|
builtins.concatLists
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
# A list of the form [ { name = "..."; modules = [ /* test case modules */ ]; } ]
|
|
||||||
fetchTests root [ ]
|
fetchTests root [ ]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue