Skip to content

Commit

Permalink
Tweak failure format of shouldThrow
Browse files Browse the repository at this point in the history
(so that it works better for multi-line output)
  • Loading branch information
sol committed Jul 19, 2023
1 parent dfb5e34 commit 0c2f882
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.cabal linguist-generated
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ packages:

package hspec-expectations
ghc-options: -Werror

tests: True
2 changes: 1 addition & 1 deletion hspec-expectations.cabal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: hspec-expectations
version: 0.8.3
version: 0.8.4
synopsis: Catchy combinators for HUnit
description: "Catchy combinators for HUnit: <https://github.com/hspec/hspec-expectations#readme>"
license: MIT
Expand Down
4 changes: 2 additions & 2 deletions src/Test/Hspec/Expectations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ action `shouldThrow` p = do
"did not get expected exception: " ++ exceptionType
Left e ->
(`expectTrue` p e) $
"predicate failed on expected exception: " ++ exceptionType ++ " (" ++ show e ++ ")"
"predicate failed on expected exception: " ++ exceptionType ++ "\n" ++ show e
where
-- a string repsentation of the expected exception's type
-- a string representation of the expected exception's type
exceptionType = (show . typeOf . instanceOf) p
where
instanceOf :: Selector a -> a
Expand Down
2 changes: 1 addition & 1 deletion test/Test/Hspec/ExpectationsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ spec = do
error "foobar" `shouldThrow` errorCall "foobar"

it "fails, if a required specific exception is not thrown" $ do
(throwIO Overflow `shouldThrow` (== DivideByZero)) `shouldThrow` expectationFailed (Reason "predicate failed on expected exception: ArithException (arithmetic overflow)")
(throwIO Overflow `shouldThrow` (== DivideByZero)) `shouldThrow` expectationFailed (Reason "predicate failed on expected exception: ArithException\narithmetic overflow")

it "fails, if any exception is required, but no exception is thrown" $ do
(return () `shouldThrow` anyException) `shouldThrow` expectationFailed (Reason "did not get expected exception: SomeException")
Expand Down

0 comments on commit 0c2f882

Please sign in to comment.