1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-21 17:59:41 +01:00
nixvim/lib/tests.nix
Matt Sturgeon 8d0ca9abc4 lib: move enableExceptInTests impl to build.test option
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.
2025-11-20 00:22:57 +00:00

58 lines
1.3 KiB
Nix

{
self,
system,
lib,
}:
let
defaultSystem = system;
# Create a nix derivation from a nixvim executable.
# The build phase simply consists in running the provided nvim binary.
mkTestDerivationFromNvim =
{
name,
nvim,
...
}:
let
result = nvim.extend {
config.test = {
inherit name;
};
};
in
result.config.build.test;
# Create a nix derivation from a nixvim configuration.
# The build phase simply consists in running neovim with the given configuration.
mkTestDerivationFromNixvimModule =
{
name ? null,
pkgs ? null,
system ? defaultSystem,
module,
extraSpecialArgs ? { },
}:
let
systemMod =
if pkgs == null then
{ nixpkgs.hostPlatform = lib.mkDefault { inherit system; }; }
else
{ nixpkgs.pkgs = lib.mkDefault pkgs; };
result = self.lib.evalNixvim {
modules = [
module
(lib.optionalAttrs (name != null) { test.name = name; })
{ wrapRc = true; }
systemMod
];
inherit extraSpecialArgs;
};
in
result.config.build.test;
in
# NOTE: this is exported publicly in the flake outputs as `lib.<system>.check`
{
inherit mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
}