packages feed

test-shouldbe 0.2.0 → 0.2.1

raw patch · 3 files changed

+50/−30 lines, 3 filesdep +hspecdep +hspec-discoverdep +silentlydep ~base

Dependencies added: hspec, hspec-discover, silently

Dependency ranges changed: base

Files

src/Test/HUnit/ShouldBe.hs view
@@ -2,12 +2,13 @@ -- Introductory documentation: <https://github.com/sol/test-shouldbe#readme> module Test.HUnit.ShouldBe ( --- * Making assertions-  shouldBe+-- * Setting expectations+  Expectation+, shouldBe , shouldSatisfy , shouldReturn --- * Checking for exceptions+-- * Expecting exceptions , shouldThrow  -- ** Selecting exceptions@@ -37,24 +38,26 @@ import           Test.HUnit import           Control.Exception import           Data.Typeable-import           Control.Arrow ((&&&)) +type Expectation = Assertion+ infix 1 `shouldBe`, `shouldSatisfy`, `shouldReturn`, `shouldThrow`  -- |--- @actual \`shouldBe\` expected@ asserts that @actual@ is equal to @expected@--- (this is just an alias for `@?=`).-shouldBe :: (Show a, Eq a) => a -> a -> Assertion+-- @actual \`shouldBe\` expected@ sets the expectation that @actual@ is equal+-- to @expected@ (this is just an alias for `@?=`).+shouldBe :: (Show a, Eq a) => a -> a -> Expectation actual `shouldBe` expected = actual @?= expected  -- |--- @v \`shouldSatisfy\` p@ asserts that @p v@ is @True@.-shouldSatisfy :: (Show a) => a -> (a -> Bool) -> Assertion+-- @v \`shouldSatisfy\` p@ sets the expectation that @p v@ is @True@.+shouldSatisfy :: (Show a) => a -> (a -> Bool) -> Expectation v `shouldSatisfy` p = assertBool (show v ++ " did not satisfy predicate!") (p v)  -- |--- @action \`shouldReturn\` expected@ asserts that @action@ returns @expected@.-shouldReturn :: (Show a, Eq a) => IO a -> a -> Assertion+-- @action \`shouldReturn\` expected@ sets the expectation that @action@+-- returns @expected@.+shouldReturn :: (Show a, Eq a) => IO a -> a -> Expectation action `shouldReturn` expected = action >>= (`shouldBe` expected)  -- |@@ -63,25 +66,25 @@ type Selector a = (a -> Bool)  -- |--- @action \`shouldThrow\` selector@ asserts that @action@ throws an exception.--- The precise nature of that exception is described with a 'Selector'.-shouldThrow :: Exception e => IO a -> Selector e -> Assertion+-- @action \`shouldThrow\` selector@ sets the expectation that @action@ throws+-- an exception.  The precise nature of the expected exception is described+-- with a 'Selector'.+shouldThrow :: Exception e => IO a -> Selector e -> Expectation action `shouldThrow` p = do-  m <- (action >> return Nothing) `catch` (return . Just . (p &&& id))-  case m of-    Nothing ->-      assertFailure msgNothing-    Just (r, e) ->-      assertBool (msgFailure e) r+  r <- try action+  case r of+    Right _ ->+      assertFailure $+        "did not get expected exception: " ++ exceptionType+    Left e ->+      (`assertBool` p e) $+        "predicate failed on expected exception: " ++ exceptionType ++ " (" ++ show e ++ ")"   where-    msgNothing = "did not get expected exception: "-            ++ (show . typeOf . instanceOf $ p)--    msgFailure e = "predicate failed on expected exception: "-            ++ (show . typeOf $ e) ++ " (" ++ show e ++ ")"--    instanceOf :: Selector a -> a-    instanceOf _ = error "Test.HUnit.ShouldBe.shouldThrow: brocken Typeable instance"+    -- a string repsentation of the expected exception's type+    exceptionType = (show . typeOf . instanceOf) p+      where+        instanceOf :: Selector a -> a+        instanceOf _ = error "Test.HUnit.ShouldBe.shouldThrow: brocken Typeable instance"  anyException :: Selector SomeException anyException = const True
test-shouldbe.cabal view
@@ -1,5 +1,5 @@ name:             test-shouldbe-version:          0.2.0+version:          0.2.1 synopsis:         Catchy combinators for HUnit description:      Catchy combinators for HUnit: <https://github.com/sol/test-shouldbe#readme> license:          MIT@@ -9,7 +9,8 @@ maintainer:       Simon Hengel <sol@typeful.net> build-type:       Simple category:         Testing-cabal-version:    >= 1.6+cabal-version:    >= 1.8+homepage:         https://github.com/sol/test-shouldbe#readme  source-repository head   type: git@@ -26,3 +27,18 @@   exposed-modules:       Test.HUnit.ShouldBe     , Test.HUnit.ShouldBe.Contrib++test-suite spec+  main-is:+      Spec.hs+  type:+      exitcode-stdio-1.0+  ghc-options:+      -Wall -Werror+  hs-source-dirs:+      src, test+  build-depends:+      base        >= 4.0  && < 4.6+    , silently+    , hspec+    , hspec-discover
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}