packages feed

hspec-core 2.11.4 → 2.11.5

raw patch · 12 files changed

+144/−55 lines, 12 filesdep ~hspec-metaPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: hspec-meta

API changes (from Hackage documentation)

+ Test.Hspec.Core.Format: [formatConfigFormatException] :: FormatConfig -> SomeException -> String
+ Test.Hspec.Core.Format: defaultFormatConfig :: FormatConfig
+ Test.Hspec.Core.Formatters.V2: FormatConfig :: Bool -> Bool -> Bool -> Bool -> Maybe Int -> Maybe (String -> String -> IO ()) -> Bool -> Maybe (String -> String -> (String, String)) -> (SomeException -> String) -> Bool -> Bool -> Bool -> Integer -> Int -> Bool -> FormatConfig
+ Test.Hspec.Core.Formatters.V2: [formatConfigDiffContext] :: FormatConfig -> Maybe Int
+ Test.Hspec.Core.Formatters.V2: [formatConfigExpectedTotalCount] :: FormatConfig -> Int
+ Test.Hspec.Core.Formatters.V2: [formatConfigExpertMode] :: FormatConfig -> Bool
+ Test.Hspec.Core.Formatters.V2: [formatConfigExternalDiff] :: FormatConfig -> Maybe (String -> String -> IO ())
+ Test.Hspec.Core.Formatters.V2: [formatConfigFormatException] :: FormatConfig -> SomeException -> String
+ Test.Hspec.Core.Formatters.V2: [formatConfigHtmlOutput] :: FormatConfig -> Bool
+ Test.Hspec.Core.Formatters.V2: [formatConfigOutputUnicode] :: FormatConfig -> Bool
+ Test.Hspec.Core.Formatters.V2: [formatConfigPrettyPrintFunction] :: FormatConfig -> Maybe (String -> String -> (String, String))
+ Test.Hspec.Core.Formatters.V2: [formatConfigPrettyPrint] :: FormatConfig -> Bool
+ Test.Hspec.Core.Formatters.V2: [formatConfigPrintCpuTime] :: FormatConfig -> Bool
+ Test.Hspec.Core.Formatters.V2: [formatConfigPrintTimes] :: FormatConfig -> Bool
+ Test.Hspec.Core.Formatters.V2: [formatConfigReportProgress] :: FormatConfig -> Bool
+ Test.Hspec.Core.Formatters.V2: [formatConfigUseColor] :: FormatConfig -> Bool
+ Test.Hspec.Core.Formatters.V2: [formatConfigUseDiff] :: FormatConfig -> Bool
+ Test.Hspec.Core.Formatters.V2: [formatConfigUsedSeed] :: FormatConfig -> Integer
+ Test.Hspec.Core.Formatters.V2: data FormatConfig
+ Test.Hspec.Core.Formatters.V2: getConfig :: FormatM FormatConfig
+ Test.Hspec.Core.Formatters.V2: getConfigValue :: (FormatConfig -> a) -> FormatM a
+ Test.Hspec.Core.Runner: [configFormatException] :: Config -> SomeException -> String
+ Test.Hspec.Core.Util: formatExceptionWith :: (SomeException -> String) -> SomeException -> String
- Test.Hspec.Core.Format: FormatConfig :: Bool -> Bool -> Bool -> Bool -> Maybe Int -> Maybe (String -> String -> IO ()) -> Bool -> Maybe (String -> String -> (String, String)) -> Bool -> Bool -> Bool -> Integer -> Int -> Bool -> FormatConfig
+ Test.Hspec.Core.Format: FormatConfig :: Bool -> Bool -> Bool -> Bool -> Maybe Int -> Maybe (String -> String -> IO ()) -> Bool -> Maybe (String -> String -> (String, String)) -> (SomeException -> String) -> Bool -> Bool -> Bool -> Integer -> Int -> Bool -> FormatConfig
- Test.Hspec.Core.Runner: Config :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe Int -> Bool -> Bool -> Bool -> Maybe FilePath -> Bool -> Bool -> Maybe (Path -> Bool) -> Maybe (Path -> Bool) -> Maybe Integer -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Int -> ColorMode -> UnicodeMode -> Bool -> Maybe Int -> Maybe (Maybe Int -> String -> String -> IO ()) -> Bool -> (Bool -> String -> String -> (String, String)) -> Bool -> Bool -> [(String, FormatConfig -> IO Format)] -> Maybe (FormatConfig -> IO Format) -> Maybe Formatter -> Bool -> Maybe Int -> Config
+ Test.Hspec.Core.Runner: Config :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe Int -> Bool -> Bool -> Bool -> Maybe FilePath -> Bool -> Bool -> Maybe (Path -> Bool) -> Maybe (Path -> Bool) -> Maybe Integer -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Int -> ColorMode -> UnicodeMode -> Bool -> Maybe Int -> Maybe (Maybe Int -> String -> String -> IO ()) -> Bool -> (Bool -> String -> String -> (String, String)) -> (SomeException -> String) -> Bool -> Bool -> [(String, FormatConfig -> IO Format)] -> Maybe (FormatConfig -> IO Format) -> Maybe Formatter -> Bool -> Maybe Int -> Config

