tests: add regression test for warnings + assertions

Ensure `mkTestDerivationFromNixvimModule` correctly test warnings & assertions.

Also did some minor cleanup:
- Call `failing-tests.nix` using `pkgs.callPackage`
- Replace repetive use of `testBuildFailure` with a wrapper
  `mkFailingNixvimTest`
This commit is contained in:
Matt Sturgeon 2024-08-28 00:20:37 +01:00
parent 4814147442
commit 1c879ec3aa
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
2 changed files with 62 additions and 18 deletions

View file

@ -1,22 +1,67 @@
{
pkgs,
linkFarmFromDrvs,
runCommandNoCCLocal,
mkTestDerivationFromNixvimModule,
}:
let
inherit (pkgs.testers) testBuildFailure;
failed = testBuildFailure (mkTestDerivationFromNixvimModule {
name = "prints-hello-world";
module = {
extraConfigLua = ''
print('Hello, world!')
'';
};
inherit pkgs;
});
# Wraps a call to mkTestDerivationFromNixvimModule with testers.testBuildFailure
mkFailingNixvimTest =
args: pkgs.testers.testBuildFailure (mkTestDerivationFromNixvimModule ({ inherit pkgs; } // args));
in
pkgs.runCommand "failing-test" { inherit failed; } ''
grep -F 'Hello, world!' "$failed/testBuildFailure.log"
[[ 1 = $(cat "$failed/testBuildFailure.exit") ]]
touch $out
''
linkFarmFromDrvs "failing-tests" [
(runCommandNoCCLocal "fail-running-nvim"
{
failed = mkFailingNixvimTest {
name = "prints-hello-world";
module = {
extraConfigLua = ''
print('Hello, world!')
'';
};
};
}
''
[[ 1 = $(cat "$failed/testBuildFailure.exit") ]]
grep -F 'ERROR: Hello, world!' "$failed/testBuildFailure.log"
touch $out
''
)
(runCommandNoCCLocal "fail-on-warnings"
{
failed = mkFailingNixvimTest {
name = "warns-hello-world";
module = {
warnings = [ "Hello, world!" ];
};
};
}
''
[[ 1 = $(cat "$failed/testBuildFailure.exit") ]]
grep -F 'Unexpected warnings:' "$failed/testBuildFailure.log"
grep -F 'Hello, world!' "$failed/testBuildFailure.log"
touch $out
''
)
(runCommandNoCCLocal "fail-on-assertions"
{
failed = mkFailingNixvimTest {
name = "asserts-hello-world";
module = {
assertions = [
{
assertion = false;
message = "Hello, world!";
}
];
};
};
}
''
[[ 1 = $(cat "$failed/testBuildFailure.exit") ]]
grep -F 'Unexpected assertions:' "$failed/testBuildFailure.log"
grep -F 'Hello, world!' "$failed/testBuildFailure.log"
touch $out
''
)
]