Skip to content

Commit 33c57ba

Browse files
committed
tests: use callTest pattern
Allows using the `callPackage(s)` pattern on tests. Rather than using `pkgs.callPackage`, we implement our own variant using `lib.callPackageWith`. Our variant (`callTest`) includes additional nixvim-specific stuff commonly used by our tests.
1 parent 44972ab commit 33c57ba

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

tests/default.nix

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,41 @@
88
self, # The flake instance
99
}:
1010
let
11-
inherit (self.legacyPackages.${system}) nixvimConfiguration;
11+
autoArgs = pkgs // {
12+
inherit
13+
helpers
14+
lib
15+
makeNixvimWithModule
16+
pkgsUnfree
17+
self
18+
system
19+
;
20+
inherit (self.legacyPackages.${system}) nixvimConfiguration;
21+
inherit (self.lib.${system}.check)
22+
mkTestDerivationFromNvim
23+
mkTestDerivationFromNixvimModule
24+
;
25+
# Recursive:
26+
inherit callTest callTests;
27+
};
28+
29+
callTest = lib.callPackageWith autoArgs;
30+
callTests = lib.callPackagesWith autoArgs;
1231
in
1332
{
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; };
33+
extra-args-tests = callTest ./extra-args.nix { };
34+
extend = callTest ./extend.nix { };
35+
extra-files = callTest ./extra-files.nix { };
36+
enable-except-in-tests = callTest ./enable-except-in-tests.nix { };
37+
failing-tests = callTest ./failing-tests.nix { };
38+
no-flake = callTest ./no-flake.nix { };
39+
lib-tests = callTest ./lib-tests.nix { };
40+
maintainers = callTest ./maintainers.nix { };
41+
plugins-by-name = callTest ./plugins-by-name.nix { };
42+
generated = callTest ./generated.nix { };
43+
package-options = callTest ./package-options.nix { };
44+
lsp-all-servers = callTest ./lsp-servers.nix { };
4145
}
4246
# Tests generated from ./test-sources
4347
# 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-
}
48+
// callTests ./main.nix { }

tests/main.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Collects the various test modules in tests/test-sources/ and groups them into a number of test derivations
22
{
3-
lib ? pkgs.lib,
3+
callPackage,
4+
callTest,
45
helpers,
6+
lib ? pkgs.lib,
57
pkgs,
68
pkgsUnfree,
79
}:
810
let
9-
fetchTests = import ./fetch-tests.nix { inherit lib pkgs helpers; };
10-
test-derivation = import ../lib/tests.nix { inherit pkgs lib; };
11+
fetchTests = callTest ./fetch-tests.nix { };
12+
test-derivation = callPackage ../lib/tests.nix { };
1113
inherit (test-derivation) mkTestDerivationFromNixvimModule;
1214

1315
moduleToTest =

tests/no-flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2+
nixvim ? "${self}",
3+
self ? throw "either supply `self` or `nixvim`",
24
system,
3-
nixvim,
45
mkTestDerivationFromNvim,
56
}:
67
let

0 commit comments

Comments
 (0)