From 1c879ec3aa6ab92d5700ec417dc1958354b8cf87 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 28 Aug 2024 00:20:37 +0100 Subject: [PATCH] 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` --- flake-modules/tests.nix | 3 +- tests/failing-tests.nix | 77 ++++++++++++++++++++++++++++++++--------- 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/flake-modules/tests.nix b/flake-modules/tests.nix index eb1f8419..674edbeb 100644 --- a/flake-modules/tests.nix +++ b/flake-modules/tests.nix @@ -25,8 +25,7 @@ inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule; }; - failing-tests = import ../tests/failing-tests.nix { - inherit pkgs; + failing-tests = pkgs.callPackage ../tests/failing-tests.nix { inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule; }; diff --git a/tests/failing-tests.nix b/tests/failing-tests.nix index 383eb988..67b142b3 100644 --- a/tests/failing-tests.nix +++ b/tests/failing-tests.nix @@ -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 + '' + ) +]