hspec-meta 1.9.5 → 1.10.0
raw patch · 11 files changed
+50/−164 lines, 11 filesdep +asyncPVP ok
version bump matches the API change (PVP)
Dependencies added: async
API changes (from Hackage documentation)
Files
- hspec-meta.cabal +2/−2
- src/Test/Hspec/Config.hs +15/−1
- src/Test/Hspec/Core.hs +1/−34
- src/Test/Hspec/Core/QuickCheckUtil.hs +0/−10
- src/Test/Hspec/Core/Type.hs +15/−19
- src/Test/Hspec/HUnit.hs +1/−17
- src/Test/Hspec/Monadic.hs +0/−53
- src/Test/Hspec/QuickCheck.hs +1/−7
- src/Test/Hspec/Runner.hs +2/−2
- src/Test/Hspec/Runner/Eval.hs +10/−9
- src/Test/Hspec/Util.hs +3/−10
hspec-meta.cabal view
@@ -1,5 +1,5 @@ name: hspec-meta-version: 1.9.5+version: 1.10.0 license: MIT license-file: LICENSE copyright: (c) 2011-2014 Simon Hengel,@@ -46,13 +46,13 @@ , HUnit >= 1.2.5 , QuickCheck >= 2.5.1 , quickcheck-io+ , async >= 2 , hspec-expectations exposed-modules: Test.Hspec.Meta other-modules: Test.Hspec Test.Hspec.Core- Test.Hspec.Monadic Test.Hspec.Runner Test.Hspec.Formatters Test.Hspec.HUnit
src/Test/Hspec/Config.hs view
@@ -40,7 +40,21 @@ } defaultConfig :: Config-defaultConfig = Config False False False Nothing Nothing Nothing Nothing Nothing 5 ColorAuto specdoc False (Left stdout)+defaultConfig = Config {+ configDryRun = False+, configPrintCpuTime = False+, configFastFail = False+, configFilterPredicate = Nothing+, configQuickCheckSeed = Nothing+, configQuickCheckMaxSuccess = Nothing+, configQuickCheckMaxDiscardRatio = Nothing+, configQuickCheckMaxSize = Nothing+, configSmallCheckDepth = 5+, configColorMode = ColorAuto+, configFormatter = specdoc+, configHtmlOutput = False+, configHandle = Left stdout+} -- | Add a filter predicate to config. If there is already a filter predicate, -- then combine them with `||`.
src/Test/Hspec/Core.hs view
@@ -9,6 +9,7 @@ Example (..) , Params (..) , Progress+, ProgressCallback , Result (..) -- * A writer monad for constructing specs@@ -23,43 +24,9 @@ , modifyParams , describe , it---- * Deprecated types and functions-, Specs-, hspecB-, hspecX-, hHspec-, hspec ) where -import Control.Applicative-import System.IO (Handle)- import Test.Hspec.Core.Type-import qualified Test.Hspec.Runner as Runner-import Test.Hspec.Runner (Summary(..), Config(..), defaultConfig) -hspecWith :: Config -> [SpecTree] -> IO Summary-hspecWith c = Runner.hspecWith c . fromSpecList- modifyParams :: (Params -> Params) -> Spec -> Spec modifyParams f = mapSpecItem $ \item -> item {itemExample = \p -> (itemExample item) (f p)}--{-# DEPRECATED hspecX "use `Test.Hspec.Runner.hspec` instead" #-} -- since 1.2.0-hspecX :: [SpecTree] -> IO ()-hspecX = hspec--{-# DEPRECATED hspec "use `Test.Hspec.Runner.hspec` instead" #-} -- since 1.4.0-hspec :: [SpecTree] -> IO ()-hspec = Runner.hspec . fromSpecList--{-# DEPRECATED hspecB "use `Test.Hspec.Runner.hspecWith` instead" #-} -- since 1.4.0-hspecB :: [SpecTree] -> IO Bool-hspecB spec = (== 0) . summaryFailures <$> hspecWith defaultConfig spec--{-# DEPRECATED hHspec "use `Test.Hspec.Runner.hspecWith` instead" #-} -- since 1.4.0-hHspec :: Handle -> [SpecTree] -> IO Summary-hHspec h = hspecWith defaultConfig {configHandle = Left h}--{-# DEPRECATED Specs "use `[SpecTree]` instead" #-} -- since 1.4.0-type Specs = [SpecTree]
src/Test/Hspec/Core/QuickCheckUtil.hs view
@@ -12,7 +12,6 @@ #if MIN_VERSION_QuickCheck(2,7,0)-import Control.Exception import Test.QuickCheck.Random #endif @@ -32,15 +31,6 @@ ref <- newIORef (return QCP.succeeded) action (reduceRose r >>= writeIORef ref) readIORef ref--isUserInterrupt :: QC.Result -> Bool-isUserInterrupt r = case r of-#if MIN_VERSION_QuickCheck(2,7,0)- QC.Failure {theException = me} -> (me >>= fromException) == Just UserInterrupt-#else- QC.Failure {QC.reason = "Exception: 'user interrupt'"} -> True-#endif- _ -> False formatNumbers :: Result -> String formatNumbers r = "(after " ++ pluralize (numTests r) "test" ++ shrinks ++ ")"
src/Test/Hspec/Core/Type.hs view
@@ -11,6 +11,7 @@ , Result (..) , Params (..) , Progress+, ProgressCallback , describe , it@@ -22,7 +23,6 @@ import qualified Control.Exception as E import Control.Applicative-import Control.Monad (when) import Control.Monad.Trans.Writer (Writer, execWriter, tell) import Data.Typeable (Typeable) import Data.List (isPrefixOf)@@ -67,22 +67,21 @@ instance E.Exception Result type Progress = (Int, Int)+type ProgressCallback = Progress -> IO () data Params = Params { paramsQuickCheckArgs :: QC.Args , paramsSmallCheckDepth :: Int-, paramsReportProgress :: Progress -> IO ()-}+} deriving (Show) -- | Internal representation of a spec. data SpecTree = SpecGroup String [SpecTree]- | SpecItem Item+ | SpecItem String Item data Item = Item { itemIsParallelizable :: Bool-, itemRequirement :: String-, itemExample :: Params -> (IO () -> IO ()) -> IO Result+, itemExample :: Params -> (IO () -> IO ()) -> ProgressCallback -> IO Result } mapSpecItem :: (Item -> Item) -> Spec -> Spec@@ -90,7 +89,7 @@ where go :: SpecTree -> SpecTree go spec = case spec of- SpecItem item -> SpecItem (f item)+ SpecItem r item -> SpecItem r (f item) SpecGroup d es -> SpecGroup d (map go es) -- | The @describe@ function combines a list of specs into a larger spec.@@ -103,7 +102,7 @@ -- | Create a spec item. it :: Example a => String -> a -> SpecTree-it s e = SpecItem $ Item False msg (evaluateExample e)+it s e = SpecItem msg $ Item False (evaluateExample e) where msg | null s = "(unspecified behavior)"@@ -111,26 +110,23 @@ -- | A type class for examples. class Example a where- evaluateExample :: a -> Params -> (IO () -> IO ()) -> IO Result+ evaluateExample :: a -> Params -> (IO () -> IO ()) -> ProgressCallback -> IO Result instance Example Bool where- evaluateExample b _ _ = if b then return Success else return (Fail "")+ evaluateExample b _ _ _ = if b then return Success else return (Fail "") instance Example Expectation where- evaluateExample e _ action = (action e >> return Success) `E.catches` [+ evaluateExample e _ action _ = (action e >> return Success) `E.catches` [ E.Handler (\(HUnitFailure err) -> return (Fail err)) , E.Handler (return :: Result -> IO Result) ] instance Example Result where- evaluateExample r _ _ = return r+ evaluateExample r _ _ _ = return r instance Example QC.Property where- evaluateExample p c action = do- r <- QC.quickCheckWithResult (paramsQuickCheckArgs c) {QC.chatty = False} (QCP.callback progressCallback $ aroundProperty action p)- when (isUserInterrupt r) $ do- E.throwIO E.UserInterrupt-+ evaluateExample p c action progressCallback = do+ r <- QC.quickCheckWithResult (paramsQuickCheckArgs c) {QC.chatty = False} (QCP.callback qcProgressCallback $ aroundProperty action p) return $ case r of QC.Success {} -> Success@@ -138,8 +134,8 @@ QC.GaveUp {QC.numTests = n} -> Fail ("Gave up after " ++ pluralize n "test" ) QC.NoExpectedFailure {} -> Fail ("No expected failure") where- progressCallback = QCP.PostTest QCP.NotCounterexample $- \st _ -> paramsReportProgress c (QC.numSuccessTests st, QC.maxSuccessTests st)+ qcProgressCallback = QCP.PostTest QCP.NotCounterexample $+ \st _ -> progressCallback (QC.numSuccessTests st, QC.maxSuccessTests st) sanitizeFailureMessage :: QC.Result -> String sanitizeFailureMessage r = let m = QC.output r in strip $
src/Test/Hspec/HUnit.hs view
@@ -1,26 +1,10 @@-{-# OPTIONS -fno-warn-orphans #-} module Test.Hspec.HUnit ( -- * Interoperability with HUnit fromHUnitTest ) where -import Data.List (intercalate)-import qualified Test.HUnit as HU-import Test.HUnit (Test (..))- import Test.Hspec.Core.Type---- | This instance is deprecated, use `Test.Hspec.HUnit.fromHUnitTest` instead!-instance Example Test where- evaluateExample test _ _ = do- (counts, fails) <- HU.runTestText HU.putTextToShowS test- let r = if HU.errors counts + HU.failures counts == 0- then Success- else Fail (details $ fails "")- return r- where- details :: String -> String- details = intercalate "\n" . tail . init . lines+import Test.HUnit (Test (..)) -- | -- Convert a HUnit test suite to a spec. This can be used to run existing
− src/Test/Hspec/Monadic.hs
@@ -1,53 +0,0 @@-{-# OPTIONS_HADDOCK not-home #-}-module Test.Hspec.Monadic {-# DEPRECATED "use \"Test.Hspec\", \"Test.Hspec.Runner\" or \"Test.Hspec.Core\" instead" #-} (--- * Types- Spec-, Example---- * Defining a spec-, describe-, context-, it-, pending---- * Running a spec-, hspec-, Summary (..)---- * Interface to the non-monadic API-, runSpecM-, fromSpecList---- * Deprecated types and functions-, Specs-, descriptions-, hspecB-, hspecX-, hHspec-) where--import System.IO-import Control.Applicative--import Test.Hspec.Core (runSpecM, fromSpecList)-import Test.Hspec.Runner-import Test.Hspec--{-# DEPRECATED Specs "use `Spec` instead" #-} -- since 1.2.0-type Specs = Spec--{-# DEPRECATED descriptions "use `sequence_` instead" #-} -- since 1.0.0-descriptions :: [Spec] -> Spec-descriptions = sequence_--{-# DEPRECATED hspecX "use `hspec` instead" #-} -- since 1.2.0-hspecX :: Spec -> IO ()-hspecX = hspec--{-# DEPRECATED hspecB "use `hspecWith` instead" #-} -- since 1.4.0-hspecB :: Spec -> IO Bool-hspecB spec = (== 0) . summaryFailures <$> hspecWith defaultConfig spec--{-# DEPRECATED hHspec "use hspecWith instead" #-} -- since 1.4.0-hHspec :: Handle -> Spec -> IO Summary-hHspec h = hspecWith defaultConfig {configHandle = Left h}
src/Test/Hspec/QuickCheck.hs view
@@ -5,13 +5,7 @@ modifyMaxSuccess , modifyMaxDiscardRatio , modifyMaxSize--- * Re-exports from QuickCheck--- |--- Previous versions of Hspec provided a distinct `property` combinator, but--- it's now possible to use QuickCheck's `property` instead. For backward--- compatibility we now re-export QuickCheck's `property`, but it is advisable--- to import it from "Test.QuickCheck" instead.-, property+ -- * Shortcuts , prop ) where
src/Test/Hspec/Runner.hs view
@@ -54,8 +54,8 @@ goSpec :: [String] -> SpecTree -> Maybe SpecTree goSpec groups spec = case spec of- SpecItem item -> guard (p (groups, itemRequirement item)) >> return spec- SpecGroup group specs -> case goSpecs (groups ++ [group]) specs of+ SpecItem requirement _ -> guard (p (groups, requirement)) >> return spec+ SpecGroup group specs -> case goSpecs (groups ++ [group]) specs of [] -> Nothing xs -> Just (SpecGroup group xs)
src/Test/Hspec/Runner/Eval.hs view
@@ -25,7 +25,7 @@ toTree :: SpecTree -> Tree Item toTree spec = case spec of SpecGroup label specs -> Node label (map toTree specs)- SpecItem item -> Leaf (itemRequirement item) item+ SpecItem r item -> Leaf r item type EvalTree = Tree (ProgressCallback -> FormatResult -> IO (FormatM ())) @@ -42,16 +42,18 @@ | useColor = every 0.05 $ exampleProgress formatter h | otherwise = return $ \_ _ -> return () - specs = map (fmap (parallelize . fmap (applyNoOpAround . applyQuickCheckArgs) . unwrapItem) . toTree) specs_+ specs = map (fmap (parallelize . fmap (applyNoOpAround . applyParams) . unwrapItem) . toTree) specs_ - unwrapItem :: Item -> (Bool, Params -> (IO () -> IO ()) -> IO Result)- unwrapItem (Item isParallelizable _ e) = (isParallelizable, e)+ unwrapItem :: Item -> (Bool, Params -> (IO () -> IO ()) -> ProgressCallback -> IO Result)+ unwrapItem (Item isParallelizable e) = (isParallelizable, e) - applyQuickCheckArgs :: (Params -> a) -> ProgressCallback -> a- applyQuickCheckArgs e progressCallback = e $ Params (configQuickCheckArgs c) (configSmallCheckDepth c) progressCallback+ applyParams :: (Params -> a) -> a+ applyParams = ($ params)+ where+ params = Params (configQuickCheckArgs c) (configSmallCheckDepth c) - applyNoOpAround :: (a -> (IO () -> IO ()) -> b) -> a -> b- applyNoOpAround = fmap ($ id)+ applyNoOpAround :: ((IO () -> IO ()) -> b) -> b+ applyNoOpAround = ($ id) -- | Execute given action at most every specified number of seconds. every :: POSIXTime -> (a -> b -> IO ()) -> IO (a -> b -> IO ())@@ -61,7 +63,6 @@ r <- timer when r (action a b) -type ProgressCallback = Progress -> IO () type FormatResult = Either E.SomeException Result -> FormatM () parallelize :: (Bool, ProgressCallback -> IO Result) -> ProgressCallback -> FormatResult -> IO (FormatM ())
src/Test/Hspec/Util.hs view
@@ -11,11 +11,12 @@ import Data.List import Data.Char (isSpace)-import Control.Applicative import qualified Control.Exception as E+import Control.Concurrent.Async import Test.Hspec.Compat (showType) + -- | Create a more readable display of a quantity of something. -- -- Examples:@@ -44,15 +45,7 @@ formatException (E.SomeException e) = showType e ++ " (" ++ show e ++ ")" safeTry :: IO a -> IO (Either E.SomeException a)-safeTry action = (Right <$> (action >>= E.evaluate)) `E.catches` [- -- Re-throw AsyncException, otherwise execution will not terminate on SIGINT- -- (ctrl-c). All AsyncExceptions are re-thrown (not just UserInterrupt)- -- because all of them indicate severe conditions and should not occur during- -- normal operation.- E.Handler $ \e -> E.throwIO (e :: E.AsyncException)-- , E.Handler $ \e -> (return . Left) (e :: E.SomeException)- ]+safeTry action = withAsync (action >>= E.evaluate) waitCatch -- | -- A tuple that represents the location of an example within a spec.