hspec-api (empty) → 2.8.0
raw patch · 10 files changed
+436/−0 lines, 10 filesdep +basedep +hspecdep +hspec-apisetup-changed
Dependencies added: base, hspec, hspec-api, hspec-core
Files
- LICENSE +19/−0
- Setup.lhs +3/−0
- hspec-api.cabal +59/−0
- src/Test/Hspec/Api/Format/V1.hs +73/−0
- src/Test/Hspec/Api/Formatters/V1.hs +99/−0
- src/Test/Hspec/Api/Formatters/V2.hs +120/−0
- test/Spec.hs +1/−0
- test/Test/Hspec/Api/Format/V1Spec.hs +22/−0
- test/Test/Hspec/Api/Formatters/V1Spec.hs +20/−0
- test/Test/Hspec/Api/Formatters/V2Spec.hs +20/−0
+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2022-2023 Simon Hengel <sol@typeful.net>++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ hspec-api.cabal view
@@ -0,0 +1,59 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.35.2.+--+-- see: https://github.com/sol/hpack++name: hspec-api+version: 2.8.0+synopsis: A Testing Framework for Haskell+description: This package provides a stable API that can be used to extend Hspec's functionality.+category: Testing+stability: stable+homepage: https://hspec.github.io/+bug-reports: https://github.com/hspec/hspec/issues+maintainer: Simon Hengel <sol@typeful.net>+copyright: (c) 2022-2023 Simon Hengel+license: MIT+license-file: LICENSE+build-type: Simple++source-repository head+ type: git+ location: https://github.com/hspec/hspec+ subdir: hspec-api++library+ exposed-modules:+ Test.Hspec.Api.Format.V1+ Test.Hspec.Api.Formatters.V1+ Test.Hspec.Api.Formatters.V2+ other-modules:+ Paths_hspec_api+ hs-source-dirs:+ src+ ghc-options: -Wall+ build-depends:+ base ==4.*+ , hspec-core >=2.8.0 && <2.11+ default-language: Haskell2010++test-suite spec+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Test.Hspec.Api.Format.V1Spec+ Test.Hspec.Api.Formatters.V1Spec+ Test.Hspec.Api.Formatters.V2Spec+ Paths_hspec_api+ hs-source-dirs:+ test+ ghc-options: -Wall+ build-tool-depends:+ hspec-discover:hspec-discover+ build-depends:+ base ==4.*+ , hspec ==2.*+ , hspec-api+ , hspec-core >=2.8.0 && <2.11+ default-language: Haskell2010
+ src/Test/Hspec/Api/Format/V1.hs view
@@ -0,0 +1,73 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE ViewPatterns #-}+-- |+-- Stability: stable+module Test.Hspec.Api.Format.V1 (+ Format+, FormatConfig(..)+, Event(..)+, Progress+, Path+, Location(..)+, Seconds(..)+, Item(..)+, Result(..)+, FailureReason(..)+, monadic++-- * Register a formatter+, useFormatter+, liftFormatter++-- * Re-exports+, Config+) where++import Test.Hspec.Core.Runner+import Test.Hspec.Core.Format hiding (FormatConfig(..))+import qualified Test.Hspec.Core.Format as Latest++-- |+-- Make a formatter available for use with @--format@ and use it by default.+useFormatter :: (String, FormatConfig -> IO Format) -> Config -> Config+useFormatter (liftFormatter -> formatter@(_, format)) config = (registerFormatter_ formatter config) { configFormat = Just format }++-- copy of Test.Hspec.Core.Runner.registerFormatter+registerFormatter_ :: (String, Latest.FormatConfig -> IO Latest.Format) -> Config -> Config+#if MIN_VERSION_hspec_core(2,9,0)+registerFormatter_ formatter config = config { configAvailableFormatters = formatter : configAvailableFormatters config }+#else+registerFormatter_ _ config = config+#endif++-- | Make a formatter compatible with types from "Test.Hspec.Core.Format".+liftFormatter :: (String, FormatConfig -> IO Format) -> (String, Latest.FormatConfig -> IO Format)+liftFormatter = fmap liftFormat+ where+ liftFormat :: (FormatConfig -> IO Format) -> Latest.FormatConfig -> IO Format+ liftFormat format = format . liftFormatConfig++data FormatConfig = FormatConfig {+ formatConfigUseColor :: Bool+, formatConfigUseDiff :: Bool+, formatConfigPrintTimes :: Bool+, formatConfigHtmlOutput :: Bool+, formatConfigPrintCpuTime :: Bool+, formatConfigUsedSeed :: Integer+, formatConfigExpectedTotalCount :: Int+}++liftFormatConfig :: Latest.FormatConfig -> FormatConfig+liftFormatConfig config = FormatConfig {+ formatConfigUseColor = Latest.formatConfigUseColor config+, formatConfigUseDiff = Latest.formatConfigUseDiff config+, formatConfigPrintTimes = Latest.formatConfigPrintTimes config+, formatConfigHtmlOutput = Latest.formatConfigHtmlOutput config+, formatConfigPrintCpuTime = Latest.formatConfigPrintCpuTime config+, formatConfigUsedSeed = Latest.formatConfigUsedSeed config+#if MIN_VERSION_hspec_core(2,9,0)+, formatConfigExpectedTotalCount = Latest.formatConfigExpectedTotalCount config+#else+, formatConfigExpectedTotalCount = Latest.formatConfigItemCount config+#endif+}
+ src/Test/Hspec/Api/Formatters/V1.hs view
@@ -0,0 +1,99 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE ViewPatterns #-}+-- |+-- Stability: deprecated+--+-- This module contains formatters that can be used with `hspecWith`:+--+-- @+-- import Test.Hspec+-- import Test.Hspec.Api.Formatters.V1+--+-- main :: IO ()+-- main = hspecWith (useFormatter ("my-formatter", formatter) defaultConfig) spec+--+-- formatter :: Formatter+-- formatter = ...+--+-- spec :: Spec+-- spec = ...+-- @+module Test.Hspec.Api.Formatters.V1 (++-- * Register a formatter+ useFormatter+, formatterToFormat++-- * Formatters+, silent+, checks+, specdoc+, progress+, failed_examples++-- * Implementing a custom Formatter+-- |+-- A formatter is a set of actions. Each action is evaluated when a certain+-- situation is encountered during a test run.+--+-- Actions live in the `FormatM` monad. It provides access to the runner state+-- and primitives for appending to the generated report.+, Formatter (..)+, FailureReason (..)+, FormatM++-- ** Accessing the runner state+, getSuccessCount+, getPendingCount+, getFailCount+, getTotalCount++, FailureRecord (..)+, getFailMessages+, usedSeed++, Seconds(..)+, getCPUTime+, getRealTime++-- ** Appending to the generated report+, write+, writeLine+, writeTransient++-- ** Dealing with colors+, withInfoColor+, withSuccessColor+, withPendingColor+, withFailColor++, useDiff+, extraChunk+, missingChunk++-- ** Helpers+, formatException++-- * Re-exports+, Location(..)+, Progress++, Config+) where++import Test.Hspec.Core.Formatters.V1+import Test.Hspec.Core.Runner+import Test.Hspec.Core.Format++-- |+-- Make a formatter available for use with @--format@ and use it by default.+useFormatter :: (String, Formatter) -> Config -> Config+useFormatter (fmap formatterToFormat -> formatter@(_, format)) config = (registerFormatter_ formatter config) { configFormat = Just format }++-- copy of Test.Hspec.Core.Runner.registerFormatter+registerFormatter_ :: (String, FormatConfig -> IO Format) -> Config -> Config+#if MIN_VERSION_hspec_core(2,9,0)+registerFormatter_ formatter config = config { configAvailableFormatters = formatter : configAvailableFormatters config }+#else+registerFormatter_ _ config = config+#endif
+ src/Test/Hspec/Api/Formatters/V2.hs view
@@ -0,0 +1,120 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE ViewPatterns #-}+-- |+-- Stability: stable+--+-- This module contains formatters that can be used with `hspecWith`:+--+-- @+-- import Test.Hspec+-- import Test.Hspec.Api.Formatters.V1+--+-- main :: IO ()+-- main = hspecWith (useFormatter ("my-formatter", formatter) defaultConfig) spec+--+-- formatter :: Formatter+-- formatter = ...+--+-- spec :: Spec+-- spec = ...+-- @+module Test.Hspec.Api.Formatters.V2 (++-- * Register a formatter+ useFormatter+, formatterToFormat++-- * Formatters+, silent+, checks+, specdoc+, progress+, failed_examples++-- * Implementing a custom Formatter+-- |+-- A formatter is a set of actions. Each action is evaluated when a certain+-- situation is encountered during a test run.+--+-- Actions live in the `FormatM` monad. It provides access to the runner state+-- and primitives for appending to the generated report.+, Formatter (..)+, Path+, Progress+, Location(..)+, Item(..)+, Result(..)+, FailureReason (..)+, FormatM++-- ** Accessing the runner state+, getSuccessCount+, getPendingCount+, getFailCount+, getTotalCount++, FailureRecord (..)+, getFailMessages+, usedSeed++, printTimes++, Seconds(..)+, getCPUTime+, getRealTime++-- ** Appending to the generated report+, write+, writeLine+, writeTransient++-- ** Dealing with colors+, withInfoColor+, withSuccessColor+, withPendingColor+, withFailColor++, useDiff+, diffContext+, externalDiffAction+, prettyPrint+, extraChunk+, missingChunk++-- ** Helpers+, formatLocation+, formatException++-- * Re-exports+, Config+) where++import Test.Hspec.Core.Formatters.V2+import Test.Hspec.Core.Runner (Config(..))+import Test.Hspec.Core.Format++#if !MIN_VERSION_hspec_core(2,10,6)+diffContext :: FormatM (Maybe Int)+diffContext = return Nothing++externalDiffAction :: FormatM (Maybe (String -> String -> IO ()))+externalDiffAction = return Nothing+#endif++-- |+-- Make a formatter available for use with @--format@ and use it by default.+useFormatter :: (String, Formatter) -> Config -> Config+useFormatter (fmap formatterToFormat -> formatter@(_, format)) config = (registerFormatter_ formatter config) { configFormat = Just format }++-- copy of Test.Hspec.Core.Runner.registerFormatter+registerFormatter_ :: (String, FormatConfig -> IO Format) -> Config -> Config+#if MIN_VERSION_hspec_core(2,9,0)+registerFormatter_ formatter config = config { configAvailableFormatters = formatter : configAvailableFormatters config }+#else+registerFormatter_ _ config = config+#endif++#if !MIN_VERSION_hspec_core(2,9,2)+prettyPrint :: FormatM Bool+prettyPrint = return True+#endif
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
+ test/Test/Hspec/Api/Format/V1Spec.hs view
@@ -0,0 +1,22 @@+module Test.Hspec.Api.Format.V1Spec (spec) where++import Test.Hspec+import Test.Hspec.Runner++import Data.IORef++import Test.Hspec.Api.Format.V1++spec :: Spec+spec = do+ describe "useFormatter" $ do+ it "sets a formatter to be used with a given config" $ do+ ref <- newIORef "NAY!"+ let+ formatter :: Format+ formatter event = case event of+ ItemDone {} -> writeIORef ref "YAY!"+ _ -> return ()++ hspecWith (useFormatter ("my-formatter", \ _ -> return formatter) defaultConfig) $ it "" True+ readIORef ref `shouldReturn` "YAY!"
+ test/Test/Hspec/Api/Formatters/V1Spec.hs view
@@ -0,0 +1,20 @@+module Test.Hspec.Api.Formatters.V1Spec (spec) where++import Test.Hspec+import Test.Hspec.Runner++import Data.IORef+import Control.Monad.IO.Class++import Test.Hspec.Api.Formatters.V1++spec :: Spec+spec = do+ describe "useFormatter" $ do+ it "sets a formatter to be used with a given config" $ do+ ref <- newIORef "NAY!"+ let+ formatter :: Formatter+ formatter = silent { exampleStarted = \ _ -> liftIO $ writeIORef ref "YAY!" }+ hspecWith (useFormatter ("my-formatter", formatter) defaultConfig) $ it "" True+ readIORef ref `shouldReturn` "YAY!"
+ test/Test/Hspec/Api/Formatters/V2Spec.hs view
@@ -0,0 +1,20 @@+module Test.Hspec.Api.Formatters.V2Spec (spec) where++import Test.Hspec+import Test.Hspec.Runner++import Data.IORef+import Control.Monad.IO.Class++import Test.Hspec.Api.Formatters.V2++spec :: Spec+spec = do+ describe "useFormatter" $ do+ it "sets a formatter to be used with a given config" $ do+ ref <- newIORef "NAY!"+ let+ formatter :: Formatter+ formatter = silent { formatterItemStarted = \ _ -> liftIO $ writeIORef ref "YAY!" }+ hspecWith (useFormatter ("my-formatter", formatter) defaultConfig) $ it "" True+ readIORef ref `shouldReturn` "YAY!"