Skip to content

Commit 44972ab

Browse files
committed
tests: move test derivations to tests/default.nix
Move the previous `default.nix` to `main.nix` so that `default.nix` can be used for defining the set of all test derivations. `main.nix` is imported by `default.nix`, but is only responsible for the tests built from `tests/test-sources/`.
1 parent 3c7b6ae commit 44972ab

File tree

3 files changed

+128
-104
lines changed

3 files changed

+128
-104
lines changed

flake-modules/tests.nix

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,29 @@
1-
{ self, helpers, ... }:
1+
{
2+
self,
3+
lib,
4+
helpers,
5+
...
6+
}:
27
{
38
perSystem =
49
{
510
pkgs,
611
pkgsUnfree,
712
system,
813
makeNixvimWithModule,
9-
self',
1014
...
1115
}:
12-
let
13-
inherit (self'.legacyPackages) nixvimConfiguration;
14-
in
1516
{
16-
checks = {
17-
extra-args-tests = import ../tests/extra-args.nix {
18-
inherit pkgs;
19-
inherit makeNixvimWithModule;
20-
};
21-
22-
extend = import ../tests/extend.nix { inherit pkgs makeNixvimWithModule; };
23-
24-
extra-files = import ../tests/extra-files.nix { inherit pkgs makeNixvimWithModule; };
25-
26-
enable-except-in-tests = import ../tests/enable-except-in-tests.nix {
27-
inherit pkgs makeNixvimWithModule;
28-
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule;
29-
};
30-
31-
failing-tests = pkgs.callPackage ../tests/failing-tests.nix {
32-
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule;
33-
};
34-
35-
no-flake = import ../tests/no-flake.nix {
36-
inherit system;
37-
inherit (self.lib.${system}.check) mkTestDerivationFromNvim;
38-
nixvim = "${self}";
39-
};
40-
41-
lib-tests = import ../tests/lib-tests.nix {
42-
inherit pkgs helpers;
43-
inherit (pkgs) lib;
44-
};
45-
46-
maintainers = import ../tests/maintainers.nix { inherit pkgs; };
47-
48-
plugins-by-name = pkgs.callPackage ../tests/plugins-by-name.nix { inherit nixvimConfiguration; };
49-
50-
generated = pkgs.callPackage ../tests/generated.nix { };
51-
52-
package-options = pkgs.callPackage ../tests/package-options.nix { inherit nixvimConfiguration; };
53-
54-
lsp-all-servers = pkgs.callPackage ../tests/lsp-servers.nix { inherit nixvimConfiguration; };
55-
} // import ../tests { inherit pkgs pkgsUnfree helpers; };
17+
checks = import ../tests {
18+
inherit
19+
helpers
20+
lib
21+
makeNixvimWithModule
22+
pkgs
23+
pkgsUnfree
24+
self
25+
system
26+
;
27+
};
5628
};
5729
}

tests/default.nix

Lines changed: 45 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,51 @@
11
{
2-
lib ? pkgs.lib,
3-
helpers,
42
pkgs,
53
pkgsUnfree,
4+
helpers,
5+
makeNixvimWithModule,
6+
lib,
7+
system,
8+
self, # The flake instance
69
}:
710
let
8-
fetchTests = import ./fetch-tests.nix { inherit lib pkgs helpers; };
9-
test-derivation = import ../lib/tests.nix { inherit pkgs lib; };
10-
inherit (test-derivation) mkTestDerivationFromNixvimModule;
11-
12-
moduleToTest =
13-
file: name: module:
14-
mkTestDerivationFromNixvimModule {
15-
inherit name;
16-
module = {
17-
_file = file;
18-
imports = [ module ];
19-
};
20-
pkgs = pkgsUnfree;
21-
};
22-
23-
# List of files containing configurations
24-
testFiles = fetchTests ./test-sources;
25-
26-
exampleFiles = {
27-
name = "examples";
28-
file = ../example.nix;
29-
cases =
30-
let
31-
config = import ../example.nix { inherit pkgs; };
32-
in
33-
{
34-
main = builtins.removeAttrs config.programs.nixvim [
35-
# This is not available to standalone modules, only HM & NixOS Modules
36-
"enable"
37-
# This is purely an example, it does not reflect a real usage
38-
"extraConfigLua"
39-
"extraConfigVim"
40-
];
41-
};
42-
};
11+
inherit (self.legacyPackages.${system}) nixvimConfiguration;
4312
in
44-
# We attempt to build & execute all configurations
45-
lib.pipe (testFiles ++ [ exampleFiles ]) [
46-
(builtins.map (
47-
{
48-
name,
49-
file,
50-
cases,
51-
}:
52-
{
53-
inherit name;
54-
path = pkgs.linkFarm name (builtins.mapAttrs (moduleToTest file) cases);
55-
}
56-
))
57-
(helpers.groupListBySize 10)
58-
(lib.imap1 (
59-
i: group: rec {
60-
name = "test-${toString i}";
61-
value = pkgs.linkFarm name group;
62-
}
63-
))
64-
builtins.listToAttrs
65-
]
13+
{
14+
extra-args-tests = import ./extra-args.nix {
15+
inherit pkgs;
16+
inherit makeNixvimWithModule;
17+
};
18+
extend = import ./extend.nix { inherit pkgs makeNixvimWithModule; };
19+
extra-files = import ./extra-files.nix { inherit pkgs makeNixvimWithModule; };
20+
enable-except-in-tests = import ./enable-except-in-tests.nix {
21+
inherit pkgs makeNixvimWithModule;
22+
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule;
23+
};
24+
failing-tests = pkgs.callPackage ./failing-tests.nix {
25+
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule;
26+
};
27+
no-flake = import ./no-flake.nix {
28+
inherit system;
29+
inherit (self.lib.${system}.check) mkTestDerivationFromNvim;
30+
nixvim = "${self}";
31+
};
32+
lib-tests = import ./lib-tests.nix {
33+
inherit pkgs helpers;
34+
inherit (pkgs) lib;
35+
};
36+
maintainers = import ./maintainers.nix { inherit pkgs; };
37+
plugins-by-name = pkgs.callPackage ./plugins-by-name.nix { inherit nixvimConfiguration; };
38+
generated = pkgs.callPackage ./generated.nix { };
39+
package-options = pkgs.callPackage ./package-options.nix { inherit nixvimConfiguration; };
40+
lsp-all-servers = pkgs.callPackage ./lsp-servers.nix { inherit nixvimConfiguration; };
41+
}
42+
# Tests generated from ./test-sources
43+
# Grouped as a number of link-farms in the form { test-1, test-2, ... test-N }
44+
// import ./main.nix {
45+
inherit
46+
lib
47+
pkgs
48+
pkgsUnfree
49+
helpers
50+
;
51+
}

