Skip to content

Commit

Permalink
tests: cleanup tests to better use callTest pattern
Browse files Browse the repository at this point in the history
e.g. Prefer taking `pkgs.*` attrs directly as function arguments.
  • Loading branch information
MattSturgeon committed Oct 18, 2024
1 parent 4a508ce commit 036e116
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
6 changes: 4 additions & 2 deletions tests/enable-except-in-tests.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
pkgs,
linkFarm,
runCommandNoCCLocal,
mkTestDerivationFromNixvimModule,
makeNixvimWithModule,
}:
Expand All @@ -19,7 +21,7 @@ let
let
nvim = makeNixvimWithModule { inherit pkgs module; };
in
pkgs.runCommand "enable-except-in-tests-not-in-test"
runCommandNoCCLocal "enable-except-in-tests-not-in-test"
{ printConfig = "${nvim}/bin/nixvim-print-init"; }
''
if ! "$printConfig" | grep 'require("image").setup'; then
Expand All @@ -31,7 +33,7 @@ let
touch $out
'';
in
pkgs.linkFarm "enable-except-in-tests" [
linkFarm "enable-except-in-tests" [
{
name = "in-test";
path = inTest;
Expand Down
7 changes: 5 additions & 2 deletions tests/extend.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{ makeNixvimWithModule, pkgs }:
{
makeNixvimWithModule,
runCommandNoCCLocal,
}:
let
firstStage = makeNixvimWithModule {
module = {
Expand All @@ -10,7 +13,7 @@ let

generated = secondStage.extend { extraConfigLua = "-- third stage"; };
in
pkgs.runCommand "extend-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
runCommandNoCCLocal "extend-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
config=$($printConfig)
for stage in "first" "second" "third"; do
if ! "$printConfig" | grep -q -- "-- $stage stage"; then
Expand Down
7 changes: 5 additions & 2 deletions tests/extra-args.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{ makeNixvimWithModule, pkgs }:
{
makeNixvimWithModule,
runCommandNoCCLocal,
}:
let
defaultModule =
{ regularArg, ... }:
Expand Down Expand Up @@ -28,7 +31,7 @@ let
};
};
in
pkgs.runCommand "special-arg-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
runCommandNoCCLocal "special-arg-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
config=$($printConfig)
if ! "$printConfig" | grep -- '-- regularArg=regularValue'; then
echo "Missing regularArg in config"
Expand Down
7 changes: 5 additions & 2 deletions tests/extra-files.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{ makeNixvimWithModule, pkgs }:
{
makeNixvimWithModule,
runCommandNoCCLocal,
}:
let
extraFiles = {
"one".text = "one";
Expand All @@ -12,7 +15,7 @@ let
};
};
in
pkgs.runCommand "extra-files-test"
runCommandNoCCLocal "extra-files-test"
{
root = build.config.build.extraFiles;
files = builtins.attrNames extraFiles;
Expand Down
15 changes: 8 additions & 7 deletions tests/lib-tests.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# For shorter test iterations run the following in the root of the repo:
# `echo ':b checks.${builtins.currentSystem}.lib-tests' | nix repl .`
{
lib,
pkgs,
helpers,
lib,
runCommandNoCCLocal,
writeText,
}:
let
luaNames = {
Expand Down Expand Up @@ -45,9 +46,9 @@ let
];
};

drv = pkgs.writeText "example-derivation" "hello, world!";
drv = writeText "example-derivation" "hello, world!";

results = pkgs.lib.runTests {
results = lib.runTests {
testToLuaObject = {
expr = helpers.toLuaObject {
foo = "bar";
Expand Down Expand Up @@ -412,11 +413,11 @@ let
};
in
if results == [ ] then
pkgs.runCommand "lib-tests-success" { } "touch $out"
runCommandNoCCLocal "lib-tests-success" { } "touch $out"
else
pkgs.runCommand "lib-tests-failure"
runCommandNoCCLocal "lib-tests-failure"
{
results = pkgs.lib.concatStringsSep "\n" (
results = lib.concatStringsSep "\n" (
builtins.map (result: ''
${result.name}:
expected: ${lib.generators.toPretty { } result.expected}
Expand Down
5 changes: 3 additions & 2 deletions tests/main.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
callTest,
helpers,
lib ? pkgs.lib,
linkFarm,
pkgs,
pkgsUnfree,
}:
Expand Down Expand Up @@ -54,14 +55,14 @@ lib.pipe (testFiles ++ [ exampleFiles ]) [
}:
{
inherit name;
path = pkgs.linkFarm name (builtins.mapAttrs (moduleToTest file) cases);
path = linkFarm name (builtins.mapAttrs (moduleToTest file) cases);
}
))
(helpers.groupListBySize 10)
(lib.imap1 (
i: group: rec {
name = "test-${toString i}";
value = pkgs.linkFarm name group;
value = linkFarm name group;
}
))
builtins.listToAttrs
Expand Down
6 changes: 3 additions & 3 deletions tests/maintainers.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
pkgs ? import <nixpkgs> { },
lib ? pkgs.lib,
lib,
runCommandNoCCLocal,
}:
let
inherit (lib) attrNames filter length;
Expand All @@ -9,7 +9,7 @@ let
duplicates = filter (name: nixpkgsList ? ${name}) (attrNames nixvimList);
count = length duplicates;
in
pkgs.runCommand "maintainers-test" { inherit count duplicates; } ''
runCommandNoCCLocal "maintainers-test" { inherit count duplicates; } ''
if [ $count -gt 0 ]; then
echo "$count nixvim maintainers are also nixpkgs maintainers:"
for name in $duplicates; do
Expand Down

0 comments on commit 036e116

Please sign in to comment.