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 <mail@profpatsch.de>
This commit is contained in:
sterni 2021-01-31 19:22:35 +01:00
parent 00f79da358
commit fde23c5d0a

View file

@ -61,6 +61,7 @@ let
should-throw = struct "should-throw" { should-throw = struct "should-throw" {
expr = any; expr = any;
}; };
unexpected-throw = struct "unexpected-throw" { };
}; };
# The result of an assert, # The result of an assert,
@ -119,6 +120,11 @@ let
in in
assertBoolContext context desc (throws expr)); 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 # Annotate a bunch of asserts with a descriptive name
it = desc: asserts: { it = desc: asserts: {
it-desc = desc; it-desc = desc;
@ -171,6 +177,7 @@ in {
inherit inherit
assertEq assertEq
assertThrows assertThrows
assertDoesNotThrow
it it
runTestsuite runTestsuite
; ;