mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-09 03:56:05 +01:00
tests: cleanup tests to better use callTest pattern
e.g. Prefer taking `pkgs.*` attrs directly as function arguments.
This commit is contained in:
parent
4a508ceee2
commit
036e11665f
7 changed files with 33 additions and 20 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
{
|
{
|
||||||
pkgs,
|
pkgs,
|
||||||
|
linkFarm,
|
||||||
|
runCommandNoCCLocal,
|
||||||
mkTestDerivationFromNixvimModule,
|
mkTestDerivationFromNixvimModule,
|
||||||
makeNixvimWithModule,
|
makeNixvimWithModule,
|
||||||
}:
|
}:
|
||||||
|
|
@ -19,7 +21,7 @@ let
|
||||||
let
|
let
|
||||||
nvim = makeNixvimWithModule { inherit pkgs module; };
|
nvim = makeNixvimWithModule { inherit pkgs module; };
|
||||||
in
|
in
|
||||||
pkgs.runCommand "enable-except-in-tests-not-in-test"
|
runCommandNoCCLocal "enable-except-in-tests-not-in-test"
|
||||||
{ printConfig = "${nvim}/bin/nixvim-print-init"; }
|
{ printConfig = "${nvim}/bin/nixvim-print-init"; }
|
||||||
''
|
''
|
||||||
if ! "$printConfig" | grep 'require("image").setup'; then
|
if ! "$printConfig" | grep 'require("image").setup'; then
|
||||||
|
|
@ -31,7 +33,7 @@ let
|
||||||
touch $out
|
touch $out
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
pkgs.linkFarm "enable-except-in-tests" [
|
linkFarm "enable-except-in-tests" [
|
||||||
{
|
{
|
||||||
name = "in-test";
|
name = "in-test";
|
||||||
path = inTest;
|
path = inTest;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
{ makeNixvimWithModule, pkgs }:
|
{
|
||||||
|
makeNixvimWithModule,
|
||||||
|
runCommandNoCCLocal,
|
||||||
|
}:
|
||||||
let
|
let
|
||||||
firstStage = makeNixvimWithModule {
|
firstStage = makeNixvimWithModule {
|
||||||
module = {
|
module = {
|
||||||
|
|
@ -10,7 +13,7 @@ let
|
||||||
|
|
||||||
generated = secondStage.extend { extraConfigLua = "-- third stage"; };
|
generated = secondStage.extend { extraConfigLua = "-- third stage"; };
|
||||||
in
|
in
|
||||||
pkgs.runCommand "extend-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
|
runCommandNoCCLocal "extend-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
|
||||||
config=$($printConfig)
|
config=$($printConfig)
|
||||||
for stage in "first" "second" "third"; do
|
for stage in "first" "second" "third"; do
|
||||||
if ! "$printConfig" | grep -q -- "-- $stage stage"; then
|
if ! "$printConfig" | grep -q -- "-- $stage stage"; then
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
{ makeNixvimWithModule, pkgs }:
|
{
|
||||||
|
makeNixvimWithModule,
|
||||||
|
runCommandNoCCLocal,
|
||||||
|
}:
|
||||||
let
|
let
|
||||||
defaultModule =
|
defaultModule =
|
||||||
{ regularArg, ... }:
|
{ regularArg, ... }:
|
||||||
|
|
@ -28,7 +31,7 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
pkgs.runCommand "special-arg-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
|
runCommandNoCCLocal "special-arg-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
|
||||||
config=$($printConfig)
|
config=$($printConfig)
|
||||||
if ! "$printConfig" | grep -- '-- regularArg=regularValue'; then
|
if ! "$printConfig" | grep -- '-- regularArg=regularValue'; then
|
||||||
echo "Missing regularArg in config"
|
echo "Missing regularArg in config"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
{ makeNixvimWithModule, pkgs }:
|
{
|
||||||
|
makeNixvimWithModule,
|
||||||
|
runCommandNoCCLocal,
|
||||||
|
}:
|
||||||
let
|
let
|
||||||
extraFiles = {
|
extraFiles = {
|
||||||
"one".text = "one";
|
"one".text = "one";
|
||||||
|
|
@ -12,7 +15,7 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
pkgs.runCommand "extra-files-test"
|
runCommandNoCCLocal "extra-files-test"
|
||||||
{
|
{
|
||||||
root = build.config.build.extraFiles;
|
root = build.config.build.extraFiles;
|
||||||
files = builtins.attrNames extraFiles;
|
files = builtins.attrNames extraFiles;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
# For shorter test iterations run the following in the root of the repo:
|
# For shorter test iterations run the following in the root of the repo:
|
||||||
# `echo ':b checks.${builtins.currentSystem}.lib-tests' | nix repl .`
|
# `echo ':b checks.${builtins.currentSystem}.lib-tests' | nix repl .`
|
||||||
{
|
{
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
helpers,
|
helpers,
|
||||||
|
lib,
|
||||||
|
runCommandNoCCLocal,
|
||||||
|
writeText,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
luaNames = {
|
luaNames = {
|
||||||
|
|
@ -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 = {
|
testToLuaObject = {
|
||||||
expr = helpers.toLuaObject {
|
expr = helpers.toLuaObject {
|
||||||
foo = "bar";
|
foo = "bar";
|
||||||
|
|
@ -412,11 +413,11 @@ let
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
if results == [ ] then
|
if results == [ ] then
|
||||||
pkgs.runCommand "lib-tests-success" { } "touch $out"
|
runCommandNoCCLocal "lib-tests-success" { } "touch $out"
|
||||||
else
|
else
|
||||||
pkgs.runCommand "lib-tests-failure"
|
runCommandNoCCLocal "lib-tests-failure"
|
||||||
{
|
{
|
||||||
results = pkgs.lib.concatStringsSep "\n" (
|
results = lib.concatStringsSep "\n" (
|
||||||
builtins.map (result: ''
|
builtins.map (result: ''
|
||||||
${result.name}:
|
${result.name}:
|
||||||
expected: ${lib.generators.toPretty { } result.expected}
|
expected: ${lib.generators.toPretty { } result.expected}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
callTest,
|
callTest,
|
||||||
helpers,
|
helpers,
|
||||||
lib ? pkgs.lib,
|
lib ? pkgs.lib,
|
||||||
|
linkFarm,
|
||||||
pkgs,
|
pkgs,
|
||||||
pkgsUnfree,
|
pkgsUnfree,
|
||||||
}:
|
}:
|
||||||
|
|
@ -54,14 +55,14 @@ lib.pipe (testFiles ++ [ exampleFiles ]) [
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
inherit name;
|
inherit name;
|
||||||
path = pkgs.linkFarm name (builtins.mapAttrs (moduleToTest file) cases);
|
path = linkFarm name (builtins.mapAttrs (moduleToTest file) cases);
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
(helpers.groupListBySize 10)
|
(helpers.groupListBySize 10)
|
||||||
(lib.imap1 (
|
(lib.imap1 (
|
||||||
i: group: rec {
|
i: group: rec {
|
||||||
name = "test-${toString i}";
|
name = "test-${toString i}";
|
||||||
value = pkgs.linkFarm name group;
|
value = linkFarm name group;
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
builtins.listToAttrs
|
builtins.listToAttrs
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
pkgs ? import <nixpkgs> { },
|
lib,
|
||||||
lib ? pkgs.lib,
|
runCommandNoCCLocal,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib) attrNames filter length;
|
inherit (lib) attrNames filter length;
|
||||||
|
|
@ -9,7 +9,7 @@ let
|
||||||
duplicates = filter (name: nixpkgsList ? ${name}) (attrNames nixvimList);
|
duplicates = filter (name: nixpkgsList ? ${name}) (attrNames nixvimList);
|
||||||
count = length duplicates;
|
count = length duplicates;
|
||||||
in
|
in
|
||||||
pkgs.runCommand "maintainers-test" { inherit count duplicates; } ''
|
runCommandNoCCLocal "maintainers-test" { inherit count duplicates; } ''
|
||||||
if [ $count -gt 0 ]; then
|
if [ $count -gt 0 ]; then
|
||||||
echo "$count nixvim maintainers are also nixpkgs maintainers:"
|
echo "$count nixvim maintainers are also nixpkgs maintainers:"
|
||||||
for name in $duplicates; do
|
for name in $duplicates; do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue