Skip to content

Commit 4a508ce

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 990ef03 commit 4a508ce

File tree

3 files changed

+42
-43
lines changed

3 files changed

+42
-43
lines changed

tests/default.nix

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