hspec-expectations-pretty-diff 0.7.2.4 → 0.7.2.5
raw patch · 3 files changed
+26/−5 lines, 3 files
Files
- hspec-expectations-pretty-diff.cabal +1/−1
- src/Test/Hspec/Expectations/Pretty.hs +12/−2
- test/Test/Hspec/Expectations/PrettySpec.hs +13/−2
hspec-expectations-pretty-diff.cabal view
@@ -1,5 +1,5 @@ name: hspec-expectations-pretty-diff-version: 0.7.2.4+version: 0.7.2.5 synopsis: Catchy combinators for HUnit description: Catchy combinators for HUnit: <https://github.com/myfreeweb/hspec-expectations-pretty-diff#readme> bug-reports: https://github.com/myfreeweb/hspec-expectations-pretty-diff/issues
src/Test/Hspec/Expectations/Pretty.hs view
@@ -56,7 +56,11 @@ import Control.Exception import Data.Typeable import Data.List-import Data.Algorithm.Diff (getDiff, Diff(..))+#if MIN_VERSION_Diff(0,4,0)+import Data.Algorithm.Diff (getDiff, PolyDiff(First, Second, Both))+#else+import Data.Algorithm.Diff (getDiff, Diff(First, Second, Both))+#endif import Language.Haskell.HsColour hiding (layout) import Language.Haskell.HsColour.Colourise (defaultColourPrefs)@@ -68,7 +72,13 @@ import Test.Hspec.Expectations.Pretty.Matcher -#ifdef HAS_SOURCE_LOCATIONS+#if defined(HAS_SOURCE_LOCATIONS) && MIN_VERSION_HUnit(1,4,0)++import GHC.Stack++#define with_loc(NAME, TYPE) NAME :: (?callStack :: CallStack) => TYPE++#elif defined(HAS_SOURCE_LOCATIONS) import GHC.Stack
test/Test/Hspec/Expectations/PrettySpec.hs view
@@ -6,13 +6,20 @@ import Test.HUnit.Lang import Test.Hspec (Spec, describe, it) import Data.Aeson+import Data.List (isPrefixOf) import Data.Text (pack)+import GHC.Stack (srcLocModule) import Test.Hspec.Expectations.Pretty expectationFailed :: String -> HUnitFailure -> Bool-expectationFailed msg (HUnitFailure _ msg') = msg == msg'+expectationFailed msg (HUnitFailure _ failureReason) =+ msg == formatFailureReason failureReason +expectationFailedPrefix :: String -> HUnitFailure -> Bool+expectationFailedPrefix msg (HUnitFailure _ failureReason) =+ msg `isPrefixOf` formatFailureReason failureReason+ data TestStructure = TestStructure String Int [TestStructure] deriving (Show, Eq) @@ -27,6 +34,10 @@ ([ TestStructure "outer" 123 [ TestStructure "inner" 456 [] ] ] `shouldBe` [ TestStructure "outer" 123 [ TestStructure "inner" 457 [] ] ]) `shouldThrow` expectationFailed " \ESC[31m[\ESC[0m\ESC[0m\n \ESC[0m\ESC[0m \ESC[0m\ESC[0mTestStructure\ESC[0m\ESC[0m \ESC[0m\ESC[35m\"outer\"\ESC[0m\ESC[0m \ESC[0m\ESC[35m123\ESC[0m\ESC[0m \ESC[0m\ESC[31m[\ESC[0m\ESC[0m\n\ESC[31m---\ESC[0m\ESC[0m\ESC[0m \ESC[0m\ESC[0mTestStructure\ESC[0m\ESC[0m \ESC[0m\ESC[35m\"inner\"\ESC[0m\ESC[0m \ESC[0m\ESC[35m457\ESC[0m\ESC[0m \ESC[0m\ESC[0m[]\ESC[0m\ESC[0m\n\ESC[32m+++\ESC[0m\ESC[0m\ESC[0m \ESC[0m\ESC[0mTestStructure\ESC[0m\ESC[0m \ESC[0m\ESC[35m\"inner\"\ESC[0m\ESC[0m \ESC[0m\ESC[35m456\ESC[0m\ESC[0m \ESC[0m\ESC[0m[]\ESC[0m\ESC[0m\n \ESC[0m\ESC[0m \ESC[0m\ESC[31m]\ESC[0m\ESC[0m\n \ESC[0m\ESC[31m]\ESC[0m\n" (object [ pack "foo" .= object [ pack "bar" .= Number 123 ] ] `shouldBe` object [ pack "foo" .= object [ pack "bar" .= Number 234, pack "quux" .= Number 567 ] ]) `shouldThrow` expectationFailed " \ESC[0mObject\ESC[0m\ESC[0m \ESC[0m\ESC[36m(\ESC[0m\ESC[0mfromList\ESC[0m\ESC[0m \ESC[0m\ESC[31m[\ESC[0m\ESC[0m\n \ESC[0m\ESC[0m \ESC[0m\ESC[36m(\ESC[0m\ESC[35m\"foo\"\ESC[0m\ESC[36m,\ESC[0m\ESC[0m\n \ESC[0m\ESC[0m \ESC[0m\ESC[0mObject\ESC[0m\ESC[0m \ESC[0m\ESC[36m(\ESC[0m\ESC[0mfromList\ESC[0m\ESC[0m \ESC[0m\ESC[31m[\ESC[0m\ESC[0m\n\ESC[31m---\ESC[0m\ESC[0m\ESC[0m \ESC[0m\ESC[36m(\ESC[0m\ESC[35m\"quux\"\ESC[0m\ESC[36m,\ESC[0m\ESC[0m\n\ESC[31m---\ESC[0m\ESC[0m\ESC[0m \ESC[0m\ESC[0mNumber\ESC[0m\ESC[0m \ESC[0m\ESC[35m567.0\ESC[0m\ESC[36m)\ESC[0m\ESC[36m,\ESC[0m\ESC[0m\n \ESC[0m\ESC[0m \ESC[0m\ESC[36m(\ESC[0m\ESC[35m\"bar\"\ESC[0m\ESC[36m,\ESC[0m\ESC[0m\n\ESC[31m---\ESC[0m\ESC[0m\ESC[0m \ESC[0m\ESC[0mNumber\ESC[0m\ESC[0m \ESC[0m\ESC[35m234.0\ESC[0m\ESC[36m)\ESC[0m\ESC[0m\n\ESC[32m+++\ESC[0m\ESC[0m\ESC[0m \ESC[0m\ESC[0mNumber\ESC[0m\ESC[0m \ESC[0m\ESC[35m123.0\ESC[0m\ESC[36m)\ESC[0m\ESC[0m\n \ESC[0m\ESC[0m \ESC[0m\ESC[31m]\ESC[0m\ESC[36m)\ESC[0m\ESC[36m)\ESC[0m\ESC[0m\n \ESC[0m\ESC[31m]\ESC[0m\ESC[36m)\ESC[0m\n" + it "includes the test location in the call stack when it fails" $+ ("foo" `shouldBe` "bar") `shouldThrow` \(HUnitFailure srcLocMaybe _) ->+ fmap srcLocModule srcLocMaybe == Just "Test.Hspec.Expectations.PrettySpec"+ describe "shouldSatisfy" $ do it "succeeds if value satisfies predicate" $ do "" `shouldSatisfy` null@@ -113,4 +124,4 @@ (return () `shouldThrow` anyErrorCall) `shouldThrow` expectationFailed "did not get expected exception: ErrorCall" it "fails, if a required specific exception is not thrown" $ do- (error "foo" `shouldThrow` errorCall "foobar") `shouldThrow` expectationFailed "predicate failed on expected exception: ErrorCall (foo)"+ (error "foo" `shouldThrow` errorCall "foobar") `shouldThrow` expectationFailedPrefix "predicate failed on expected exception: ErrorCall (foo"