tasty-hspec 1.2 → 1.2.0.1
raw patch · 7 files changed
+114/−82 lines, 7 filesdep ~basedep ~hspecdep ~hspec-corePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, hspec, hspec-core
API changes (from Hackage documentation)
Files
- .gitignore +0/−2
- CHANGELOG.md +6/−20
- LICENSE +1/−1
- cabal.project +0/−3
- src/Test/Tasty/Hspec.hs +46/−49
- src/Test/Tasty/Hspec/Compat.hs +53/−1
- tasty-hspec.cabal +8/−6
.gitignore view
@@ -1,5 +1,3 @@ .ghc.environment.* .ghcid-.stack-work/-dist/ dist-newstyle/
CHANGELOG.md view
@@ -1,9 +1,8 @@ # Changelog -All notable changes to this project will be documented in this file.+## [1.2.0.1] - 2022-05-14 -The format is based on [Keep a Changelog](http://keepachangelog.com/)-and this project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/).+- Support hspec-2.10.0 ## [1.2] - 2021-05-28 @@ -11,54 +10,41 @@ ## [1.1.7] - 2021-05-12 -### Changed - Support hspec-2.8.0--### Removed-- Don't re-export `Test.Hspec`+- Remove re-export of `Test.Hspec` - Drop support for hspec < 2.5 ## [1.1.6-r1] - 2021-03-13 -### Changed - Support base-4.15 ## [1.1.6] - 2020-11-11 -### Changed - Rename `Success`/`Failure` to `TreatPendingAsSuccess`/`TreatPendingAsFailure` - Support tasty-1.4 ## [1.1.5.1] - 2018-11-15 -### Changed - Support hspec-2.6.0 ## [1.1.5] - 2018-06-27 -### Added-- `TreatPendingAs` option, for allowing pending tests to be treated as successes+- Add `TreatPendingAs` option, for allowing pending tests to be treated as successes ## [1.1.4] - 2018-3-18 -### Changed - Support hspec-2.5.0--### Removed-- Re-exports of QuickCheck and SmallCheck options+- Remove re-exports of QuickCheck and SmallCheck options ## [1.1.3.3] - 2018-1-26 -### Removed-- Redundant `random` dependency+- Remove redundant `random` dependency ## [1.1.3.2] - 2017-6-20 -### Changed - Support tasty-0.9.1 - More accurate dependency version bounds ## [1.1.3.1] - 2017-1-25 -### Changed - Support hspec-2.4.0
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2013, Mitchell Rosen+Copyright (c) 2013-2022, Mitchell Rosen All rights reserved.
− cabal.project
@@ -1,3 +0,0 @@-packages: .--optimization: False
src/Test/Tasty/Hspec.hs view
@@ -22,15 +22,15 @@ import Data.Maybe (catMaybes, fromMaybe, mapMaybe) import Data.Proxy import Data.Typeable (Typeable)-import qualified Test.Hspec as H-import qualified Test.Hspec.Core.Formatters as H-import qualified Test.Hspec.Core.Spec as H-import qualified Test.Tasty as T+import qualified Test.Hspec as Hspec+import qualified Test.Hspec.Core.Formatters as Hspec.Core.Formatters+import qualified Test.Hspec.Core.Spec as Hspec.Core.Spec+import qualified Test.Tasty as Tasty import Test.Tasty.Hspec.Compat-import qualified Test.Tasty.Options as T-import qualified Test.Tasty.Providers as T+import qualified Test.Tasty.Options as Tasty.Options+import qualified Test.Tasty.Providers as Tasty.Providers import qualified Test.Tasty.QuickCheck as TQC-import qualified Test.Tasty.Runners as T+import qualified Test.Tasty.Runners as Tasty.Runners import qualified Test.Tasty.SmallCheck as TSC -- $examples@@ -75,86 +75,83 @@ -- | Create a <https://hackage.haskell.org/package/tasty tasty> 'T.TestTree' from an -- <https://hackage.haskell.org/package/hspec hspec> 'H.Spec'.-testSpec :: T.TestName -> H.Spec -> IO T.TestTree+testSpec :: Tasty.TestName -> Hspec.Spec -> IO Tasty.TestTree testSpec name spec = do trees <- testSpecs spec- pure (T.testGroup name trees)+ pure (Tasty.testGroup name trees) -- | Create a list of <https://hackage.haskell.org/package/tasty tasty> 'T.TestTree' from an -- <https://hackage.haskell.org/package/hspec hspec> 'H.Spec'. This returns the same tests as 'testSpec' -- but doesn't create a <https://hackage.haskell.org/package/tasty tasty> test group from them.-testSpecs :: H.Spec -> IO [T.TestTree]+testSpecs :: Hspec.Spec -> IO [Tasty.TestTree] testSpecs spec = do -- Here we do as hspec does, which is pre-process a spec by focusing the whole thing, which is a no-op if -- anything inside is already focused, but otherwise focuses every item. Then, when creating a tasty test tree, -- we just toss the unfocused items.- trees <- H.runSpecM (focus spec)+ trees <- runSpecM (focus spec) pure (mapMaybe specTreeToTestTree trees) -specTreeToTestTree :: H.SpecTree () -> Maybe T.TestTree+specTreeToTestTree :: Hspec.Core.Spec.SpecTree () -> Maybe Tasty.TestTree specTreeToTestTree = \case- Node name trees -> pure (T.testGroup name (mapMaybe specTreeToTestTree trees))+ Node name trees -> pure (Tasty.testGroup name (mapMaybe specTreeToTestTree trees)) NodeWithCleanup cleanup trees -> do- tree <- specTreeToTestTree (H.Node "(unnamed)" trees)- pure (T.WithResource (T.ResourceSpec (return ()) cleanup) (const tree))+ tree <- specTreeToTestTree (Node "(unnamed)" trees)+ pure (Tasty.Runners.WithResource (Tasty.Runners.ResourceSpec (pure ()) (twiddleCleanup cleanup)) (const tree)) Leaf item -> do guard (itemIsFocused item)- pure (T.singleTest (H.itemRequirement item) (Item item))+ pure (Tasty.Providers.singleTest (Hspec.Core.Spec.itemRequirement item) (Item item)) newtype Item- = Item (H.Item ())+ = Item (Hspec.Core.Spec.Item ()) deriving (Typeable) -instance T.IsTest Item where+instance Tasty.Providers.IsTest Item where run opts (Item item) progress = do qcArgs <- optionSetToQuickCheckArgs opts- H.Result _ result <- itemExample item (params qcArgs) ($ ()) progress'+ let params =+ Hspec.Core.Spec.Params+ { Hspec.Core.Spec.paramsQuickCheckArgs = qcArgs,+ Hspec.Core.Spec.paramsSmallCheckDepth = optionSetToSmallCheckDepth opts+ }+ Hspec.Core.Spec.Result _ result <- itemExample item params ($ ()) progress' pure ( case result of- H.Success -> T.testPassed ""- H.Pending _ reason ->- case T.lookupOption opts of- TreatPendingAsFailure -> T.testFailed reason'- TreatPendingAsSuccess -> T.testPassed reason'+ Hspec.Core.Spec.Success -> Tasty.Providers.testPassed ""+ Hspec.Core.Spec.Pending _ reason ->+ case Tasty.Options.lookupOption opts of+ TreatPendingAsFailure -> Tasty.Providers.testFailed reason'+ TreatPendingAsSuccess -> Tasty.Providers.testPassed reason' where reason' = "# PENDING: " ++ fromMaybe "No reason given" reason- H.Failure _ reason ->+ Hspec.Core.Spec.Failure _ reason -> case reason of- H.NoReason -> T.testFailed ""- H.Reason x -> T.testFailed x- H.ExpectedButGot preface expected actual ->- T.testFailed . unlines . catMaybes $+ Hspec.Core.Spec.NoReason -> Tasty.Providers.testFailed ""+ Hspec.Core.Spec.Reason x -> Tasty.Providers.testFailed x+ Hspec.Core.Spec.ExpectedButGot preface expected actual ->+ Tasty.Providers.testFailed . unlines . catMaybes $ [ preface, Just ("expected: " ++ expected), Just (" but got: " ++ actual) ]- H.Error _ exception -> T.testFailed ("uncaught exception: " ++ H.formatException exception)+ Hspec.Core.Spec.Error _ exception ->+ Tasty.Providers.testFailed ("uncaught exception: " ++ Hspec.Core.Formatters.formatException exception) ) where- params qcArgs =- H.Params- { H.paramsQuickCheckArgs = qcArgs,- H.paramsSmallCheckDepth =- case T.lookupOption opts of- TSC.SmallCheckDepth depth ->- depth- }- progress' (x, y) = progress- T.Progress- { T.progressText = "",- T.progressPercent = fromIntegral x / fromIntegral y+ Tasty.Runners.Progress+ { Tasty.Runners.progressText = "",+ Tasty.Runners.progressPercent = fromIntegral x / fromIntegral y } testOptions = pure- [ T.Option (Proxy :: Proxy TreatPendingAs),- T.Option (Proxy :: Proxy TQC.QuickCheckTests),- T.Option (Proxy :: Proxy TQC.QuickCheckReplay),- T.Option (Proxy :: Proxy TQC.QuickCheckMaxSize),- T.Option (Proxy :: Proxy TQC.QuickCheckMaxRatio),- T.Option (Proxy :: Proxy TSC.SmallCheckDepth)+ [ Tasty.Options.Option (Proxy :: Proxy TreatPendingAs),+ Tasty.Options.Option (Proxy :: Proxy TQC.QuickCheckTests),+ Tasty.Options.Option (Proxy :: Proxy TQC.QuickCheckReplay),+ Tasty.Options.Option (Proxy :: Proxy TQC.QuickCheckMaxSize),+ Tasty.Options.Option (Proxy :: Proxy TQC.QuickCheckMaxRatio),+ Tasty.Options.Option (Proxy :: Proxy TSC.SmallCheckDepth) ] -- | How to treat @hspec@ pending tests.@@ -168,7 +165,7 @@ TreatPendingAsFailure | TreatPendingAsSuccess -instance T.IsOption TreatPendingAs where+instance Tasty.Options.IsOption TreatPendingAs where defaultValue = TreatPendingAsFailure
src/Test/Tasty/Hspec/Compat.hs view
@@ -5,6 +5,9 @@ itemIsFocused, focus, optionSetToQuickCheckArgs,+ optionSetToSmallCheckDepth,+ runSpecM,+ twiddleCleanup, pattern Leaf, pattern Node,@@ -17,6 +20,11 @@ import qualified Test.QuickCheck as QuickCheck import qualified Test.Tasty.Options as Tasty import qualified Test.Tasty.QuickCheck as Tasty.QuickCheck+import qualified Test.Tasty.SmallCheck as Tasty.SmallCheck+#if MIN_VERSION_hspec_core(2,10,0)+import Data.Monoid (Endo)+import qualified Test.Hspec.Core.Runner as Hspec.Core.Runner+#endif {-# COMPLETE Leaf, Node, NodeWithCleanup #-} @@ -25,7 +33,7 @@ Hspec.Leaf item pattern Node :: String -> [Hspec.Tree c a] -> Hspec.Tree c a-pattern Node name trees <-+pattern Node name trees = Hspec.Node name trees pattern NodeWithCleanup :: c -> [Hspec.Tree c a] -> Hspec.Tree c a@@ -81,3 +89,47 @@ Tasty.QuickCheck.QuickCheckMaxRatio max_ratio = T.lookupOption opts #endif +-- In hspec-core-2.10.0, Int changed to Maybe Int+optionSetToSmallCheckDepth ::+ Tasty.OptionSet ->+#if MIN_VERSION_hspec_core(2,10,0)+ Maybe+#endif+ Int+optionSetToSmallCheckDepth opts =+ case Tasty.lookupOption opts of+ Tasty.SmallCheck.SmallCheckDepth depth ->+#if MIN_VERSION_hspec_core(2,10,0)+ Just+#endif+ depth++-- In hspec-core-2.10.0, runSpecM started returning an Endo Config, which we don't need. (Right? :shrug:)+runSpecM :: Hspec.SpecWith a -> IO [Hspec.SpecTree a]+runSpecM spec = do+#if MIN_VERSION_hspec_core(2,10,0)+ (_ :: Endo Hspec.Core.Runner.Config, trees) <- Hspec.runSpecM spec+ pure trees+#else+ Hspec.runSpecM spec+#endif++-- In hspec-core-2.10.0, the spec SpecTree type alias changed from+--+-- type SpecTree a = Tree (a -> IO ()) (Item a)+--+-- to+--+-- type SpecTree a = Tree (IO ()) (Item a)+--+-- So we have a function that "twiddles" the cleanup action (at monomorphic type `SpecTree ()`), which always returns a+-- value of type `() -> IO ()`+#if MIN_VERSION_hspec_core(2,10,0)+twiddleCleanup :: IO () -> () -> IO ()+twiddleCleanup =+ const+#else+twiddleCleanup :: (() -> IO ()) -> () -> IO ()+twiddleCleanup =+ id+#endif
tasty-hspec.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.0 name: tasty-hspec-version: 1.2+version: 1.2.0.1 synopsis: Hspec support for the Tasty test framework. description: This package provides a Tasty provider for Hspec test suites.@@ -13,9 +13,10 @@ category: Testing build-type: Simple +tested-with: GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.2+ extra-source-files: .gitignore- cabal.project CHANGELOG.md examples/example.hs README.md@@ -26,19 +27,20 @@ library build-depends:- base ^>= 4.9 || ^>= 4.10 || ^>= 4.11 || ^>= 4.12 || ^>= 4.13 || ^>= 4.14 || ^>= 4.15,- hspec >= 2.5 && < 2.9,- hspec-core >= 2.5 && < 2.9,+ base ^>= 4.9 || ^>= 4.10 || ^>= 4.11 || ^>= 4.12 || ^>= 4.13 || ^>= 4.14 || ^>= 4.15 || ^>= 4.16,+ hspec ^>= 2.5 || ^>= 2.6 || ^>= 2.7 || ^>= 2.8 || ^>= 2.9 || ^>= 2.10,+ hspec-core ^>= 2.5 || ^>= 2.6 || ^>= 2.7 || ^>= 2.8 || ^>= 2.9 || ^>= 2.10, QuickCheck ^>= 2.7 || ^>= 2.8 || ^>= 2.9 || ^>= 2.10 || ^>= 2.11 || ^>= 2.12 || ^>= 2.13 || ^>= 2.14, tasty ^>= 0.8 || ^>= 0.9 || ^>= 0.10 || ^>= 0.11 || ^>= 0.12 || ^>= 1.0 || ^>= 1.1 || ^>= 1.2 || ^>= 1.3 || ^>= 1.4, tasty-smallcheck >= 0.1 && < 0.9, -- 0.9 is missing 'optionSetToArgs' tasty-quickcheck >=0.3 && <0.9 || ^>=0.9.1 || ^>= 0.10 if impl(ghc < 7.8)- build-depends: tagged >= 0.2+ build-depends: tagged >= 0.2 default-extensions: LambdaCase PatternSynonyms+ ScopedTypeVariables default-language: Haskell2010 exposed-modules: Test.Tasty.Hspec ghc-options: -Wall