From 520047b47f494aaac3d7de24ddfb71dbf99ba35c Mon Sep 17 00:00:00 2001 From: rhiannon morris Date: Fri, 27 May 2022 13:31:01 +0200 Subject: [PATCH] add testThrowsIO --- TAP.idr | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/TAP.idr b/TAP.idr index 483fd9b..22ffd75 100644 --- a/TAP.idr +++ b/TAP.idr @@ -126,7 +126,7 @@ export skip : Test -> Test skip = skipWith "" -||| test that an expression fails in an expected way. +||| test that an action fails in an expected way. ||| - if the body returns `Left err` and the predicate given returns `True`, ||| then the test succeeds ||| - if the body returns `Left err` and the predicate given returns `False`, @@ -134,13 +134,19 @@ skip = skipWith "" ||| - if the body returns `Right val`, then the test fails with ||| `{success: val}` export -testThrows : (ToInfo e, Show a) => - String -> (e -> Bool) -> Lazy (Either e a) -> Test -testThrows label p act = One $ MakeTest label $ do - case !(lazyToIO act) of +testThrowsIO : (ToInfo e, Show a) => + String -> (e -> Bool) -> EitherT e IO a -> Test +testThrowsIO label p act = One $ MakeTest label $ do + case !(runEitherT act) of Left err => if p err then result True () else result False err Right val => result False [("success", val)] +||| pure version of `testThrowsIO` +export +testThrows : (ToInfo e, Show a) => + String -> (e -> Bool) -> Lazy (Either e a) -> Test +testThrows label p act = testThrowsIO label p $ MkEitherT $ lazyToIO act + infix 1 :- ||| make a test group export