Skip to content

Commit

Permalink
hspec-contrib: Handle exceptions in retryWith
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Oct 26, 2016
1 parent 8178f41 commit 985d4fb
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions hspec-contrib/src/Test/Hspec/Contrib/Retry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ data Retry a = Retry Int a

instance Example a => Example (Retry a) where
type Arg (Retry a) = Arg a
evaluateExample (Retry n example) a b c = do
v <- evaluateExample example a b c
case v of
Success -> return v
_ | n > 1 -> evaluateExample (Retry (pred n) example) a b c
_ -> return v
evaluateExample (Retry n example) a b c
| n > 1 = do
r <- safeEvaluateExample example a b c
case r of
Right result -> case result of
Success{} -> return result
Pending{} -> return result
Failure{} -> retry
Left _ -> retry
| otherwise = evaluateExample example a b c
where
retry = evaluateExample (Retry (pred n) example) a b c

-- | Retry evaluating example that may be failed until success.
retryWith :: Int
Expand Down

0 comments on commit 985d4fb

Please sign in to comment.