From fde23c5d0af0c09bccbfa6c3402bfaeae9bf88e0 Mon Sep 17 00:00:00 2001 From: sterni Date: Sun, 31 Jan 2021 19:22:35 +0100 Subject: [PATCH] feat(nix/runTestsuite): add assertDoesNotThrow assertDoesNotThrow is like assertThrows, but fails if the expression throws. In that case the new unexpected-throw branch of AssertErrorContext is returned. Change-Id: I7195eb5df8965456e9ab9b69e35ec96b33f00a35 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2476 Tested-by: BuildkiteCI Reviewed-by: Profpatsch --- nix/runTestsuite/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nix/runTestsuite/default.nix b/nix/runTestsuite/default.nix index 18206b67d..5bb0ce1f8 100644 --- a/nix/runTestsuite/default.nix +++ b/nix/runTestsuite/default.nix @@ -61,6 +61,7 @@ let should-throw = struct "should-throw" { expr = any; }; + unexpected-throw = struct "unexpected-throw" { }; }; # The result of an assert, @@ -119,6 +120,11 @@ let in assertBoolContext context desc (throws expr)); + # assert that the expression does not throw when `deepSeq`-ed + assertDoesNotThrow = defun [ string any AssertResult ] + (desc: expr: + assertBoolContext { unexpected-throw = { }; } desc (!(throws expr))); + # Annotate a bunch of asserts with a descriptive name it = desc: asserts: { it-desc = desc; @@ -171,6 +177,7 @@ in { inherit assertEq assertThrows + assertDoesNotThrow it runTestsuite ;