hspec-expectations 0.6.0.1 → 0.6.1
raw patch · 3 files changed
+33/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- hspec-expectations.cabal +3/−1
- src/Test/Hspec/Expectations.hs +4/−4
- src/Test/Hspec/Expectations/Matcher.hs +26/−0
hspec-expectations.cabal view
@@ -1,5 +1,5 @@ name: hspec-expectations-version: 0.6.0.1+version: 0.6.1 synopsis: Catchy combinators for HUnit description: Catchy combinators for HUnit: <https://github.com/sol/hspec-expectations#readme> license: MIT@@ -27,6 +27,8 @@ exposed-modules: Test.Hspec.Expectations , Test.Hspec.Expectations.Contrib+ other-modules:+ Test.Hspec.Expectations.Matcher test-suite spec main-is:
src/Test/Hspec/Expectations.hs view
@@ -40,8 +40,10 @@ import Test.HUnit (Assertion, (@?=), assertBool, assertFailure) import Control.Exception import Data.Typeable-import Data.List ((\\), isInfixOf)+import Data.List (isInfixOf) +import Test.Hspec.Expectations.Matcher+ type Expectation = Assertion -- | This is just an alias for HUnit's `assertFailure`.@@ -73,9 +75,7 @@ -- @xs \`shouldMatchList\` ys@ sets the expectation that @xs@ has the same -- elements that @ys@ has, possibly in another order shouldMatchList :: (Show a, Eq a) => [a] -> [a] -> Expectation-xs `shouldMatchList` ys = assertBool errorMsg (all null [xs \\ ys, ys \\ xs])- where- errorMsg = show ys ++ " is not a permutation of " ++ show xs+xs `shouldMatchList` ys = maybe (return ()) assertFailure (matchList xs ys) -- | -- @action \`shouldReturn\` expected@ sets the expectation that @action@
+ src/Test/Hspec/Expectations/Matcher.hs view
@@ -0,0 +1,26 @@+module Test.Hspec.Expectations.Matcher (matchList) where++import Prelude hiding (showList)+import Data.List++matchList :: (Show a, Eq a) => [a] -> [a] -> Maybe String+xs `matchList` ys+ | null extra && null missing = Nothing+ | otherwise = Just (err "")+ where+ extra = xs \\ ys+ missing = ys \\ xs++ msgAndList msg zs = showString msg . showList zs . showString "\n"+ optMsgList msg zs = if null zs then id else msgAndList msg zs++ 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++showList :: Show a => [a] -> ShowS+showList xs = showChar '[' . foldr (.) (showChar ']') (intersperse (showString ", ") $ map shows xs)