Skip to content

Commit 01ef05e

Browse files
committed
tests: use callPackage pattern for flake checks
1 parent 7aa0fa3 commit 01ef05e

File tree

10 files changed

+62
-63
lines changed

10 files changed

+62
-63
lines changed

flake-modules/tests.nix

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ self, ... }:
1+
{ self, lib, ... }:
22
{
33
perSystem =
44
{
@@ -10,40 +10,31 @@
1010
}:
1111
let
1212
inherit (self'.legacyPackages.lib) helpers makeNixvimWithModule;
13-
inherit (self'.legacyPackages.lib.check) mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
14-
evaluatedNixvim = helpers.modules.evalNixvim { check = false; };
13+
callTest = lib.callPackageWith (
14+
pkgs
15+
// {
16+
nixvimLib = self'.legacyPackages.lib;
17+
inherit helpers makeNixvimWithModule;
18+
inherit (self'.legacyPackages.lib.check) mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
19+
evaluatedNixvim = helpers.modules.evalNixvim { check = false; };
20+
}
21+
);
1522
in
1623
{
1724
checks = {
18-
extra-args-tests = import ../tests/extra-args.nix { inherit pkgs makeNixvimWithModule; };
19-
20-
extend = import ../tests/extend.nix { inherit pkgs makeNixvimWithModule; };
21-
22-
extra-files = import ../tests/extra-files.nix { inherit pkgs makeNixvimWithModule; };
23-
24-
enable-except-in-tests = import ../tests/enable-except-in-tests.nix {
25-
inherit pkgs makeNixvimWithModule mkTestDerivationFromNixvimModule;
26-
};
27-
28-
failing-tests = pkgs.callPackage ../tests/failing-tests.nix {
29-
inherit mkTestDerivationFromNixvimModule;
30-
};
31-
32-
no-flake = import ../tests/no-flake.nix {
33-
inherit system mkTestDerivationFromNvim;
25+
extra-args-tests = callTest ../tests/extra-args.nix { };
26+
extend = callTest ../tests/extend.nix { };
27+
extra-files = callTest ../tests/extra-files.nix { };
28+
enable-except-in-tests = callTest ../tests/enable-except-in-tests.nix { };
29+
failing-tests = callTest ../tests/failing-tests.nix { };
30+
no-flake = callTest ../tests/no-flake.nix {
31+
inherit system;
3432
nixvim = "${self}";
3533
};
36-
37-
lib-tests = import ../tests/lib-tests.nix {
38-
inherit pkgs helpers;
39-
inherit (pkgs) lib;
40-
};
41-
42-
maintainers = import ../tests/maintainers.nix { inherit pkgs; };
43-
44-
generated = pkgs.callPackage ../tests/generated.nix { };
45-
46-
package-options = pkgs.callPackage ../tests/package-options.nix { inherit evaluatedNixvim; };
47-
} // import ../tests { inherit pkgs pkgsUnfree helpers; };
34+
lib-tests = callTest ../tests/lib-tests.nix { };
35+
maintainers = callTest ../tests/maintainers.nix { };
36+
generated = callTest ../tests/generated.nix { };
37+
package-options = callTest ../tests/package-options.nix { };
38+
} // callTest ../tests { inherit pkgsUnfree; };
4839
};
4940
}

tests/default.nix

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
lib ? pkgs.lib,
32
helpers,
3+
lib,
4+
linkFarm,
45
pkgs,
56
pkgsUnfree,
7+
mkTestDerivationFromNixvimModule,
68
}:
79
let
8-
fetchTests = import ./fetch-tests.nix;
9-
test-derivation = import ../lib/tests.nix { inherit pkgs lib; };
10-
inherit (test-derivation) mkTestDerivationFromNixvimModule;
10+
fetchTests = import ./fetch-tests.nix { inherit lib pkgs helpers; };
1111

1212
moduleToTest =
1313
name: module:
@@ -17,10 +17,7 @@ let
1717
};
1818

1919
# List of files containing configurations
20-
testFiles = fetchTests {
21-
inherit lib pkgs helpers;
22-
root = ./test-sources;
23-
};
20+
testFiles = fetchTests ./test-sources;
2421

2522
exampleFiles = {
2623
name = "examples";
@@ -44,13 +41,13 @@ in
4441
lib.pipe (testFiles ++ [ exampleFiles ]) [
4542
(builtins.map (file: {
4643
inherit (file) name;
47-
path = pkgs.linkFarm file.name (builtins.mapAttrs moduleToTest file.cases);
44+
path = linkFarm file.name (builtins.mapAttrs moduleToTest file.cases);
4845
}))
4946
(helpers.groupListBySize 10)
5047
(lib.imap1 (
5148
i: group: rec {
5249
name = "test-${toString i}";
53-
value = pkgs.linkFarm name group;
50+
value = linkFarm name group;
5451
}
5552
))
5653
builtins.listToAttrs

tests/enable-except-in-tests.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
pkgs,
3+
linkFarm,
4+
runCommandNoCCLocal,
35
mkTestDerivationFromNixvimModule,
46
makeNixvimWithModule,
57
}:
@@ -19,7 +21,7 @@ let
1921
let
2022
nvim = makeNixvimWithModule { inherit pkgs module; };
2123
in
22-
pkgs.runCommand "enable-except-in-tests-not-in-test"
24+
runCommandNoCCLocal "enable-except-in-tests-not-in-test"
2325
{ printConfig = "${nvim}/bin/nixvim-print-init"; }
2426
''
2527
if ! "$printConfig" | grep 'require("image").setup'; then
@@ -31,7 +33,7 @@ let
3133
touch $out
3234
'';
3335
in
34-
pkgs.linkFarm "enable-except-in-tests" [
36+
linkFarm "enable-except-in-tests" [
3537
{
3638
name = "in-test";
3739
path = inTest;

tests/extend.nix

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
{ makeNixvimWithModule, pkgs }:
1+
{
2+
makeNixvimWithModule,
3+
runCommandNoCCLocal,
4+
}:
25
let
36
firstStage = makeNixvimWithModule {
47
module = {
@@ -10,7 +13,7 @@ let
1013

1114
generated = secondStage.extend { extraConfigLua = "-- third stage"; };
1215
in
13-
pkgs.runCommand "extend-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
16+
runCommandNoCCLocal "extend-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
1417
config=$($printConfig)
1518
for stage in "first" "second" "third"; do
1619
if ! "$printConfig" | grep -q -- "-- $stage stage"; then

tests/extra-args.nix

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
{ makeNixvimWithModule, pkgs }:
1+
{
2+
makeNixvimWithModule,
3+
runCommandNoCCLocal,
4+
}:
25
let
36
defaultModule =
47
{ regularArg, ... }:
@@ -28,7 +31,7 @@ let
2831
};
2932
};
3033
in
31-
pkgs.runCommand "special-arg-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
34+
runCommandNoCCLocal "special-arg-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
3235
config=$($printConfig)
3336
if ! "$printConfig" | grep -- '-- regularArg=regularValue'; then
3437
echo "Missing regularArg in config"

tests/extra-files.nix

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
{ makeNixvimWithModule, pkgs }:
1+
{
2+
makeNixvimWithModule,
3+
runCommandNoCCLocal,
4+
}:
25
let
36
extraFiles = {
47
"one".text = "one";
@@ -12,7 +15,7 @@ let
1215
};
1316
};
1417
in
15-
pkgs.runCommand "extra-files-test"
18+
runCommandNoCCLocal "extra-files-test"
1619
{
1720
root = build.config.filesPlugin;
1821
files = builtins.attrNames extraFiles;

tests/fetch-tests.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
root,
32
lib,
43
pkgs,
54
helpers,
@@ -49,4 +48,4 @@ let
4948
builtins.concatLists
5049
];
5150
in
52-
fetchTests root [ ]
51+
root: fetchTests root [ ]

tests/generated.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
lib,
3-
runCommand,
43
pkgs,
4+
runCommandNoCCLocal,
55
}:
66
let
77
# Format a list of errors with an error message and trailing newline
@@ -68,7 +68,7 @@ let
6868
}
6969
);
7070
in
71-
runCommand "generated-sources-test" { inherit errors; } ''
71+
runCommandNoCCLocal "generated-sources-test" { inherit errors; } ''
7272
if [ -n "$errors" ]; then
7373
echo -n "$errors"
7474
exit 1

tests/lib-tests.nix

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# For shorter test iterations run the following in the root of the repo:
22
# `echo ':b checks.${builtins.currentSystem}.lib-tests' | nix repl .`
33
{
4-
lib,
5-
pkgs,
64
helpers,
5+
lib,
6+
runCommandNoCCLocal,
7+
writeText,
78
}:
89
let
910
luaNames = {
@@ -45,9 +46,9 @@ let
4546
];
4647
};
4748

48-
drv = pkgs.writeText "example-derivation" "hello, world!";
49+
drv = writeText "example-derivation" "hello, world!";
4950

50-
results = pkgs.lib.runTests {
51+
results = lib.runTests {
5152
testToLuaObject = {
5253
expr = helpers.toLuaObject {
5354
foo = "bar";
@@ -377,11 +378,11 @@ let
377378
};
378379
in
379380
if results == [ ] then
380-
pkgs.runCommand "lib-tests-success" { } "touch $out"
381+
runCommandNoCCLocal "lib-tests-success" { } "touch $out"
381382
else
382-
pkgs.runCommand "lib-tests-failure"
383+
runCommandNoCCLocal "lib-tests-failure"
383384
{
384-
results = pkgs.lib.concatStringsSep "\n" (
385+
results = lib.concatStringsSep "\n" (
385386
builtins.map (result: ''
386387
${result.name}:
387388
expected: ${lib.generators.toPretty { } result.expected}

tests/maintainers.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
pkgs ? import <nixpkgs> { },
3-
lib ? pkgs.lib,
2+
lib,
3+
runCommandNoCCLocal,
44
}:
55
let
66
inherit (lib) attrNames filter length;
@@ -9,7 +9,7 @@ let
99
duplicates = filter (name: nixpkgsList ? ${name}) (attrNames nixvimList);
1010
count = length duplicates;
1111
in
12-
pkgs.runCommand "maintainers-test" { inherit count duplicates; } ''
12+
runCommandNoCCLocal "maintainers-test" { inherit count duplicates; } ''
1313
if [ $count -gt 0 ]; then
1414
echo "$count nixvim maintainers are also nixpkgs maintainers:"
1515
for name in $duplicates; do

0 commit comments

Comments
 (0)