packages feed

hspec-expectations 0.6.1.1 → 0.7.0

raw patch · 5 files changed

+61/−179 lines, 5 filesdep −hspecdep −markdown-unlitdep −silentlydep ~basePVP ok

version bump matches the API change (PVP)

Dependencies removed: hspec, markdown-unlit, silently

Dependency ranges changed: base

API changes (from Hackage documentation)

- Test.Hspec.Expectations.Contrib: shouldNotBe :: (Show a, Eq a) => a -> a -> Expectation
- Test.Hspec.Expectations.Contrib: shouldNotContain :: (Show a, Eq a) => [a] -> [a] -> Expectation
- Test.Hspec.Expectations.Contrib: shouldNotReturn :: (Show a, Eq a) => IO a -> a -> Expectation
- Test.Hspec.Expectations.Contrib: shouldNotSatisfy :: Show a => a -> (a -> Bool) -> Expectation
+ Test.Hspec.Expectations: shouldEndWith :: (Show a, Eq a) => [a] -> [a] -> Expectation
+ Test.Hspec.Expectations: shouldNotBe :: (Show a, Eq a) => a -> a -> Expectation
+ Test.Hspec.Expectations: shouldNotContain :: (Show a, Eq a) => [a] -> [a] -> Expectation
+ Test.Hspec.Expectations: shouldNotReturn :: (Show a, Eq a) => IO a -> a -> Expectation
+ Test.Hspec.Expectations: shouldNotSatisfy :: Show a => a -> (a -> Bool) -> Expectation
+ Test.Hspec.Expectations: shouldStartWith :: (Show a, Eq a) => [a] -> [a] -> Expectation

Files

