feat(nix/runTestsuite): add assertThrows
Uses `builtins.tryEval` to check that the expression throws when `deepSeq`-ed. Change-Id: I0d57cc37f473bb733f57a1b1c0d889084152fd2f Reviewed-on: https://cl.tvl.fyi/c/depot/+/2463 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
7f091079ce
commit
f4a4da134b
1 changed files with 22 additions and 4 deletions
|
@ -56,11 +56,15 @@ let
|
||||||
yep = struct "yep" {
|
yep = struct "yep" {
|
||||||
test = string;
|
test = string;
|
||||||
};
|
};
|
||||||
nope = struct "nope" {
|
nope-eq = struct "nope-eq" {
|
||||||
test = string;
|
test = string;
|
||||||
left = any;
|
left = any;
|
||||||
right = any;
|
right = any;
|
||||||
};
|
};
|
||||||
|
nope-throw = struct "nope-throw" {
|
||||||
|
test = string;
|
||||||
|
expr = any;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Result of an it. An it is a bunch of asserts
|
# Result of an it. An it is a bunch of asserts
|
||||||
|
@ -76,12 +80,23 @@ let
|
||||||
(desc: left: right:
|
(desc: left: right:
|
||||||
if left == right
|
if left == right
|
||||||
then { yep = { test = desc; }; }
|
then { yep = { test = desc; }; }
|
||||||
else { nope = {
|
else { nope-eq = {
|
||||||
test = desc;
|
test = desc;
|
||||||
inherit left right;
|
inherit left right;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
# assert that the expression throws when `deepSeq`-ed
|
||||||
|
assertThrows = defun [ string any AssertResult ]
|
||||||
|
(desc: expr:
|
||||||
|
if ! (builtins.tryEval (builtins.deepSeq expr {})).success
|
||||||
|
then { yep = { test = desc; }; }
|
||||||
|
else { nope-throw = {
|
||||||
|
test = desc;
|
||||||
|
inherit 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;
|
||||||
|
@ -99,7 +114,8 @@ let
|
||||||
goodAss = ass: {
|
goodAss = ass: {
|
||||||
good = AssertResult.match ass {
|
good = AssertResult.match ass {
|
||||||
yep = _: true;
|
yep = _: true;
|
||||||
nope = _: false;
|
nope-eq = _: false;
|
||||||
|
nope-throw = _: false;
|
||||||
};
|
};
|
||||||
x = ass;
|
x = ass;
|
||||||
};
|
};
|
||||||
|
@ -108,7 +124,8 @@ let
|
||||||
asserts = partitionTests (ass:
|
asserts = partitionTests (ass:
|
||||||
AssertResult.match ass {
|
AssertResult.match ass {
|
||||||
yep = _: true;
|
yep = _: true;
|
||||||
nope = _: false;
|
nope-eq = _: false;
|
||||||
|
nope-throw = _: false;
|
||||||
}) it.asserts;
|
}) it.asserts;
|
||||||
};
|
};
|
||||||
goodIts = partitionTests (it: (goodIt it).asserts.err == []);
|
goodIts = partitionTests (it: (goodIt it).asserts.err == []);
|
||||||
|
@ -133,6 +150,7 @@ let
|
||||||
in {
|
in {
|
||||||
inherit
|
inherit
|
||||||
assertEq
|
assertEq
|
||||||
|
assertThrows
|
||||||
it
|
it
|
||||||
runTestsuite
|
runTestsuite
|
||||||
;
|
;
|
||||||
|
|
Loading…
Reference in a new issue