hspec-meta 2.0.0 → 2.1.5
raw patch · 13 files changed
+107/−45 lines, 13 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Test.Hspec.Meta: before_ :: IO () -> SpecWith a -> SpecWith a
- Test.Hspec.Meta: afterAll_ :: IO () -> Spec -> Spec
+ Test.Hspec.Meta: afterAll_ :: IO () -> SpecWith a -> SpecWith a
- Test.Hspec.Meta: after_ :: IO () -> Spec -> Spec
+ Test.Hspec.Meta: after_ :: IO () -> SpecWith a -> SpecWith a
- Test.Hspec.Meta: around_ :: (IO () -> IO ()) -> Spec -> Spec
+ Test.Hspec.Meta: around_ :: (IO () -> IO ()) -> SpecWith a -> SpecWith a
- Test.Hspec.Meta: class Example e where type family Arg e
+ Test.Hspec.Meta: class Example e where type family Arg e type instance Arg e = ()
Files
- hspec-core/src/Test/Hspec/Config.hs +2/−1
- hspec-core/src/Test/Hspec/Core.hs +0/−18
- hspec-core/src/Test/Hspec/Core/Example.hs +13/−1
- hspec-core/src/Test/Hspec/Core/Formatters.hs +15/−13
- hspec-core/src/Test/Hspec/Core/Hooks.hs +11/−6
- hspec-core/src/Test/Hspec/Core/Runner.hs +2/−1
- hspec-core/src/Test/Hspec/Options.hs +8/−1
- hspec-discover/src/Run.hs +10/−1
- hspec-meta.cabal +3/−2
- src/Test/Hspec.hs +1/−0
- src/Test/Hspec/Core.hs +18/−0
- src/Test/Hspec/Discover.hs +0/−1
- src/Test/Hspec/HUnit.hs +24/−0
hspec-core/src/Test/Hspec/Config.hs view
@@ -16,6 +16,7 @@ import Test.Hspec.Options import Test.Hspec.FailureReport import Test.Hspec.Core.QuickCheckUtil (mkGen)+import Test.Hspec.Core.Example (Params(..), defaultParams) -- | Add a filter predicate to config. If there is already a filter predicate, -- then combine them with `||`.@@ -50,7 +51,7 @@ maybe id setSeed (configQuickCheckSeed c) . maybe id setMaxDiscardRatio (configQuickCheckMaxDiscardRatio c) . maybe id setMaxSize (configQuickCheckMaxSize c)- . maybe id setMaxSuccess (configQuickCheckMaxSuccess c)) QC.stdArgs+ . maybe id setMaxSuccess (configQuickCheckMaxSuccess c)) (paramsQuickCheckArgs defaultParams) setMaxSuccess :: Int -> QC.Args -> QC.Args setMaxSuccess n args = args {QC.maxSuccess = n}
− hspec-core/src/Test/Hspec/Core.hs
@@ -1,18 +0,0 @@--- | Stability: unstable-module Test.Hspec.Core (- module Test.Hspec.Core.Spec--- * Deprecated functions-, describe-, it-) where--import Test.Hspec.Core.Spec hiding (describe, it)---{-# DEPRECATED describe "use `specGroup` instead" #-}-describe :: String -> [SpecTree a] -> SpecTree a-describe = specGroup--{-# DEPRECATED it "use `specItem` instead" #-}-it :: Example a => String -> a -> SpecTree (Arg a)-it = specItem
hspec-core/src/Test/Hspec/Core/Example.hs view
@@ -2,6 +2,7 @@ module Test.Hspec.Core.Example ( Example (..) , Params (..)+, defaultParams , ActionWith , Progress , ProgressCallback@@ -18,7 +19,6 @@ import qualified Test.QuickCheck.State as QC import qualified Test.QuickCheck.Property as QCP-import qualified Test.QuickCheck.IO () import Test.Hspec.Core.QuickCheckUtil import Test.Hspec.Core.Util@@ -27,6 +27,9 @@ -- | A type class for examples class Example e where type Arg e+#if __GLASGOW_HASKELL__ >= 704+ type Arg e = ()+#endif evaluateExample :: e -> Params -> (ActionWith (Arg e) -> IO ()) -> ProgressCallback -> IO Result data Params = Params {@@ -34,6 +37,12 @@ , paramsSmallCheckDepth :: Int } deriving (Show) +defaultParams :: Params+defaultParams = Params {+ paramsQuickCheckArgs = QC.stdArgs+, paramsSmallCheckDepth = 5+}+ type Progress = (Int, Int) type ProgressCallback = Progress -> IO () @@ -79,6 +88,9 @@ QC.Failure {QC.output = m} -> fromMaybe (Fail $ sanitizeFailureMessage r) (parsePending m) QC.GaveUp {QC.numTests = n} -> Fail ("Gave up after " ++ pluralize n "test" ) QC.NoExpectedFailure {} -> Fail ("No expected failure")+#if MIN_VERSION_QuickCheck(2,8,0)+ QC.InsufficientCoverage {} -> Fail ("Insufficient coverage")+#endif where qcProgressCallback = QCP.PostTest QCP.NotCounterexample $ \st _ -> progressCallback (QC.numSuccessTests st, QC.maxSuccessTests st)
hspec-core/src/Test/Hspec/Core/Formatters.hs view
@@ -158,15 +158,18 @@ failures <- getFailMessages - forM_ (zip [1..] failures) $ \x -> do- formatFailure x+ unless (null failures) $ do+ writeLine "Failures:" writeLine "" - when (hasBestEffortLocations failures) $ do- withInfoColor $ writeLine "Source locations marked with \"best-effort\" are calculated heuristically and may be incorrect."- writeLine ""+ forM_ (zip [1..] failures) $ \x -> do+ formatFailure x+ writeLine "" - unless (null failures) $ do+ when (hasBestEffortLocations failures) $ do+ withInfoColor $ writeLine "Source locations marked with \"best-effort\" are calculated heuristically and may be incorrect."+ writeLine ""+ write "Randomized with seed " >> usedSeed >>= writeLine . show writeLine "" where@@ -178,17 +181,16 @@ formatFailure :: (Int, FailureRecord) -> FormatM () formatFailure (n, FailureRecord mLoc path reason) = do- write (show n ++ ") ")- writeLine (formatRequirement path)- withFailColor $ do- unless (null err) $ do- writeLine err forM_ mLoc $ \loc -> do- writeLine "" withInfoColor $ writeLine (formatLoc loc)+ write (" " ++ show n ++ ") ")+ writeLine (formatRequirement path)+ withFailColor $ do+ forM_ (lines err) $ \x -> do+ writeLine (" " ++ x) where err = either (("uncaught exception: " ++) . formatException) id reason- formatLoc (Location file line _column accuracy) = "# " ++ file ++ ":" ++ show line ++ bestEffortMarking+ formatLoc (Location file line _column accuracy) = " " ++ file ++ ":" ++ show line ++ ":" ++ bestEffortMarking where bestEffortMarking = case accuracy of ExactLocation -> ""
hspec-core/src/Test/Hspec/Core/Hooks.hs view
@@ -1,6 +1,7 @@ -- | Stability: provisional module Test.Hspec.Core.Hooks ( before+, before_ , beforeWith , beforeAll , after@@ -22,6 +23,10 @@ before action = around (action >>=) -- | Run a custom action before every spec item.+before_ :: IO () -> SpecWith a -> SpecWith a+before_ action = around_ (action >>)++-- | Run a custom action before every spec item. beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith b beforeWith action = aroundWith $ \e x -> action x >>= e @@ -44,8 +49,8 @@ after action = aroundWith $ \e x -> e x `finally` action x -- | Run a custom action after every spec item.-after_ :: IO () -> Spec -> Spec-after_ action = after $ \() -> action+after_ :: IO () -> SpecWith a -> SpecWith a+after_ action = after $ \_ -> action -- | Run a custom action before and/or after every spec item. around :: (ActionWith a -> IO ()) -> SpecWith a -> Spec@@ -56,12 +61,12 @@ afterAll action spec = runIO (runSpecM spec) >>= fromSpecList . return . NodeWithCleanup action -- | Run a custom action after the last spec item.-afterAll_ :: IO () -> Spec -> Spec-afterAll_ action = afterAll (\() -> action)+afterAll_ :: IO () -> SpecWith a -> SpecWith a+afterAll_ action = afterAll (\_ -> action) -- | Run a custom action before and/or after every spec item.-around_ :: (IO () -> IO ()) -> Spec -> Spec-around_ action = around $ action . ($ ())+around_ :: (IO () -> IO ()) -> SpecWith a -> SpecWith a+around_ action = aroundWith $ \e a -> action (e a) -- | Run a custom action before and/or after every spec item. aroundWith :: (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith b
hspec-core/src/Test/Hspec/Core/Runner.hs view
@@ -47,7 +47,8 @@ filterSpecs c = go [] where p :: Path -> Bool- p = fromMaybe (const True) (configFilterPredicate c)+ p path = (fromMaybe (const True) (configFilterPredicate c) path) &&+ not (fromMaybe (const False) (configSkipPredicate c) path) go :: [String] -> [SpecTree a] -> [SpecTree a] go groups = mapMaybe (goSpec groups)
hspec-core/src/Test/Hspec/Options.hs view
@@ -15,6 +15,7 @@ import Test.Hspec.Core.Formatters import Test.Hspec.Compat import Test.Hspec.Core.Util+import Test.Hspec.Core.Example (Params(..), defaultParams) data Config = Config { configDryRun :: Bool@@ -26,6 +27,7 @@ -- that satisfy the predicate are run. , configRerun :: Bool , configFilterPredicate :: Maybe (Path -> Bool)+, configSkipPredicate :: Maybe (Path -> Bool) , configQuickCheckSeed :: Maybe Integer , configQuickCheckMaxSuccess :: Maybe Int , configQuickCheckMaxDiscardRatio :: Maybe Int@@ -44,11 +46,12 @@ , configFastFail = False , configRerun = False , configFilterPredicate = Nothing+, configSkipPredicate = Nothing , configQuickCheckSeed = Nothing , configQuickCheckMaxSuccess = Nothing , configQuickCheckMaxDiscardRatio = Nothing , configQuickCheckMaxSize = Nothing-, configSmallCheckDepth = 5+, configSmallCheckDepth = paramsSmallCheckDepth defaultParams , configColorMode = ColorAuto , configFormatter = Nothing , configHtmlOutput = False@@ -63,6 +66,9 @@ addMatch :: String -> Config -> Config addMatch s c = c {configFilterPredicate = Just (filterPredicate s) `filterOr` configFilterPredicate c} +addSkip :: String -> Config -> Config+addSkip s c = c {configSkipPredicate = Just (filterPredicate s) `filterOr` configSkipPredicate c}+ setDepth :: Int -> Config -> Config setDepth n c = c {configSmallCheckDepth = n} @@ -117,6 +123,7 @@ options = [ Option [] ["help"] (NoArg (const $ Left Help)) (h "display this help and exit") , mkOption "m" "match" (Arg "PATTERN" return addMatch) (h "only run examples that match given PATTERN")+ , mkOption [] "skip" (Arg "PATTERN" return addSkip) (h "skip examples that match given PATTERN") , Option [] ["color"] (NoArg setColor) (h "colorize the output") , Option [] ["no-color"] (NoArg setNoColor) (h "do not colorize the output") , mkOption "f" "format" (Arg "FORMATTER" readFormatter setFormatter) formatHelp
hspec-discover/src/Run.hs view
@@ -121,12 +121,21 @@ fileToSpec :: FilePath -> FilePath -> Maybe Spec fileToSpec dir file = case reverse $ splitDirectories file of x:xs -> case stripSuffix "Spec.hs" x <|> stripSuffix "Spec.lhs" x of- Just name | (not . null) name -> Just . Spec (dir </> file) $ (intercalate "." . reverse) (name : xs)+ Just name | isValidModuleName name && all isValidModuleName xs ->+ Just . Spec (dir </> file) $ (intercalate "." . reverse) (name : xs) _ -> Nothing _ -> Nothing where stripSuffix :: Eq a => [a] -> [a] -> Maybe [a] stripSuffix suffix str = reverse <$> stripPrefix (reverse suffix) (reverse str)++-- See `Cabal.Distribution.ModuleName` (http://git.io/bj34)+isValidModuleName :: String -> Bool+isValidModuleName [] = False+isValidModuleName (c:cs) = isUpper c && all isValidModuleChar cs++isValidModuleChar :: Char -> Bool+isValidModuleChar c = isAlphaNum c || c == '_' || c == '\'' getFilesRecursive :: FilePath -> IO [FilePath] getFilesRecursive baseDir = sort <$> go []
hspec-meta.cabal view
@@ -1,5 +1,5 @@ name: hspec-meta-version: 2.0.0+version: 2.1.5 license: MIT license-file: LICENSE copyright: (c) 2011-2014 Simon Hengel,@@ -50,8 +50,9 @@ Test.Hspec.Formatters Test.Hspec.QuickCheck Test.Hspec.Discover- Test.Hspec.Core+ Test.Hspec.HUnit+ Test.Hspec.Core.Spec Test.Hspec.Core.Hooks Test.Hspec.Core.Runner
src/Test/Hspec.hs view
@@ -30,6 +30,7 @@ -- * Hooks , ActionWith , before+, before_ , beforeWith , beforeAll , after
+ src/Test/Hspec/Core.hs view
@@ -0,0 +1,18 @@+-- | Stability: unstable+module Test.Hspec.Core {-# DEPRECATED "use \"Test.Hspec.Core.Spec\" instead" #-} (+ module Test.Hspec.Core.Spec+-- * Deprecated functions+, describe+, it+) where++import Test.Hspec.Core.Spec hiding (describe, it)+++{-# DEPRECATED describe "use `specGroup` instead" #-}+describe :: String -> [SpecTree a] -> SpecTree a+describe = specGroup++{-# DEPRECATED it "use `specItem` instead" #-}+it :: Example a => String -> a -> SpecTree (Arg a)+it = specItem
src/Test/Hspec/Discover.hs view
@@ -8,7 +8,6 @@ , hspecWithFormatter , postProcessSpec , describe-, module Prelude ) where import Control.Applicative
+ src/Test/Hspec/HUnit.hs view
@@ -0,0 +1,24 @@+module Test.Hspec.HUnit {-# DEPRECATED "use \"Test.Hspec.Contrib.HUnit\" from package @hspec-contrib@ instead" #-}+(+-- * Interoperability with HUnit+ fromHUnitTest+) where++import Test.Hspec.Core.Spec+import Test.HUnit (Test (..))++-- |+-- Convert a HUnit test suite to a spec. This can be used to run existing+-- HUnit tests with Hspec.+fromHUnitTest :: Test -> Spec+fromHUnitTest t = case t of+ TestList xs -> mapM_ go xs+ x -> go x+ where+ go :: Test -> Spec+ go t_ = case t_ of+ TestLabel s (TestCase e) -> it s e+ TestLabel s (TestList xs) -> describe s (mapM_ go xs)+ TestLabel s x -> describe s (go x)+ TestList xs -> describe "<unlabeled>" (mapM_ go xs)+ TestCase e -> it "<unlabeled>" e