tests/main.nix

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Collects the various test modules in tests/test-sources/ and groups them into a number of test derivations
2+
{
3+
lib ? pkgs.lib,
4+
helpers,
5+
pkgs,
6+
pkgsUnfree,
7+
}:
8+
let
9+
fetchTests = import ./fetch-tests.nix { inherit lib pkgs helpers; };
10+
test-derivation = import ../lib/tests.nix { inherit pkgs lib; };
11+
inherit (test-derivation) mkTestDerivationFromNixvimModule;
12+
13+
moduleToTest =
14+
file: name: module:
15+
mkTestDerivationFromNixvimModule {
16+
inherit name;
17+
module = {
18+
_file = file;
19+
imports = [ module ];
20+
};
21+
pkgs = pkgsUnfree;
22+
};
23+
24+
# List of files containing configurations
25+
testFiles = fetchTests ./test-sources;
26+
27+
exampleFiles = {
28+
name = "examples";
29+
file = ../example.nix;
30+
cases =
31+
let
32+
config = import ../example.nix { inherit pkgs; };
33+
in
34+
{
35+
main = builtins.removeAttrs config.programs.nixvim [
36+
# This is not available to standalone modules, only HM & NixOS Modules
37+
"enable"
38+
# This is purely an example, it does not reflect a real usage
39+
"extraConfigLua"
40+
"extraConfigVim"
41+
];
42+
};
43+
};
44+
in
45+
# We attempt to build & execute all configurations
46+
lib.pipe (testFiles ++ [ exampleFiles ]) [
47+
(builtins.map (
48+
{
49+
name,
50+
file,
51+
cases,
52+
}:
53+
{
54+
inherit name;
55+
path = pkgs.linkFarm name (builtins.mapAttrs (moduleToTest file) cases);
56+
}
57+
))
58+
(helpers.groupListBySize 10)
59+
(lib.imap1 (
60+
i: group: rec {
61+
name = "test-${toString i}";
62+
value = pkgs.linkFarm name group;
63+
}
64+
))
65+
builtins.listToAttrs
66+
]

0 commit comments

Comments
 (0)