diff options
author | Profpatsch <mail@profpatsch.de> | 2021-01-29T19·53+0100 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2021-01-30T11·44+0000 |
commit | f4a4da134b42e3fcb95101e98aaba6d23c35e193 (patch) | |
tree | 4b4b6299a991dda5166a306e9cc4c7f3b88161bc /nix | |
parent | 7f091079ce834775abcd4840ca42122727f4593e (diff) |
feat(nix/runTestsuite): add assertThrows r/2162
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>
Diffstat (limited to 'nix')
-rw-r--r-- | nix/runTestsuite/default.nix | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/nix/runTestsuite/default.nix b/nix/runTestsuite/default.nix index 6d2befc863fe..9ac9f87d45fa 100644 --- a/nix/runTestsuite/default.nix +++ b/nix/runTestsuite/default.nix @@ -56,11 +56,15 @@ let yep = struct "yep" { test = string; }; - nope = struct "nope" { + nope-eq = struct "nope-eq" { test = string; left = any; right = any; }; + nope-throw = struct "nope-throw" { + test = string; + expr = any; + }; }; # Result of an it. An it is a bunch of asserts @@ -76,12 +80,23 @@ let (desc: left: right: if left == right then { yep = { test = desc; }; } - else { nope = { + else { nope-eq = { test = desc; 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 it = desc: asserts: { it-desc = desc; @@ -99,7 +114,8 @@ let goodAss = ass: { good = AssertResult.match ass { yep = _: true; - nope = _: false; + nope-eq = _: false; + nope-throw = _: false; }; x = ass; }; @@ -108,7 +124,8 @@ let asserts = partitionTests (ass: AssertResult.match ass { yep = _: true; - nope = _: false; + nope-eq = _: false; + nope-throw = _: false; }) it.asserts; }; goodIts = partitionTests (it: (goodIt it).asserts.err == []); @@ -133,6 +150,7 @@ let in { inherit assertEq + assertThrows it runTestsuite ; |