Files

help.txt view
@@ -41,6 +41,9 @@            --diff-command=CMD      use an external diff command                                    example: --diff-command="git diff"            --[no-]pretty           try to pretty-print diff values+           --show-exceptions       use `show` when formatting exceptions+           --display-exceptions    use `displayException` when formatting+                                   exceptions            --[no-]times            report times for individual spec items            --print-cpu-time        include used CPU time in summary   -p[N]    --print-slow-items[=N]  print the N slowest spec items (default: 10)
hspec-core.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.35.2.+-- This file has been generated from package.yaml by hpack version 0.35.5. -- -- see: https://github.com/sol/hpack  name:             hspec-core-version:          2.11.4+version:          2.11.5 license:          MIT license-file:     LICENSE copyright:        (c) 2011-2023 Simon Hengel,@@ -19,6 +19,7 @@ category:         Testing stability:        experimental bug-reports:      https://github.com/hspec/hspec/issues+author:           Simon Hengel <sol@typeful.net> homepage:         https://hspec.github.io/ synopsis:         A Testing Framework for Haskell description:      This package exposes internal types and functions that can be used to extend Hspec's functionality.@@ -129,7 +130,7 @@     , filepath     , haskell-lexer     , hspec-expectations ==0.8.4.*-    , hspec-meta ==2.11.4+    , hspec-meta ==2.11.5     , process     , quickcheck-io >=0.2.0     , random
src/Test/Hspec/Core/Config/Definition.hs view
@@ -81,6 +81,7 @@  , configPrettyPrint :: Bool , configPrettyPrintFunction :: Bool -> String -> String -> (String, String)+, configFormatException :: SomeException -> String -- ^ @since 2.11.5 , configTimes :: Bool , configExpertMode :: Bool -- ^ @since 2.11.2 , configAvailableFormatters :: [(String, FormatConfig -> IO Format)] -- ^ @since 2.9.0@@ -122,6 +123,7 @@ , configExternalDiff = Nothing , configPrettyPrint = True , configPrettyPrintFunction = pretty2+, configFormatException = formatExceptionWith show , configTimes = False , configExpertMode = False , configAvailableFormatters = formatters@@ -178,6 +180,9 @@       ]   , option "diff-command" (argument "CMD" return setDiffCommand) "use an external diff command\nexample: --diff-command=\"git diff\""   , mkFlag "pretty" setPretty "try to pretty-print diff values"+  , mkOptionNoArg "show-exceptions" Nothing setShowException "use `show` when formatting exceptions"+  , mkOptionNoArg "display-exceptions" Nothing setDisplayException "use `displayException` when formatting exceptions"+   , mkFlag "times" setTimes "report times for individual spec items"   , mkOptionNoArg "print-cpu-time" Nothing setPrintCpuTime "include used CPU time in summary"   , printSlowItemsOption@@ -227,6 +232,12 @@      setPretty :: Bool -> Config -> Config     setPretty v config = config {configPrettyPrint = v}++    setShowException :: Config -> Config+    setShowException config = config {configFormatException = formatExceptionWith show}++    setDisplayException :: Config -> Config+    setDisplayException config = config {configFormatException = formatExceptionWith displayException}      setTimes :: Bool -> Config -> Config     setTimes v config = config {configTimes = v}
src/Test/Hspec/Core/Format.hs view
@@ -11,6 +11,7 @@ (   Format , FormatConfig(..)+, defaultFormatConfig , Event(..) , Progress , Path@@ -31,7 +32,7 @@ import           Control.Monad.IO.Class  import           Test.Hspec.Core.Example (Progress, Location(..), FailureReason(..))-import           Test.Hspec.Core.Util (Path)+import           Test.Hspec.Core.Util (Path, formatExceptionWith) import           Test.Hspec.Core.Clock (Seconds(..))  type Format = Event -> IO ()@@ -68,6 +69,7 @@ , formatConfigExternalDiff :: Maybe (String -> String -> IO ()) , formatConfigPrettyPrint :: Bool , formatConfigPrettyPrintFunction :: Maybe (String -> String -> (String, String))+, formatConfigFormatException :: SomeException -> String -- ^ @since 2.11.5 , formatConfigPrintTimes :: Bool , formatConfigHtmlOutput :: Bool , formatConfigPrintCpuTime :: Bool@@ -77,6 +79,26 @@ }  {-# DEPRECATED formatConfigPrettyPrint "Use `formatConfigPrettyPrintFunction` instead" #-}++-- ^ @since 2.11.5+defaultFormatConfig :: FormatConfig+defaultFormatConfig = FormatConfig {+  formatConfigUseColor = False+, formatConfigReportProgress = False+, formatConfigOutputUnicode = False+, formatConfigUseDiff = False+, formatConfigDiffContext = Nothing+, formatConfigExternalDiff = Nothing+, formatConfigPrettyPrint = False+, formatConfigPrettyPrintFunction = Nothing+, formatConfigFormatException = formatExceptionWith show+, formatConfigPrintTimes = False+, formatConfigHtmlOutput = False+, formatConfigPrintCpuTime = False+, formatConfigUsedSeed = 0+, formatConfigExpectedTotalCount = 0+, formatConfigExpertMode = False+}  data Signal = Ok | NotOk SomeException 
src/Test/Hspec/Core/Formatters/Internal.hs view
@@ -10,6 +10,10 @@ , FormatM , formatterToFormat +, getConfig+, getConfigValue+, FormatConfig(..)+ , getSuccessCount , getPendingCount , getFailCount@@ -118,13 +122,13 @@  -- | Return `True` if the user requested colorized diffs, `False` otherwise. useDiff :: FormatM Bool-useDiff = getConfig formatConfigUseDiff+useDiff = getConfigValue formatConfigUseDiff  -- | Do nothing on `--expert`, otherwise run the given action. -- -- @since 2.11.2 unlessExpert :: FormatM () -> FormatM ()-unlessExpert action = getConfig formatConfigExpertMode >>= \ case+unlessExpert action = getConfigValue formatConfigExpertMode >>= \ case   False -> action   True -> return () @@ -133,7 +137,7 @@ -- -- @since 2.10.6 diffContext :: FormatM (Maybe Int)-diffContext = getConfig formatConfigDiffContext+diffContext = getConfigValue formatConfigDiffContext  -- | An action for printing diffs. --@@ -145,11 +149,11 @@ -- -- @since 2.10.6 externalDiffAction :: FormatM (Maybe (String -> String -> IO ()))-externalDiffAction = getConfig formatConfigExternalDiff+externalDiffAction = getConfigValue formatConfigExternalDiff  -- | Return `True` if the user requested pretty diffs, `False` otherwise. prettyPrint :: FormatM Bool-prettyPrint = maybe False (const True) <$> getConfig formatConfigPrettyPrintFunction+prettyPrint = maybe False (const True) <$> getConfigValue formatConfigPrettyPrintFunction {-# DEPRECATED prettyPrint "use `prettyPrintFunction` instead" #-}  -- | Return a function for pretty-printing if the user requested pretty diffs,@@ -157,13 +161,13 @@ -- -- @since 2.10.0 prettyPrintFunction :: FormatM (Maybe (String -> String -> (String, String)))-prettyPrintFunction = getConfig formatConfigPrettyPrintFunction+prettyPrintFunction = getConfigValue formatConfigPrettyPrintFunction  -- | Return `True` if the user requested unicode output, `False` otherwise. -- -- @since 2.9.0 outputUnicode :: FormatM Bool-outputUnicode = getConfig formatConfigOutputUnicode+outputUnicode = getConfigValue formatConfigOutputUnicode  -- | The same as `write`, but adds a newline character. writeLine :: String -> FormatM ()@@ -198,12 +202,17 @@ , stateColor           :: Maybe SGR } -getConfig :: (FormatConfig -> a) -> FormatM a-getConfig f = gets (f . stateConfig)+-- | @since 2.11.5+getConfig :: FormatM FormatConfig+getConfig = gets stateConfig +-- | @since 2.11.5+getConfigValue :: (FormatConfig -> a) -> FormatM a+getConfigValue f = gets (f . stateConfig)+ -- | The random seed that is used for QuickCheck. usedSeed :: FormatM Integer-usedSeed = getConfig formatConfigUsedSeed+usedSeed = getConfigValue formatConfigUsedSeed  -- NOTE: We use an IORef here, so that the state persists when UserInterrupt is -- thrown.@@ -257,11 +266,11 @@ -- -- @since 2.9.0 getExpectedTotalCount :: FormatM Int-getExpectedTotalCount = getConfig formatConfigExpectedTotalCount+getExpectedTotalCount = getConfigValue formatConfigExpectedTotalCount  writeTransient :: String -> FormatM () writeTransient new = do-  reportProgress <- getConfig formatConfigReportProgress+  reportProgress <- getConfigValue formatConfigReportProgress   when reportProgress $ do     write new     liftIO $ IO.hFlush stdout@@ -310,7 +319,7 @@ -- | Set a color, run an action, and finally reset colors. withColor :: SGR -> String -> FormatM a -> FormatM a withColor color cls action = do-  produceHTML <- getConfig formatConfigHtmlOutput+  produceHTML <- getConfigValue formatConfigHtmlOutput   (if produceHTML then htmlSpan cls else withColor_ color) action  htmlSpan :: String -> FormatM a -> FormatM a@@ -323,14 +332,14 @@  setColor :: Maybe SGR -> FormatM () setColor color = do-  useColor <- getConfig formatConfigUseColor+  useColor <- getConfigValue formatConfigUseColor   when useColor $ do     modify (\ state -> state { stateColor = color })  -- | Output given chunk in red. extraChunk :: String -> FormatM () extraChunk s = do-  diff <- getConfig formatConfigUseDiff+  diff <- getConfigValue formatConfigUseDiff   case diff of     True -> extra s     False -> write s@@ -341,7 +350,7 @@ -- | Output given chunk in green. missingChunk :: String -> FormatM () missingChunk s = do-  diff <- getConfig formatConfigUseDiff+  diff <- getConfigValue formatConfigUseDiff   case diff of     True -> missing s     False -> write s
src/Test/Hspec/Core/Formatters/V2.hs view
@@ -33,6 +33,11 @@ , FormatM , formatterToFormat +-- ** Accessing config values+, getConfig+, getConfigValue+, FormatConfig(..)+ -- ** Accessing the runner state , getSuccessCount , getPendingCount@@ -76,7 +81,7 @@  -- ** Helpers , formatLocation-, formatException+, Util.formatException  #ifdef TEST , Chunk(..)@@ -90,7 +95,8 @@ import           System.IO (hFlush, stdout)  import           Data.Char-import           Test.Hspec.Core.Util+import           Test.Hspec.Core.Util hiding (formatException)+import qualified Test.Hspec.Core.Util as Util import           Test.Hspec.Core.Clock import           Test.Hspec.Core.Example (Location(..), Progress) import           Text.Printf@@ -110,6 +116,10 @@   , FormatM   , formatterToFormat +  , getConfig+  , getConfigValue+  , FormatConfig(..)+   , getSuccessCount   , getPendingCount   , getFailCount@@ -341,6 +351,7 @@          Error info e -> do           mapM_ indent info+          formatException <- getConfigValue formatConfigFormatException           withFailColor . indent $ "uncaught exception: " ++ formatException e  
src/Test/Hspec/Core/Runner.hs view
@@ -383,6 +383,7 @@       , formatConfigExternalDiff = if configDiff config then ($ configDiffContext config) <$> configExternalDiff config else Nothing       , formatConfigPrettyPrint = configPrettyPrint config       , formatConfigPrettyPrintFunction = if configPrettyPrint config then Just (configPrettyPrintFunction config outputUnicode) else Nothing+      , formatConfigFormatException = configFormatException config       , formatConfigPrintTimes = configTimes config       , formatConfigHtmlOutput = configHtmlOutput config       , formatConfigPrintCpuTime = configPrintCpuTime config
src/Test/Hspec/Core/Util.hs view
@@ -16,6 +16,7 @@ -- * Working with exceptions , safeTry , formatException+, formatExceptionWith ) where  import           Prelude ()@@ -137,9 +138,13 @@ -- -- @since 2.0.0 formatException :: SomeException -> String-formatException err@(SomeException e) = case fromException err of-  Just ioe -> showType ioe ++ " of type " ++ showIOErrorType ioe ++ "\n" ++ show ioe-  Nothing  -> showType e ++ "\n" ++ show e+formatException = formatExceptionWith show++-- | @since 2.11.5+formatExceptionWith :: (SomeException -> String) -> SomeException -> String+formatExceptionWith showException err@(SomeException e) = case fromException err of+  Just ioe -> showType ioe ++ " of type " ++ showIOErrorType ioe ++ "\n" ++ showException (toException ioe)+  Nothing  -> showType e ++ "\n" ++ showException (SomeException e)   where     showIOErrorType :: IOException -> String     showIOErrorType ioe = case ioe_type ioe of
test/Test/Hspec/Core/Formatters/InternalSpec.hs view
@@ -10,21 +10,10 @@ import           Test.Hspec.Core.Formatters.Internal  formatConfig :: FormatConfig-formatConfig = FormatConfig {+formatConfig = defaultFormatConfig {   formatConfigUseColor = True-, formatConfigReportProgress = False-, formatConfigOutputUnicode = False , formatConfigUseDiff = True , formatConfigDiffContext = Just 3-, formatConfigExternalDiff = Nothing-, formatConfigPrettyPrint = False-, formatConfigPrettyPrintFunction = Nothing-, formatConfigPrintTimes = False-, formatConfigHtmlOutput = False-, formatConfigPrintCpuTime = False-, formatConfigUsedSeed = 0-, formatConfigExpectedTotalCount = 0-, formatConfigExpertMode = False }  spec :: Spec
test/Test/Hspec/Core/Formatters/V2Spec.hs view
@@ -20,23 +20,14 @@     H.it "exceptions" (undefined :: Spec.Result)     H.it "fail 3"     (H.Result "" $ Spec.Failure Nothing H.NoReason) - formatConfig :: FormatConfig-formatConfig = FormatConfig {-  formatConfigUseColor = False-, formatConfigReportProgress = False-, formatConfigOutputUnicode = unicode+formatConfig = defaultFormatConfig {+  formatConfigOutputUnicode = unicode , formatConfigUseDiff = True , formatConfigDiffContext = Just 3 , formatConfigExternalDiff = Nothing , formatConfigPrettyPrint = True , formatConfigPrettyPrintFunction = Just (H.configPrettyPrintFunction H.defaultConfig unicode)-, formatConfigPrintTimes = False-, formatConfigHtmlOutput = False-, formatConfigPrintCpuTime = False-, formatConfigUsedSeed = 0-, formatConfigExpectedTotalCount = 0-, formatConfigExpertMode = False } where     unicode = True 
test/Test/Hspec/Core/RunnerSpec.hs view
@@ -35,6 +35,18 @@ person :: Int -> Person person = Person "Joe" +data MyException = MyException+  deriving (Eq, Show)++instance Exception MyException where+  displayException MyException = "my exception"++resultWithColorizedReason :: H.Result+resultWithColorizedReason = H.Result {+  H.resultInfo = "info"+, H.resultStatus = H.Failure Nothing . H.ColorizedReason $ "some " <> green "colorized" <> " error message"+}+ spec :: Spec spec = do   describe "hspec" $ do@@ -531,12 +543,45 @@           , "        but got: Person {personName = \"Joe\", personAge = 23}"           ] -    let-      resultWithColorizedReason :: H.Result-      resultWithColorizedReason = H.Result {-          H.resultInfo = "info"-        , H.resultStatus = H.Failure Nothing . H.ColorizedReason $ "some " <> green "colorized" <> " error message"-        }+    context "when formatting exceptions" $ do+      let spec_ = H.it "foo" $ void (throwIO MyException)+      context "with --show-exceptions" $ do+        it "uses `show`" $ do+          hspecCapture ["--seed=0", "--format=failed-examples", "--display-exceptions", "--show-exceptions"] spec_+          `shouldReturn` unlines [+              ""+            , "Failures:"+            , ""+            , "  1) foo"+            , "       uncaught exception: MyException"+            , "       MyException"+            , ""+            , "  To rerun use: --match \"/foo/\""+            , ""+            , "Randomized with seed 0"+            , ""+            , "Finished in 0.0000 seconds"+            , "1 example, 1 failure"+            ]++      context "with --display-exceptions" $ do+        it "uses `displayException`" $ do+          hspecCapture ["--seed=0", "--format=failed-examples", "--show-exceptions", "--display-exceptions"] spec_+          `shouldReturn` unlines [+              ""+            , "Failures:"+            , ""+            , "  1) foo"+            , "       uncaught exception: MyException"+            , "       my exception"+            , ""+            , "  To rerun use: --match \"/foo/\""+            , ""+            , "Randomized with seed 0"+            , ""+            , "Finished in 0.0000 seconds"+            , "1 example, 1 failure"+            ]      context "with --color" $ do       it "outputs ColorizedReason" $ do
version.yaml view
@@ -1,5 +1,6 @@-version: &version 2.11.4+version: &version 2.11.5 synopsis: A Testing Framework for Haskell+author: Simon Hengel <sol@typeful.net> maintainer: Simon Hengel <sol@typeful.net> category: Testing stability: experimental