mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-21 17:59:41 +01:00
Simplify the `enableExceptInTests` attribute, removing the `_nixvimTests` argument. We now do a full re-eval of the nixvim configuration before building the test, giving us a central place to implement `enableExceptInTests` and its eventual replacement(s). This extends support for `enableExceptInTests` to all methods of getting a nixvim test derivation. Previously, it only worked when using `mkTestDerivationFromNixvimModule`. In `tests/main.nix`, we avoid the re-eval by doing the initial eval with a "test mode" lib from the start.
89 lines
2 KiB
Nix
89 lines
2 KiB
Nix
# Collects the various test modules in tests/test-sources/ and groups them into a number of test derivations
|
|
{
|
|
callTest,
|
|
lib ? pkgs.lib,
|
|
linkFarm,
|
|
pkgs,
|
|
pkgsForTest,
|
|
}:
|
|
let
|
|
fetchTests = callTest ./fetch-tests.nix { };
|
|
|
|
# Avoid `build.test` re-evaluating its nixvim configuration by providing a
|
|
# "test mode" lib from the start
|
|
testLib = lib.extend (
|
|
final: prev: {
|
|
nixvim = prev.nixvim.extend (
|
|
final: prev: {
|
|
utils = prev.utils // {
|
|
enableExceptInTests = false;
|
|
};
|
|
}
|
|
);
|
|
}
|
|
);
|
|
|
|
moduleToTest =
|
|
file: name: module:
|
|
let
|
|
configuration = testLib.nixvim.modules.evalNixvim {
|
|
modules = [
|
|
{
|
|
test.name = lib.mkDefault name;
|
|
_module.args.pkgs = lib.mkForce pkgsForTest;
|
|
}
|
|
{
|
|
_file = file;
|
|
imports = lib.toList module;
|
|
}
|
|
];
|
|
};
|
|
in
|
|
configuration.config.build.test.overrideAttrs (old: {
|
|
passthru =
|
|
old.passthru or { }
|
|
// builtins.removeAttrs configuration [
|
|
"_type"
|
|
"type"
|
|
]
|
|
// {
|
|
inherit file module;
|
|
optionType = configuration.type;
|
|
};
|
|
});
|
|
|
|
# List of files containing configurations
|
|
testFiles = fetchTests ./test-sources;
|
|
|
|
exampleFiles = {
|
|
name = "examples";
|
|
file = ../example.nix;
|
|
cases =
|
|
let
|
|
config = import ../example.nix { inherit pkgs; };
|
|
in
|
|
{
|
|
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
|
|
{
|
|
tests = map (
|
|
{
|
|
name,
|
|
file,
|
|
cases,
|
|
}:
|
|
{
|
|
inherit name;
|
|
path = linkFarm name (builtins.mapAttrs (moduleToTest file) cases);
|
|
}
|
|
) (testFiles ++ [ exampleFiles ]);
|
|
}
|