packages feed

hspec 1.12.1 → 1.12.2

raw patch · 4 files changed

+58/−7 lines, 4 filesdep ~hspec-meta

Dependency ranges changed: hspec-meta

Files

hspec.cabal view
@@ -1,5 +1,5 @@ name:             hspec-version:          1.12.1+version:          1.12.2 license:          MIT license-file:     LICENSE copyright:        (c) 2011-2014 Simon Hengel,@@ -139,7 +139,7 @@     , hspec-expectations     , async -    , hspec-meta == 1.12.1+    , hspec-meta >= 1.12     , process     , directory     , stringbuilder
src/Test/Hspec/Runner/Tree.hs view
@@ -1,16 +1,35 @@-{-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable #-}+{-# LANGUAGE CPP, DeriveFunctor #-} module Test.Hspec.Runner.Tree where  import           Control.Applicative-import           Data.Foldable (Foldable)-import           Data.Traversable (Traversable)+import           Data.Foldable+import           Data.Traversable import           Test.Hspec.Core.Type+import           Data.Monoid  data Tree a   = Node !String [Tree a]   | NodeWithCleanup (IO ()) [Tree a]   | Leaf a-  deriving (Functor, Foldable, Traversable)+  deriving Functor++instance Foldable Tree where -- Note: GHC 7.0.1 fails to derive this instance+  foldMap = go+    where+      go :: Monoid m => (a -> m) -> Tree a -> m+      go f t = case t of+        Node _ xs -> foldMap (foldMap f) xs+        NodeWithCleanup _ xs -> foldMap (foldMap f) xs+        Leaf x -> f x++instance Traversable Tree where -- Note: GHC 7.0.1 fails to derive this instance+  sequenceA = go+    where+      go :: Applicative f => Tree (f a) -> f (Tree a)+      go t = case t of+        Node label xs -> Node label <$> sequenceA (map go xs)+        NodeWithCleanup action xs -> NodeWithCleanup action <$> sequenceA (map go xs)+        Leaf a -> Leaf <$> a  toTree :: Spec -> IO [Tree Item] toTree spec = map f <$> runSpecM spec
src/Test/Hspec/Util.hs view
@@ -11,6 +11,7 @@  import           Data.List import           Data.Char (isSpace)+import           GHC.IO.Exception import qualified Control.Exception as E import           Control.Concurrent.Async @@ -28,8 +29,34 @@ -- @ -- "ArithException (divide by zero)" -- @+--+-- For `IOException`s the `IOErrorType` is included. formatException :: E.SomeException -> String-formatException (E.SomeException e) = showType e ++ " (" ++ show e ++ ")"+formatException err@(E.SomeException e) = case E.fromException err of+  Just ioe -> showType ioe ++ " of type " ++ showIOErrorType ioe ++ " (" ++ show ioe ++ ")"+  Nothing  -> showType e ++ " (" ++ show e ++ ")"+  where+    showIOErrorType :: IOException -> String+    showIOErrorType ioe = case ioe_type ioe of+      AlreadyExists -> "AlreadyExists"+      NoSuchThing -> "NoSuchThing"+      ResourceBusy -> "ResourceBusy"+      ResourceExhausted -> "ResourceExhausted"+      EOF -> "EOF"+      IllegalOperation -> "IllegalOperation"+      PermissionDenied -> "PermissionDenied"+      UserError -> "UserError"+      UnsatisfiedConstraints -> "UnsatisfiedConstraints"+      SystemError -> "SystemError"+      ProtocolError -> "ProtocolError"+      OtherError -> "OtherError"+      InvalidArgument -> "InvalidArgument"+      InappropriateType -> "InappropriateType"+      HardwareFault -> "HardwareFault"+      UnsupportedOperation -> "UnsupportedOperation"+      TimeExpired -> "TimeExpired"+      ResourceVanished -> "ResourceVanished"+      Interrupted -> "Interrupted"  safeTry :: IO a -> IO (Either E.SomeException a) safeTry action = withAsync (action >>= E.evaluate) waitCatch
test/Test/Hspec/UtilSpec.hs view
@@ -28,6 +28,11 @@     it "converts exception to string" $ do       formatException (E.toException E.DivideByZero) `shouldBe` "ArithException (divide by zero)" +    context "when used with an IOException" $ do+      it "includes the IOErrorType" $ do+        Left e <- E.try (readFile "foo")+        formatException e `shouldBe` "IOException of type NoSuchThing (foo: openFile: does not exist (No such file or directory))"+   describe "lineBreaksAt" $ do     it "inserts line breaks at word boundaries" $ do       lineBreaksAt 20 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod"