2024-08-20 00:30:16 +01:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
lib ? pkgs.lib,
|
|
|
|
makeNixvimWithModule,
|
|
|
|
...
|
|
|
|
}:
|
2023-03-22 07:42:02 +01:00
|
|
|
let
|
|
|
|
# Create a nix derivation from a nixvim executable.
|
|
|
|
# The build phase simply consists in running the provided nvim binary.
|
|
|
|
mkTestDerivationFromNvim =
|
|
|
|
{
|
2023-03-03 09:18:52 +00:00
|
|
|
name,
|
2024-08-18 20:17:14 +01:00
|
|
|
nvim,
|
2024-08-20 00:30:16 +01:00
|
|
|
# TODO: Deprecated 2024-08-20, remove after 24.11
|
2023-05-15 11:04:52 +02:00
|
|
|
dontRun ? false,
|
2023-03-03 09:18:52 +00:00
|
|
|
...
|
2024-08-20 00:30:16 +01:00
|
|
|
}@args:
|
|
|
|
let
|
|
|
|
cfg = nvim.config.test;
|
|
|
|
runNvim =
|
|
|
|
lib.warnIf (args ? dontRun)
|
|
|
|
"mkTestDerivationFromNvim: the `dontRun` argument is deprecated. You should use the `test.runNvim` module option instead."
|
|
|
|
(cfg.runNvim && !dontRun);
|
|
|
|
in
|
2023-03-03 09:18:52 +00:00
|
|
|
pkgs.stdenv.mkDerivation {
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit name;
|
2023-03-03 09:18:52 +00:00
|
|
|
|
2024-08-18 20:17:14 +01:00
|
|
|
nativeBuildInputs = [
|
|
|
|
nvim
|
|
|
|
pkgs.docker-client
|
|
|
|
];
|
2023-03-03 09:18:52 +00:00
|
|
|
|
|
|
|
dontUnpack = true;
|
|
|
|
# We need to set HOME because neovim will try to create some files
|
|
|
|
#
|
|
|
|
# Because neovim does not return an exitcode when quitting we need to check if there are
|
|
|
|
# errors on stderr
|
2024-08-20 00:30:16 +01:00
|
|
|
buildPhase = lib.optionalString runNvim ''
|
|
|
|
mkdir -p .cache/nvim
|
2023-04-15 13:34:00 +02:00
|
|
|
|
2024-08-20 00:30:16 +01:00
|
|
|
output=$(HOME=$(realpath .) nvim -mn --headless "+q" 2>&1 >/dev/null)
|
|
|
|
if [[ -n $output ]]; then
|
|
|
|
echo "ERROR: $output"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
2023-03-03 09:18:52 +00:00
|
|
|
|
|
|
|
# If we don't do this nix is not happy
|
|
|
|
installPhase = ''
|
|
|
|
mkdir $out
|
|
|
|
'';
|
|
|
|
};
|
2023-03-22 07:42:02 +01:00
|
|
|
|
tests/test-derivation: allow tests to be modules
Use `mkTestDerivationFromNixvimModule` instead of `mkTestDerivation`,
allowing "proper" modules to be used instead of plain attr configs.
This is useful for more complex tests that wish to use `config` or
`options` arguments, e.g:
```nix
{config, options, ...}: {
/* some cool test */
}
```
To allow `tests.dontRun` to be defined on such a test, the module is
allowed to be nested as `module`, e.g:
```nix
{
tests.dontRun = true;
module = {config, options, ...}: {
/* a disabled test */
};
}
```
Also ended up doing some general cleanup, removing an unused function,
etc.
2024-06-29 20:16:16 +01:00
|
|
|
# Create a nix derivation from a nixvim configuration.
|
|
|
|
# The build phase simply consists in running neovim with the given configuration.
|
2024-02-15 14:27:45 +01:00
|
|
|
mkTestDerivationFromNixvimModule =
|
|
|
|
{
|
|
|
|
name ? "nixvim-check",
|
tests/test-derivation: allow tests to be modules
Use `mkTestDerivationFromNixvimModule` instead of `mkTestDerivation`,
allowing "proper" modules to be used instead of plain attr configs.
This is useful for more complex tests that wish to use `config` or
`options` arguments, e.g:
```nix
{config, options, ...}: {
/* some cool test */
}
```
To allow `tests.dontRun` to be defined on such a test, the module is
allowed to be nested as `module`, e.g:
```nix
{
tests.dontRun = true;
module = {config, options, ...}: {
/* a disabled test */
};
}
```
Also ended up doing some general cleanup, removing an unused function,
etc.
2024-06-29 20:16:16 +01:00
|
|
|
pkgs ? pkgs,
|
2024-08-18 20:17:14 +01:00
|
|
|
module,
|
2024-02-15 14:27:45 +01:00
|
|
|
extraSpecialArgs ? { },
|
2024-08-20 00:30:16 +01:00
|
|
|
# TODO: Deprecated 2024-08-20, remove after 24.11
|
tests/test-derivation: allow tests to be modules
Use `mkTestDerivationFromNixvimModule` instead of `mkTestDerivation`,
allowing "proper" modules to be used instead of plain attr configs.
This is useful for more complex tests that wish to use `config` or
`options` arguments, e.g:
```nix
{config, options, ...}: {
/* some cool test */
}
```
To allow `tests.dontRun` to be defined on such a test, the module is
allowed to be nested as `module`, e.g:
```nix
{
tests.dontRun = true;
module = {config, options, ...}: {
/* a disabled test */
};
}
```
Also ended up doing some general cleanup, removing an unused function,
etc.
2024-06-29 20:16:16 +01:00
|
|
|
dontRun ? false,
|
2024-08-20 00:30:16 +01:00
|
|
|
}@args:
|
2024-02-15 14:27:45 +01:00
|
|
|
let
|
2024-08-18 20:17:14 +01:00
|
|
|
nvim = makeNixvimWithModule {
|
2024-08-20 00:30:16 +01:00
|
|
|
inherit pkgs extraSpecialArgs;
|
2024-08-18 20:17:14 +01:00
|
|
|
_nixvimTests = true;
|
2024-08-20 00:30:16 +01:00
|
|
|
module =
|
|
|
|
if args ? dontRun then
|
|
|
|
lib.warn
|
|
|
|
"mkTestDerivationFromNixvimModule: the `dontRun` argument is deprecated. You should use the `test.runNvim` module option instead."
|
|
|
|
{
|
|
|
|
imports = [ module ];
|
|
|
|
config.test.runNvim = !dontRun;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
module;
|
2024-08-18 20:17:14 +01:00
|
|
|
};
|
2024-02-15 14:27:45 +01:00
|
|
|
in
|
2024-08-20 00:30:16 +01:00
|
|
|
mkTestDerivationFromNvim { inherit name nvim; };
|
2023-05-15 11:04:52 +02:00
|
|
|
in
|
|
|
|
{
|
tests/test-derivation: allow tests to be modules
Use `mkTestDerivationFromNixvimModule` instead of `mkTestDerivation`,
allowing "proper" modules to be used instead of plain attr configs.
This is useful for more complex tests that wish to use `config` or
`options` arguments, e.g:
```nix
{config, options, ...}: {
/* some cool test */
}
```
To allow `tests.dontRun` to be defined on such a test, the module is
allowed to be nested as `module`, e.g:
```nix
{
tests.dontRun = true;
module = {config, options, ...}: {
/* a disabled test */
};
}
```
Also ended up doing some general cleanup, removing an unused function,
etc.
2024-06-29 20:16:16 +01:00
|
|
|
inherit mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
|
2023-05-15 11:04:52 +02:00
|
|
|
}
|