nix-community.nixvim/lib/tests.nix

78 lines
2.3 KiB
Nix
Raw Permalink Normal View History

{
pkgs,
lib ? pkgs.lib,
...
}:
2024-05-05 19:39:35 +02:00
let
defaultPkgs = pkgs;
2023-03-22 07:42:02 +01:00
# Create a nix derivation from a nixvim executable.
# The build phase simply consists in running the provided nvim binary.
2024-05-05 19:39:35 +02:00
mkTestDerivationFromNvim =
{
name,
nvim,
# TODO: Deprecated 2024-08-20, remove after 24.11
2024-05-05 19:39:35 +02:00
dontRun ? false,
...
}@args:
let
# FIXME: this doesn't support helpers.enableExceptInTests, a context option would be better
result = nvim.extend {
config.test =
{
inherit name;
}
// lib.optionalAttrs (args ? dontRun) (
lib.warn
"mkTestDerivationFromNvim: the `dontRun` argument is deprecated. You should use the `test.runNvim` module option instead."
{ runNvim = !dontRun; }
);
};
in
result.config.build.test;
2023-03-22 07:42:02 +01:00
# Create a nix derivation from a nixvim configuration.
# The build phase simply consists in running neovim with the given configuration.
2024-05-05 19:39:35 +02:00
mkTestDerivationFromNixvimModule =
{
name ? null,
pkgs ? defaultPkgs,
module,
2024-05-05 19:39:35 +02:00
extraSpecialArgs ? { },
# TODO: Deprecated 2024-08-20, remove after 24.11
dontRun ? false,
}@args:
2024-05-05 19:39:35 +02:00
let
helpers = import ../lib {
# NOTE: must match the user-facing functions, so we still include the `pkgs` argument
inherit pkgs lib;
# TODO: deprecate helpers.enableExceptInTests,
# add a context option e.g. `config.isTest`?
_nixvimTests = true;
};
result = helpers.modules.evalNixvim {
modules = [
module
(lib.optionalAttrs (name != null) { test.name = name; })
(lib.optionalAttrs (args ? dontRun) (
lib.warn
"mkTestDerivationFromNixvimModule: the `dontRun` argument is deprecated. You should use the `test.runNvim` module option instead."
{ config.test.runNvim = !dontRun; }
))
{ wrapRc = true; }
# TODO: Only do this when `args?pkgs`
# Consider deprecating the `pkgs` arg too...
{ nixpkgs.pkgs = lib.mkDefault pkgs; }
];
inherit extraSpecialArgs;
};
2024-05-05 19:39:35 +02:00
in
result.config.build.test;
2024-05-05 19:39:35 +02:00
in
# NOTE: this is exported publicly in the flake outputs as `lib.<system>.check`
2024-05-05 19:39:35 +02:00
{
inherit mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
}