hspec-expectations 0.8.1 → 0.8.2
raw patch · 2 files changed
+17/−25 lines, 2 filesdep ~HUnit
Dependency ranges changed: HUnit
Files
hspec-expectations.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: hspec-expectations-version: 0.8.1+version: 0.8.2 synopsis: Catchy combinators for HUnit description: Catchy combinators for HUnit: <https://github.com/hspec/hspec-expectations#readme> bug-reports: https://github.com/hspec/hspec-expectations/issues@@ -27,8 +27,8 @@ ghc-options: -Wall build-depends: base == 4.*- , HUnit , call-stack+ , HUnit exposed-modules: Test.Hspec.Expectations Test.Hspec.Expectations.Contrib@@ -46,9 +46,9 @@ ghc-options: -Wall build-depends: base == 4.*- , HUnit , call-stack , nanospec+ , HUnit >= 1.5.0.0 other-modules: Test.Hspec.Expectations.MatcherSpec Test.Hspec.ExpectationsSpec
test/Test/Hspec/ExpectationsSpec.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} module Test.Hspec.ExpectationsSpec (spec) where@@ -10,23 +9,16 @@ import Test.Hspec.Expectations hiding (HasCallStack) import Data.CallStack -expectationFailed :: HasCallStack => String -> HUnitFailure -> Bool+expectationFailed :: HasCallStack => FailureReason -> HUnitFailure -> Bool expectationFailed msg (HUnitFailure l m) = m == msg && (fmap setColumn l) == (fmap setColumn location) where location = case reverse callStack of [] -> Nothing-#if MIN_VERSION_HUnit(1,4,0) (_, loc) : _ -> Just loc location :: Maybe SrcLoc setColumn loc_ = loc_{srcLocStartCol = 0, srcLocEndCol = 0}-#else- (_, loc) : _ -> Just $ Location (srcLocFile loc) (srcLocStartLine loc) 0- location :: Maybe Location - setColumn loc_ = loc_{locationColumn = 0}-#endif- spec :: Spec spec = do describe "shouldBe" $ do@@ -34,70 +26,70 @@ "foo" `shouldBe` "foo" it "fails if arguments are not equal" $ do- ("foo" `shouldBe` "bar") `shouldThrow` expectationFailed "expected: \"bar\"\n but got: \"foo\""+ ("foo" `shouldBe` "bar") `shouldThrow` expectationFailed (ExpectedButGot Nothing "\"bar\"" "\"foo\"") describe "shouldSatisfy" $ do it "succeeds if value satisfies predicate" $ do "" `shouldSatisfy` null it "fails if value does not satisfy predicate" $ do- ("foo" `shouldSatisfy` null) `shouldThrow` expectationFailed "predicate failed on: \"foo\""+ ("foo" `shouldSatisfy` null) `shouldThrow` expectationFailed (Reason "predicate failed on: \"foo\"") describe "shouldReturn" $ do it "succeeds if arguments represent equal values" $ do return "foo" `shouldReturn` "foo" it "fails if arguments do not represent equal values" $ do- (return "foo" `shouldReturn` "bar") `shouldThrow` expectationFailed "expected: \"bar\"\n but got: \"foo\""+ (return "foo" `shouldReturn` "bar") `shouldThrow` expectationFailed (ExpectedButGot Nothing "\"bar\"" "\"foo\"") describe "shouldStartWith" $ do it "succeeds if second is prefix of first" $ do "hello world" `shouldStartWith` "hello" it "fails if second is not prefix of first" $ do- ("hello world" `shouldStartWith` "world") `shouldThrow` expectationFailed "\"hello world\" does not start with \"world\""+ ("hello world" `shouldStartWith` "world") `shouldThrow` expectationFailed (Reason "\"hello world\" does not start with \"world\"") describe "shouldEndWith" $ do it "succeeds if second is suffix of first" $ do "hello world" `shouldEndWith` "world" it "fails if second is not suffix of first" $ do- ("hello world" `shouldEndWith` "hello") `shouldThrow` expectationFailed "\"hello world\" does not end with \"hello\""+ ("hello world" `shouldEndWith` "hello") `shouldThrow` expectationFailed (Reason "\"hello world\" does not end with \"hello\"") describe "shouldContain" $ do it "succeeds if second argument is contained in the first" $ do "I'm an hello world message" `shouldContain` "an hello" it "fails if first argument does not contain the second" $ do- ("foo" `shouldContain` "bar") `shouldThrow` expectationFailed "\"foo\" does not contain \"bar\""+ ("foo" `shouldContain` "bar") `shouldThrow` expectationFailed (Reason "\"foo\" does not contain \"bar\"") describe "shouldNotBe" $ do it "succeeds if arguments are not equal" $ do "foo" `shouldNotBe` "bar" it "fails if arguments are equal" $ do- ("foo" `shouldNotBe` "foo") `shouldThrow` expectationFailed "not expected: \"foo\""+ ("foo" `shouldNotBe` "foo") `shouldThrow` expectationFailed (Reason "not expected: \"foo\"") describe "shouldNotSatisfy" $ do it "succeeds if value does not satisfy predicate" $ do "bar" `shouldNotSatisfy` null it "fails if the value does satisfy predicate" $ do- ("" `shouldNotSatisfy` null) `shouldThrow` expectationFailed "predicate succeeded on: \"\""+ ("" `shouldNotSatisfy` null) `shouldThrow` expectationFailed (Reason "predicate succeeded on: \"\"") describe "shouldNotReturn" $ do it "succeeds if arguments does not represent equal values" $ do return "foo" `shouldNotReturn` "bar" it "fails if arguments do represent equal values" $ do- (return "foo" `shouldNotReturn` "foo") `shouldThrow` expectationFailed "not expected: \"foo\""+ (return "foo" `shouldNotReturn` "foo") `shouldThrow` expectationFailed (Reason "not expected: \"foo\"") describe "shouldNotContain" $ do it "succeeds if second argument is not contained in the first" $ do "I'm an hello world message" `shouldNotContain` "test" it "fails if first argument does contain the second" $ do- ("foo abc def" `shouldNotContain` "def") `shouldThrow` expectationFailed "\"foo abc def\" does contain \"def\""+ ("foo abc def" `shouldNotContain` "def") `shouldThrow` expectationFailed (Reason "\"foo abc def\" does contain \"def\"") describe "shouldThrow" $ do it "can be used to require a specific exception" $ do@@ -113,10 +105,10 @@ error "foobar" `shouldThrow` errorCall "foobar" it "fails, if a required specific exception is not thrown" $ do- (throwIO Overflow `shouldThrow` (== DivideByZero)) `shouldThrow` expectationFailed "predicate failed on expected exception: ArithException (arithmetic overflow)"+ (throwIO Overflow `shouldThrow` (== DivideByZero)) `shouldThrow` expectationFailed (Reason "predicate failed on expected exception: ArithException (arithmetic overflow)") it "fails, if any exception is required, but no exception is thrown" $ do- (return () `shouldThrow` anyException) `shouldThrow` expectationFailed "did not get expected exception: SomeException"+ (return () `shouldThrow` anyException) `shouldThrow` expectationFailed (Reason "did not get expected exception: SomeException") it "fails, if an exception of a specific type is required, but no exception is thrown" $ do- (return () `shouldThrow` anyErrorCall) `shouldThrow` expectationFailed "did not get expected exception: ErrorCall"+ (return () `shouldThrow` anyErrorCall) `shouldThrow` expectationFailed (Reason "did not get expected exception: ErrorCall")