Skip to content

Commit f860c4d

Browse files
committed
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`.
1 parent 831218c commit f860c4d

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

lib/default.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
lib,
33
flake,
44
_isExtended ? false,
5-
_nixvimTests ? false,
65
}:
76
lib.makeExtensible (
87
self:
@@ -25,7 +24,7 @@ lib.makeExtensible (
2524
modules = call ./modules.nix { inherit flake; };
2625
options = call ./options.nix { };
2726
plugins = call ./plugins { };
28-
utils = call ./utils.nix { inherit _nixvimTests; } // call ./utils.internal.nix { };
27+
utils = call ./utils.nix { } // call ./utils.internal.nix { };
2928

3029
# Top-level helper aliases:
3130
# TODO: deprecate some aliases

lib/tests.nix

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ let
1515
...
1616
}:
1717
let
18-
# FIXME: this doesn't support helpers.enableExceptInTests, a context option would be better
1918
result = nvim.extend {
2019
config.test = {
2120
inherit name;
@@ -35,20 +34,13 @@ let
3534
extraSpecialArgs ? { },
3635
}:
3736
let
38-
# NOTE: we are importing this just for evalNixvim
39-
helpers = self.lib.nixvim.override {
40-
# TODO: deprecate helpers.enableExceptInTests,
41-
# add a context option e.g. `config.isTest`?
42-
_nixvimTests = true;
43-
};
44-
4537
systemMod =
4638
if pkgs == null then
4739
{ nixpkgs.hostPlatform = lib.mkDefault { inherit system; }; }
4840
else
4941
{ nixpkgs.pkgs = lib.mkDefault pkgs; };
5042

51-
result = helpers.modules.evalNixvim {
43+
result = self.lib.evalNixvim {
5244
modules = [
5345
module
5446
(lib.optionalAttrs (name != null) { test.name = name; })

lib/utils.nix

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
{
2-
lib,
3-
_nixvimTests,
4-
}:
1+
{ lib }:
52
rec {
63
/**
74
Transforms a list to an _"unkeyed"_ attribute set.
@@ -23,15 +20,14 @@ rec {
2320
builtins.listToAttrs (lib.lists.imap0 (idx: lib.nameValuePair "__unkeyed-${toString idx}") list);
2421

2522
/**
26-
Usually `true`, except when nixvim is being evaluated by
27-
`mkTestDerivationFromNixvimModule`, where it is `false`.
23+
Usually `true`, except within the `build.test` option, where it is `false`.
2824
2925
This can be used to dynamically enable plugins that can't be run in the
3026
test environment.
3127
*/
3228
# TODO: replace and deprecate
3329
# We shouldn't need to use another instance of `lib` when building a test drv
34-
enableExceptInTests = !_nixvimTests;
30+
enableExceptInTests = true;
3531

3632
/**
3733
An empty lua table `{ }` that will be included in the final lua configuration.

modules/top-level/test.nix

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
{
22
pkgs,
33
config,
4-
options,
54
lib,
5+
extendModules,
66
...
77
}:
88
let
9+
# Reevaluate the nixvim configuration in "test mode"
10+
# This allows users to use `lib.nixvim.enableExceptInTests`
11+
testConfiguration = extendModules {
12+
specialArgs =
13+
let
14+
# TODO: replace and deprecate enableExceptInTests
15+
# We shouldn't need to use another instance of `lib` when building a test drv
16+
# Maybe add a context option e.g. `config.isTest`?
17+
nixvimLib = lib.recursiveUpdate lib.nixvim {
18+
enableExceptInTests = false;
19+
utils.enableExceptInTests = false;
20+
};
21+
in
22+
{
23+
lib = lib.extend (_: _: { nixvim = nixvimLib; });
24+
helpers = nixvimLib;
25+
};
26+
};
927
cfg = config.test;
1028

1129
# Expectation submodule used for checking warnings and/or assertions
@@ -264,8 +282,10 @@ in
264282
config =
265283
let
266284
input = {
267-
inherit (config) warnings;
268-
assertions = builtins.concatMap (x: lib.optional (!x.assertion) x.message) config.assertions;
285+
inherit (testConfiguration.config) warnings;
286+
assertions = builtins.concatMap (
287+
x: lib.optional (!x.assertion) x.message
288+
) testConfiguration.config.assertions;
269289
};
270290

271291
expectationMessages =
@@ -323,7 +343,7 @@ in
323343
nativeBuildInputs =
324344
cfg.extraInputs
325345
++ lib.optionals cfg.buildNixvim [
326-
config.build.nvimPackage
346+
testConfiguration.config.build.nvimPackage
327347
];
328348

329349
inherit (failedExpectations) warnings assertions;
@@ -335,7 +355,8 @@ in
335355
#
336356
# Yes, three levels of `entries` is cursed.
337357
passthru = {
338-
inherit config options;
358+
inherit (testConfiguration) config options;
359+
configuration = testConfiguration;
339360
};
340361
}
341362
(

wrappers/standalone.nix

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99
# NOTE: `defaultSystem` is the only reason this function can't go in `<nixvim>.lib`
1010
system ? defaultSystem,
1111
extraSpecialArgs ? { },
12-
_nixvimTests ? false,
1312
module,
1413
}:
1514
let
1615
# NOTE: we are importing this just for evalNixvim
17-
helpers = self.lib.nixvim.override { inherit _nixvimTests; };
18-
inherit (helpers.modules) evalNixvim;
19-
2016
systemMod =
2117
if pkgs == null then
2218
{
@@ -33,7 +29,7 @@ let
3329
mod:
3430
let
3531
modules = lib.toList mod;
36-
nixvimConfig = evalNixvim {
32+
nixvimConfig = self.lib.evalNixvim {
3733
modules = modules ++ [
3834
systemMod
3935
];

0 commit comments

Comments
 (0)