1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-21 17:59:41 +01:00
nixvim/tests/enable-except-in-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

78 lines
1.9 KiB
Nix

{
lib,
pkgs,
linkFarm,
runCommandLocal,
mkTestDerivationFromNixvimModule,
makeNixvimWithModule,
}:
let
inTest = mkTestDerivationFromNixvimModule {
name = "enable-except-in-tests-test";
inherit pkgs;
module =
{ lib, helpers, ... }:
{
assertions = [
{
assertion = !lib.nixvim.enableExceptInTests;
message = "Expected lib.nixvim.enableExceptInTests to be false";
}
{
# NOTE: evaluating `helpers` here prints an eval warning
assertion = !helpers.enableExceptInTests;
message = "Expected helpers.enableExceptInTests to be false";
}
];
};
};
notInTest =
let
nvim = makeNixvimWithModule {
inherit pkgs;
module =
{ lib, helpers, ... }:
{
assertions = [
{
assertion = lib.nixvim.enableExceptInTests;
message = "Expected lib.nixvim.enableExceptInTests to be true";
}
{
# NOTE: evaluating `helpers` here prints an eval warning
assertion = helpers.enableExceptInTests;
message = "Expected helpers.enableExceptInTests to be true";
}
];
};
};
in
runCommandLocal "enable-except-in-tests-not-in-test"
{
__structuredAttrs = true;
assertions = lib.pipe nvim.config.assertions [
(lib.filter (x: !x.assertion))
(lib.map (x: x.message))
];
}
''
if (( ''${#assertions[@]} )); then
for assertion in "''${assertions[@]}"; do
echo "- $assertion"
done
exit 1
fi
touch $out
'';
in
linkFarm "enable-except-in-tests" [
{
name = "in-test";
path = inTest;
}
{
name = "not-in-test";
path = notInTest;
}
]