nix-community.nixvim/tests/default.nix

87 lines
2.1 KiB
Nix
Raw Normal View History

2023-03-22 07:42:02 +01:00
{
makeNixvimWithModule,
lib ? pkgs.lib,
helpers,
2023-03-22 07:42:02 +01:00
pkgs,
pkgsUnfree,
2024-05-05 19:39:35 +02:00
}:
let
2023-03-22 07:42:02 +01:00
fetchTests = import ./fetch-tests.nix;
test-derivation = import ./test-derivation.nix { inherit pkgs lib makeNixvimWithModule; };
inherit (test-derivation) mkTestDerivationFromNixvimModule;
2023-03-22 07:42:02 +01:00
# List of files containing configurations
testFiles = fetchTests {
inherit lib pkgs helpers;
2023-03-22 07:42:02 +01:00
root = ./test-sources;
};
exampleFiles = {
name = "examples";
cases =
2024-05-05 19:39:35 +02:00
let
config = import ../example.nix { inherit pkgs; };
in
[
{
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"
];
}
];
};
in
# We attempt to build & execute all configurations
lib.pipe (testFiles ++ [ exampleFiles ]) [
(builtins.map (
file:
let
# The test case can either be the actual definition,
# or a child attr named `module`.
prepareModule =
case: if lib.isFunction case then case else case.module or (lib.removeAttrs case [ "tests" ]);
# Convert legacy `dontRun` definitions into `test.runNvim` option defs
dontRunModule =
case:
let
dontRun = case.tests.dontRun or false;
in
lib.optionalAttrs dontRun { test.runNvim = false; };
mkTest =
{ name, case }:
{
inherit name;
path = mkTestDerivationFromNixvimModule {
inherit name;
module = {
imports = [
(dontRunModule case)
(prepareModule case)
];
};
pkgs = pkgsUnfree;
};
};
in
{
inherit (file) name;
path = pkgs.linkFarm file.name (builtins.map mkTest file.cases);
}
))
(helpers.groupListBySize 10)
(lib.imap1 (
i: group: rec {
name = "test-${toString i}";
value = pkgs.linkFarm name group;
}
))
builtins.listToAttrs
]