Skip to content

Commit

Permalink
shouldMatchList: More concise error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Jan 21, 2021
1 parent c1ba41c commit 55f00d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/Test/Hspec/Expectations/Matcher.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ xs `matchList` ys
err :: ShowS
err =
showString "Actual list is not a permutation of expected list!\n"
. msgAndList " expected list contains: " ys
. msgAndList " actual list contains: " xs
. optMsgList " the missing elements are: " missing
. optMsgList " the extra elements are: " extra
. msgAndList " expected elements: " ys
. msgAndList " actual elements: " xs
. optMsgList " missing elements: " missing
. optMsgList " extra elements: " extra

showList :: Show a => [a] -> ShowS
showList xs = showChar '[' . foldr (.) (showChar ']') (intersperse (showString ", ") $ map shows xs)
12 changes: 6 additions & 6 deletions test/Test/Hspec/Expectations/MatcherSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ spec = do
it "shows extra elements" $ do
[1, 2, 2, 3] `matchList` [1, 2, 3 :: Int] `shouldBe` (Just . unlines) [
"Actual list is not a permutation of expected list!"
, " expected list contains: [1, 2, 3]"
, " actual list contains: [1, 2, 2, 3]"
, " the extra elements are: [2]"
, " expected elements: [1, 2, 3]"
, " actual elements: [1, 2, 2, 3]"
, " extra elements: [2]"
]

it "shows missing elements" $ do
[1, 2, 3] `matchList` [1, 2, 2, 3 :: Int] `shouldBe` (Just . unlines) [
"Actual list is not a permutation of expected list!"
, " expected list contains: [1, 2, 2, 3]"
, " actual list contains: [1, 2, 3]"
, " the missing elements are: [2]"
, " expected elements: [1, 2, 2, 3]"
, " actual elements: [1, 2, 3]"
, " missing elements: [2]"
]

0 comments on commit 55f00d0

Please sign in to comment.