about summary refs log tree commit diff
path: root/nix/runTestsuite
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-01-31T18·22+0100
committersterni <sternenseemann@systemli.org>2021-02-09T21·57+0000
commitfde23c5d0af0c09bccbfa6c3402bfaeae9bf88e0 (patch)
tree69907a790f6b4ea8edfad4c24b19e52d032c16cd /nix/runTestsuite
parent00f79da3581d5902ad1b45795cdf9334d6becad3 (diff)
feat(nix/runTestsuite): add assertDoesNotThrow r/2198
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 <mail@profpatsch.de>
Diffstat (limited to 'nix/runTestsuite')
-rw-r--r--nix/runTestsuite/default.nix7
1 files changed, 7 insertions, 0 deletions
diff --git a/nix/runTestsuite/default.nix b/nix/runTestsuite/default.nix
index 18206b67d8..5bb0ce1f85 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
     ;