Skip to content

Commit 990ef03

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 990ef03

File tree

3 files changed

+129
-105
lines changed

3 files changed

+129
-105
lines changed

flake-modules/tests.nix

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,27 @@
1-
{ self, helpers, ... }:
1+
{
2+
self,
3+
lib,
4+
helpers,
5+
...
6+
}:
27
{
38
perSystem =
49
{
510
pkgs,
611
pkgsUnfree,
712
system,
8-
makeNixvimWithModule,
9-
self',
1013
...
1114
}:
12-
let
13-
inherit (self'.legacyPackages) nixvimConfiguration;
14-
in
1515
{
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; };
16+
checks = import ../tests {
17+
inherit
18+
helpers
19+
lib
20+
pkgs
21+
pkgsUnfree
22+
self
23+
system
24+
;
25+
};
5626
};
5727
}

tests/default.nix

Lines changed: 47 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,53 @@
11
{
2-
lib ? pkgs.lib,
3-
helpers,
42
pkgs,
53
pkgsUnfree,
4+
helpers,
5+
lib,
6+
system,
7+
self, # The flake instance
68
}:
79
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-
};
10+
inherit (self.legacyPackages.${system})
11+
makeNixvimWithModule
12+
nixvimConfiguration
13+
;
4314
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-
]
15+
{
16+
extra-args-tests = import ./extra-args.nix {
17+
inherit pkgs;
18+
inherit makeNixvimWithModule;
19+
};
20+
extend = import ./extend.nix { inherit pkgs makeNixvimWithModule; };
21+
extra-files = import ./extra-files.nix { inherit pkgs makeNixvimWithModule; };
22+
enable-except-in-tests = import ./enable-except-in-tests.nix {
23+
inherit pkgs makeNixvimWithModule;
24+
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule;
25+
};
26+
failing-tests = pkgs.callPackage ./failing-tests.nix {
27+
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule;
28+
};
29+
no-flake = import ./no-flake.nix {
30+
inherit system;
31+
inherit (self.lib.${system}.check) mkTestDerivationFromNvim;
32+
nixvim = "${self}";
33+
};
34+
lib-tests = import ./lib-tests.nix {
35+
inherit pkgs helpers;
36+
inherit (pkgs) lib;
37+
};
38+
maintainers = import ./maintainers.nix { inherit pkgs; };
39+
plugins-by-name = pkgs.callPackage ./plugins-by-name.nix { inherit nixvimConfiguration; };
40+
generated = pkgs.callPackage ./generated.nix { };
41+
package-options = pkgs.callPackage ./package-options.nix { inherit nixvimConfiguration; };
42+
lsp-all-servers = pkgs.callPackage ./lsp-servers.nix { inherit nixvimConfiguration; };
43+
}
44+
# Tests generated from ./test-sources
45+
# Grouped as a number of link-farms in the form { test-1, test-2, ... test-N }
46+
// import ./main.nix {
47+
inherit
48+
lib
49+
pkgs
50+
pkgsUnfree
51+
helpers
52+
;
53+
}

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)