mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
modules/test: init, replacing dontRun
arg
Introduces the `test.runNvim` module option. Deprecates the historic `dontRun` argument passed to the test-derivation helpers. Soft-deprecates the `tests.dontRun` attr used in tests currently.
This commit is contained in:
parent
312db6b6e2
commit
f47374fd26
6 changed files with 69 additions and 25 deletions
|
@ -10,7 +10,7 @@
|
||||||
{ pkgs, config, ... }:
|
{ pkgs, config, ... }:
|
||||||
import ../lib {
|
import ../lib {
|
||||||
inherit pkgs lib;
|
inherit pkgs lib;
|
||||||
inherit (config.legacyPackages) makeNixvim makeNixvimWithModule;
|
inherit (config.legacyPackages) makeNixvimWithModule;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
# Args probably only needs pkgs and lib
|
# Args probably only needs pkgs and lib
|
||||||
{
|
{
|
||||||
makeNixvim,
|
|
||||||
makeNixvimWithModule,
|
makeNixvimWithModule,
|
||||||
pkgs,
|
pkgs,
|
||||||
|
lib ? pkgs.lib,
|
||||||
_nixvimTests ? false,
|
_nixvimTests ? false,
|
||||||
...
|
...
|
||||||
}@args:
|
}@args:
|
||||||
{
|
{
|
||||||
# Add all exported modules here
|
# Add all exported modules here
|
||||||
check = import ../tests/test-derivation.nix { inherit makeNixvim makeNixvimWithModule pkgs; };
|
check = import ../tests/test-derivation.nix { inherit makeNixvimWithModule lib pkgs; };
|
||||||
helpers = import ./helpers.nix (args // { inherit _nixvimTests; });
|
helpers = import ./helpers.nix (args // { inherit _nixvimTests; });
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,5 +8,6 @@
|
||||||
../.
|
../.
|
||||||
./files
|
./files
|
||||||
./output.nix
|
./output.nix
|
||||||
|
./test.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
10
modules/top-level/test.nix
Normal file
10
modules/top-level/test.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{ lib, ... }:
|
||||||
|
{
|
||||||
|
options.test = {
|
||||||
|
runNvim = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
description = "Whether to run `nvim` in the test.";
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
fetchTests = import ./fetch-tests.nix;
|
fetchTests = import ./fetch-tests.nix;
|
||||||
test-derivation = import ./test-derivation.nix { inherit pkgs makeNixvimWithModule; };
|
test-derivation = import ./test-derivation.nix { inherit pkgs lib makeNixvimWithModule; };
|
||||||
inherit (test-derivation) mkTestDerivationFromNixvimModule;
|
inherit (test-derivation) mkTestDerivationFromNixvimModule;
|
||||||
|
|
||||||
# List of files containing configurations
|
# List of files containing configurations
|
||||||
|
@ -43,16 +43,29 @@ lib.pipe (testFiles ++ [ exampleFiles ]) [
|
||||||
let
|
let
|
||||||
# The test case can either be the actual definition,
|
# The test case can either be the actual definition,
|
||||||
# or a child attr named `module`.
|
# or a child attr named `module`.
|
||||||
prepareModule = case: case.module or (lib.removeAttrs case [ "tests" ]);
|
prepareModule =
|
||||||
dontRunModule = case: case.tests.dontRun or false;
|
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 =
|
mkTest =
|
||||||
{ name, case }:
|
{ name, case }:
|
||||||
{
|
{
|
||||||
inherit name;
|
inherit name;
|
||||||
path = mkTestDerivationFromNixvimModule {
|
path = mkTestDerivationFromNixvimModule {
|
||||||
inherit name;
|
inherit name;
|
||||||
module = prepareModule case;
|
module = {
|
||||||
dontRun = dontRunModule case;
|
imports = [
|
||||||
|
(dontRunModule case)
|
||||||
|
(prepareModule case)
|
||||||
|
];
|
||||||
|
};
|
||||||
pkgs = pkgsUnfree;
|
pkgs = pkgsUnfree;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
{ pkgs, makeNixvimWithModule, ... }:
|
{
|
||||||
|
pkgs,
|
||||||
|
lib ? pkgs.lib,
|
||||||
|
makeNixvimWithModule,
|
||||||
|
...
|
||||||
|
}:
|
||||||
let
|
let
|
||||||
# Create a nix derivation from a nixvim executable.
|
# Create a nix derivation from a nixvim executable.
|
||||||
# The build phase simply consists in running the provided nvim binary.
|
# The build phase simply consists in running the provided nvim binary.
|
||||||
|
@ -6,9 +11,17 @@ let
|
||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
nvim,
|
nvim,
|
||||||
|
# TODO: Deprecated 2024-08-20, remove after 24.11
|
||||||
dontRun ? false,
|
dontRun ? false,
|
||||||
...
|
...
|
||||||
}:
|
}@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
|
||||||
pkgs.stdenv.mkDerivation {
|
pkgs.stdenv.mkDerivation {
|
||||||
inherit name;
|
inherit name;
|
||||||
|
|
||||||
|
@ -22,9 +35,7 @@ let
|
||||||
#
|
#
|
||||||
# Because neovim does not return an exitcode when quitting we need to check if there are
|
# Because neovim does not return an exitcode when quitting we need to check if there are
|
||||||
# errors on stderr
|
# errors on stderr
|
||||||
buildPhase =
|
buildPhase = lib.optionalString runNvim ''
|
||||||
if !dontRun then
|
|
||||||
''
|
|
||||||
mkdir -p .cache/nvim
|
mkdir -p .cache/nvim
|
||||||
|
|
||||||
output=$(HOME=$(realpath .) nvim -mn --headless "+q" 2>&1 >/dev/null)
|
output=$(HOME=$(realpath .) nvim -mn --headless "+q" 2>&1 >/dev/null)
|
||||||
|
@ -32,9 +43,7 @@ let
|
||||||
echo "ERROR: $output"
|
echo "ERROR: $output"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
''
|
'';
|
||||||
else
|
|
||||||
'''';
|
|
||||||
|
|
||||||
# If we don't do this nix is not happy
|
# If we don't do this nix is not happy
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
|
@ -50,15 +59,26 @@ let
|
||||||
pkgs ? pkgs,
|
pkgs ? pkgs,
|
||||||
module,
|
module,
|
||||||
extraSpecialArgs ? { },
|
extraSpecialArgs ? { },
|
||||||
|
# TODO: Deprecated 2024-08-20, remove after 24.11
|
||||||
dontRun ? false,
|
dontRun ? false,
|
||||||
}:
|
}@args:
|
||||||
let
|
let
|
||||||
nvim = makeNixvimWithModule {
|
nvim = makeNixvimWithModule {
|
||||||
inherit pkgs module extraSpecialArgs;
|
inherit pkgs extraSpecialArgs;
|
||||||
_nixvimTests = true;
|
_nixvimTests = true;
|
||||||
|
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;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
mkTestDerivationFromNvim { inherit name nvim dontRun; };
|
mkTestDerivationFromNvim { inherit name nvim; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
|
inherit mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue