Skip to content

Commit 036e116

Browse files
committed
tests: cleanup tests to better use callTest pattern
e.g. Prefer taking `pkgs.*` attrs directly as function arguments.
1 parent 4a508ce commit 036e116

File tree

7 files changed

+33
-20
lines changed

7 files changed

+33
-20
lines changed

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.build.extraFiles;
1821
files = builtins.attrNames extraFiles;

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";
@@ -412,11 +413,11 @@ let
412413
};
413414
in
414415
if results == [ ] then
415-
pkgs.runCommand "lib-tests-success" { } "touch $out"
416+
runCommandNoCCLocal "lib-tests-success" { } "touch $out"
416417
else
417-
pkgs.runCommand "lib-tests-failure"
418+
runCommandNoCCLocal "lib-tests-failure"
418419
{
419-
results = pkgs.lib.concatStringsSep "\n" (
420+
results = lib.concatStringsSep "\n" (
420421
builtins.map (result: ''
421422
${result.name}:
422423
expected: ${lib.generators.toPretty { } result.expected}

tests/main.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
callTest,
55
helpers,
66
lib ? pkgs.lib,
7+
linkFarm,
78
pkgs,
89
pkgsUnfree,
910
}:
@@ -54,14 +55,14 @@ lib.pipe (testFiles ++ [ exampleFiles ]) [
5455
}:
5556
{
5657
inherit name;
57-
path = pkgs.linkFarm name (builtins.mapAttrs (moduleToTest file) cases);
58+
path = linkFarm name (builtins.mapAttrs (moduleToTest file) cases);
5859
}
5960
))
6061
(helpers.groupListBySize 10)
6162
(lib.imap1 (
6263
i: group: rec {
6364
name = "test-${toString i}";
64-
value = pkgs.linkFarm name group;
65+
value = linkFarm name group;
6566
}
6667
))
6768
builtins.listToAttrs

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)