− README.lhs
@@ -1,107 +0,0 @@-# Catchy combinators for HUnit--(inspired by [ScalaTest's ShouldMatchers](http://www.scalatest.org/))--The three main primitives are `shouldBe`, `shouldSatisfy` and-`shouldThrow`. They can be used with-[HUnit](http://hackage.haskell.org/package/HUnit), or any framework that-integrates with HUnit, like-[test-framework](http://hackage.haskell.org/package/test-framework) or-[Hspec](http://hackage.haskell.org/package/hspec).--## An introductory example--Here is an example that uses Hspec. It's a partial specification of-itself.--~~~ {.haskell .literate}-import Test.Hspec-import Control.Exception--main :: IO ()-main = hspec $ do-  describe "shouldBe" $ do-    it "asserts equality" $ do-      "foo" `shouldBe` "foo"--  describe "shouldSatisfy" $ do-    it "asserts that a predicate holds" $ do-      "bar" `shouldSatisfy` (not . null)--  describe "shouldThrow" $ do-    it "asserts that an exception is thrown" $ do-      evaluate (1 `div` 0 :: Int) `shouldThrow` (== DivideByZero)-~~~--## shouldBe--`shouldBe` is just an alias for HUnit's `@?=`.--## shouldSatisfy--`shouldSatisfy` asserts that some predicate holds for a given value.--~~~ {.haskell}-"bar" `shouldSatisfy` (not . null)-~~~--It is similar to HUnit's `assertBool`, but gives a useful error message.--    >>> 23 `shouldSatisfy` (> 42)-    *** Exception: HUnitFailure "23 did not satisfy predicate!"--## shouldReturn--`shouldReturn` asserts that an action returns a given value.--~~~ {.haskell}-launchMissiles `shouldReturn` Left "permission error"-~~~--## shouldThrow--`shouldThrow` asserts that an exception is thrown. The precise nature of-that exception is described with a `Selector`.--~~~ {.haskell}-error "foobar" `shouldThrow` anyException-~~~--A `Selector` is a predicate, it can simultaneously constrain the type-and value of an exception.--~~~ {.haskell}-throw DivideByZero `shouldThrow` (== DivideByZero)-~~~--To select all exceptions of a given type, `const True` can be used.--~~~ {.haskell}-error "foobar" `shouldThrow` (const True :: Selector ErrorCall)-~~~--For convenience, predefined selectors for some standard exceptions are-provided.--~~~ {.haskell}-error "foobar" `shouldThrow` anyErrorCall-~~~--Some exceptions (like `ErrorCall`) have no `Eq` instance, so checking-for a specific value requires pattern matching.--~~~ {.haskell}-error "foobar" `shouldThrow` (\e -> case e of-    ErrorCall "foobar" -> True-    _ -> False-    )-~~~--For such exceptions, combinators that construct selectors are provided.-Each combinator corresponds to a constructor; it takes the same-arguments, and has the same name (but starting with a lower-case-letter).--~~~ {.haskell}-error "foobar" `shouldThrow` errorCall "foobar"-~~~
hspec-expectations.cabal view
@@ -1,5 +1,5 @@ name:             hspec-expectations-version:          0.6.1.1+version:          0.7.0 synopsis:         Catchy combinators for HUnit description:      Catchy combinators for HUnit: <https://github.com/sol/hspec-expectations#readme> license:          MIT@@ -29,31 +29,3 @@     , Test.Hspec.Expectations.Contrib   other-modules:       Test.Hspec.Expectations.Matcher--test-suite spec-  main-is:-      Spec.hs-  type:-      exitcode-stdio-1.0-  ghc-options:-      -Wall-  hs-source-dirs:-      src-    , test-  build-depends:-      base-    , HUnit-    , silently-    , hspec == 2.*--test-suite readme-  type:-      exitcode-stdio-1.0-  ghc-options:-      -Wall -pgmL markdown-unlit -optL haskell+literate-  main-is:-      README.lhs-  build-depends:-      base-    , hspec >= 1.3-    , markdown-unlit
src/Test/Hspec/Expectations.hs view
@@ -7,10 +7,17 @@ , expectationFailure , shouldBe , shouldSatisfy+, shouldStartWith+, shouldEndWith , shouldContain , shouldMatchList , shouldReturn +, shouldNotBe+, shouldNotSatisfy+, shouldNotContain+, shouldNotReturn+ -- * Expecting exceptions , shouldThrow @@ -40,7 +47,7 @@ import           Test.HUnit (Assertion, (@?=), assertBool, assertFailure) import           Control.Exception import           Data.Typeable-import           Data.List (isInfixOf)+import           Data.List  import           Test.Hspec.Expectations.Matcher @@ -50,7 +57,8 @@ expectationFailure :: String -> Expectation expectationFailure = assertFailure -infix 1 `shouldBe`, `shouldSatisfy`, `shouldContain`, `shouldMatchList`, `shouldReturn`, `shouldThrow`+infix 1 `shouldBe`, `shouldSatisfy`, `shouldStartWith`, `shouldEndWith`, `shouldContain`, `shouldMatchList`, `shouldReturn`, `shouldThrow`+infix 1 `shouldNotBe`, `shouldNotSatisfy`, `shouldNotContain`, `shouldNotReturn`  -- | -- @actual \`shouldBe\` expected@ sets the expectation that @actual@ is equal@@ -63,13 +71,26 @@ shouldSatisfy :: (Show a) => a -> (a -> Bool) -> Expectation v `shouldSatisfy` p = assertBool ("predicate failed on: " ++ show v) (p v) +compareWith :: (Show a, Eq a) => (a -> a -> Bool) -> String -> a -> a -> Expectation+compareWith comparator errorDesc result expected =  assertBool errorMsg (comparator expected result)+  where+    errorMsg = show result ++ " " ++ errorDesc ++ " " ++ show expected+ -- |+-- @list \`shouldStartWith\` prefix@ sets the expectation that @list@ starts with @prefix@,+shouldStartWith :: (Show a, Eq a) => [a] -> [a] -> Expectation+shouldStartWith = compareWith isPrefixOf "does not start with"++-- |+-- @list \`shouldEndWith\` suffix@ sets the expectation that @list@ ends with @suffix@,+shouldEndWith :: (Show a, Eq a) => [a] -> [a] -> Expectation+shouldEndWith = compareWith isSuffixOf "does not end with"++-- | -- @list \`shouldContain\` sublist@ sets the expectation that @sublist@ is contained, -- wholly and intact, anywhere in @list@. shouldContain :: (Show a, Eq a) => [a] -> [a] -> Expectation-list `shouldContain` sublist = assertBool errorMsg (sublist `isInfixOf` list)-  where-    errorMsg = show list ++ " doesn't contain " ++ show sublist+shouldContain = compareWith isInfixOf "does not contain"  -- | -- @xs \`shouldMatchList\` ys@ sets the expectation that @xs@ has the same@@ -82,6 +103,31 @@ -- returns @expected@. shouldReturn :: (Show a, Eq a) => IO a -> a -> Expectation action `shouldReturn` expected = action >>= (`shouldBe` expected)++-- |+-- @actual \`shouldNotBe\` notExpected@ sets the expectation that @actual@ is not+-- equal to @notExpected@+shouldNotBe :: (Show a, Eq a) => a -> a -> Expectation+actual `shouldNotBe` notExpected = assertBool ("not expected: " ++ show actual) (actual /= notExpected)++-- |+-- @v \`shouldNotSatisfy\` p@ sets the expectation that @p v@ is @False@.+shouldNotSatisfy :: (Show a) => a -> (a -> Bool) -> Expectation+v `shouldNotSatisfy` p = assertBool ("predicate succeded on: " ++ show v) ((not . p) v)++-- |+-- @list \`shouldNotContain\` sublist@ sets the expectation that @sublist@ is not+-- contained anywhere in @list@.+shouldNotContain :: (Show a, Eq a) => [a] -> [a] -> Expectation+list `shouldNotContain` sublist = assertBool errorMsg ((not . isInfixOf sublist) list)+  where+    errorMsg = show list ++ " does contain " ++ show sublist++-- |+-- @action \`shouldNotReturn\` notExpected@ sets the expectation that @action@+-- does not return @notExpected@.+shouldNotReturn :: (Show a, Eq a) => IO a -> a -> Expectation+action `shouldNotReturn` notExpected = action >>= (`shouldNotBe` notExpected)  -- | -- A @Selector@ is a predicate; it can simultaneously constrain the type and
src/Test/Hspec/Expectations/Contrib.hs view
@@ -1,54 +1,26 @@+{-# LANGUAGE CPP #-} -- | -- Experimental combinators, that may become part of the main distribution, if -- they turn out to be useful for a wider audience. module Test.Hspec.Expectations.Contrib (--- * Additional combinators for setting expectations-  shouldNotBe-, shouldNotSatisfy-, shouldNotReturn-, shouldNotContain- -- * Predicates -- | (useful in combination with `shouldSatisfy`)-, isLeft+  isLeft , isRight ) where -import Test.Hspec.Expectations-import Test.HUnit (assertBool)-import Data.List (isInfixOf) +#if MIN_VERSION_base(4,7,0)+import Data.Either+#else+ isLeft :: Either a b -> Bool+{-# DEPRECATED isLeft "use Data.Either.Compat.isLeft from package base-compat instead" #-} isLeft (Left  _) = True isLeft (Right _) = False  isRight :: Either a b -> Bool+{-# DEPRECATED isRight "use Data.Either.Compat.isRight from package base-compat instead" #-} isRight (Left  _) = False isRight (Right _) = True--infix 1 `shouldNotBe`, `shouldNotSatisfy`, `shouldNotContain`, `shouldNotReturn`---- |--- @actual \`shouldNotBe\` notExpected@ sets the expectation that @actual@ is not--- equal to @notExpected@-shouldNotBe :: (Show a, Eq a) => a -> a -> Expectation-actual `shouldNotBe` notExpected = assertBool ("not expected: " ++ show actual) (actual /= notExpected)---- |--- @v \`shouldNotSatisfy\` p@ sets the expectation that @p v@ is @False@.-shouldNotSatisfy :: (Show a) => a -> (a -> Bool) -> Expectation-v `shouldNotSatisfy` p = assertBool ("predicate succeded on: " ++ show v) ((not . p) v)---- |--- @list \`shouldNotContain\` sublist@ sets the expectation that @sublist@ is not--- contained anywhere in the second.-shouldNotContain :: (Show a, Eq a) => [a] -> [a] -> Expectation-list `shouldNotContain` sublist = assertBool errorMsg ((not . isInfixOf sublist) list)-  where-    errorMsg = show list ++ " does contain " ++ show sublist---- |--- @action \`shouldNotReturn\` notExpected@ sets the expectation that @action@--- does not return @notExpected@.-shouldNotReturn :: (Show a, Eq a) => IO a -> a -> Expectation-action `shouldNotReturn` notExpected = action >>= (`shouldNotBe` notExpected)+#endif
− test/Spec.hs
@@ -1,1 +0,0 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover #-}