tasty-hspec 1.1.3.3 → 1.1.4
raw patch · 4 files changed
+122/−35 lines, 4 filesdep ~hspecdep ~hspec-coredep ~tastyPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: hspec, hspec-core, tasty, tasty-quickcheck
API changes (from Hackage documentation)
- Test.Tasty.Hspec: QuickCheckMaxRatio :: Int -> QuickCheckMaxRatio
- Test.Tasty.Hspec: QuickCheckMaxSize :: Int -> QuickCheckMaxSize
- Test.Tasty.Hspec: QuickCheckReplay :: Maybe Int -> QuickCheckReplay
- Test.Tasty.Hspec: QuickCheckTests :: Int -> QuickCheckTests
- Test.Tasty.Hspec: SmallCheckDepth :: Int -> SmallCheckDepth
- Test.Tasty.Hspec: newtype QuickCheckMaxRatio :: *
- Test.Tasty.Hspec: newtype QuickCheckMaxSize :: *
- Test.Tasty.Hspec: newtype QuickCheckReplay :: *
- Test.Tasty.Hspec: newtype QuickCheckTests :: *
- Test.Tasty.Hspec: newtype SmallCheckDepth :: *
Files
- .gitignore +1/−0
- CHANGELOG.md +8/−0
- src/Test/Tasty/Hspec.hs +94/−32
- tasty-hspec.cabal +19/−3
.gitignore view
@@ -1,3 +1,4 @@ dist/ dist-newstyle/+.ghc.environment.* .stack-work/
CHANGELOG.md view
@@ -5,6 +5,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/). +## [1.1.4] - 2018-3-18++### Changed+- Support hspec-2.5.0++### Removed+- Re-exports of QuickCheck and SmallCheck options+ ## [1.1.3.3] - 2018-1-26 ### Removed
src/Test/Tasty/Hspec.hs view
@@ -1,23 +1,25 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} -module Test.Tasty.Hspec (- -- * Test+-- | @hspec@ and @tasty@ serve similar purposes; consider using one or the+-- other.+--+-- However, in a pinch, this module allows you to run an @hspec@ 'H.Spec' as a+-- @tasty@ 'T.TestTree'.+--++module Test.Tasty.Hspec+ ( -- * Documentation testSpec , testSpecs- -- * Options- -- | === Re-exported from <https://hackage.haskell.org/package/tasty-smallcheck tasty-smallcheck>- , SmallCheckDepth(..)- -- | === Re-exported from <https://hackage.haskell.org/package/tasty-quickcheck tasty-quickcheck>- , QuickCheckMaxRatio(..)- , QuickCheckMaxSize(..)- , QuickCheckReplay(..)- , QuickCheckTests(..)- -- * Hspec re-export , module Test.Hspec+ -- * Examples+ -- $examples ) where import Control.Applicative ((<$>))+import Control.Exception (SomeException)+import Data.Maybe (catMaybes, fromMaybe) import Data.Monoid (mconcat) import Data.Proxy import Data.Typeable (Typeable)@@ -35,19 +37,43 @@ -- For re-export. import Test.Hspec-import Test.Tasty.SmallCheck (SmallCheckDepth(..))-import Test.Tasty.QuickCheck- (QuickCheckMaxRatio(..), QuickCheckMaxSize(..), QuickCheckReplay(..),- QuickCheckTests(..)) +-- $examples+--+-- The simplest usage of this library involves first creating a 'T.TestTree' in+-- @IO@, then running it with 'T.defaultMain'.+--+-- @+-- main = do+-- spec <- 'testSpec' "spec" mySpec+-- 'T.defaultMain'+-- ('T.testGroup' "tests"+-- [ spec+-- , ...+-- ])+-- @+--+-- However, if you don't do any @IO@ during 'Spec' creation, or the @IO@ need+-- not be performed at any particular time relative to other @IO@ actions, it's+-- perfectly fine to use 'System.IO.unsafePerformIO'.+--+-- @+-- main = do+-- 'T.defaultMain'+-- ('T.testGroup' "tests"+-- [ 'System.IO.unsafePerformIO' ('testSpec' "spec" mySpec)+-- , ...+-- ])+-- @+ -- | 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 name spec = T.testGroup name <$> testSpecs spec -- | Create a list of <https://hackage.haskell.org/package/tasty tasty>--- 'T.TestTree' from a <https://hackage.haskell.org/package/hspec Hspec>--- 'H.Spec' test. This returns the same tests as 'testSpec' but doesn't create+-- '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 spec = map specTreeToTestTree <$> H.runSpecM spec@@ -65,7 +91,8 @@ H.Leaf item -> T.singleTest (H.itemRequirement item) (Item item) -newtype Item = Item (H.Item ())+newtype Item+ = Item (H.Item ()) deriving Typeable instance T.IsTest Item where@@ -79,12 +106,13 @@ , H.paramsSmallCheckDepth = sc_depth } -#if MIN_VERSION_hspec(2,4,0)- either (T.testFailed . H.formatException) hspecResultToTastyResult+#if MIN_VERSION_hspec(2,4,0) && !MIN_VERSION_hspec(2,5,0)+ either handleUncaughtException hspecResultToTastyResult #else hspecResultToTastyResult #endif <$> ex params ($ ()) hprogress+ where sc_depth :: Int sc_depth = depth@@ -126,23 +154,57 @@ #endif hspecResultToTastyResult :: H.Result -> T.Result+#if MIN_VERSION_hspec(2,5,0)+hspecResultToTastyResult (H.Result _ result) =+#else hspecResultToTastyResult result =+#endif case result of- H.Success -> T.testPassed ""- H.Pending mstr -> T.testFailed ("Test pending" ++ maybe "" (": " ++) mstr)+ H.Success ->+ T.testPassed ""++#if MIN_VERSION_hspec(2,5,0)+ H.Pending _ x ->+#else+ H.Pending x ->+#endif+ handleResultPending x+ #if MIN_VERSION_hspec(2,4,0)- H.Failure _ reason ->- case reason of- H.NoReason -> T.testFailed ""- H.Reason str -> T.testFailed str- H.ExpectedButGot preface expected actual ->- T.testFailed $ mconcat- [ maybe "" (++ ": ") preface- , "expected " ++ expected- , ", but got " ++ actual- ]+ H.Failure _ x ->+ handleResultFailure x #elif MIN_VERSION_hspec(2,2,0) H.Fail _ str -> T.testFailed str #else H.Fail str -> T.testFailed str #endif++handleResultPending :: Maybe String -> T.Result+handleResultPending x =+ T.testFailed ("# PENDING: " ++ fromMaybe "No reason given" x)++-- FailureReason+--+-- - Introduced in 2.4.0+-- - Error constructor added in 2.5.0+#if MIN_VERSION_hspec(2,4,0)+handleResultFailure :: H.FailureReason -> T.Result+handleResultFailure reason =+ case reason of+ H.NoReason -> T.testFailed ""+ H.Reason x -> T.testFailed x+ H.ExpectedButGot preface expected actual ->+ T.testFailed . unlines . catMaybes $+ [ preface+ , Just ("expected: " ++ expected)+ , Just (" but got: " ++ actual)+ ]+#if MIN_VERSION_hspec(2,5,0)+ H.Error _ ex ->+ handleUncaughtException ex+#endif+#endif++handleUncaughtException :: SomeException -> T.Result+handleUncaughtException ex =+ T.testFailed ("uncaught exception: " ++ H.formatException ex)
tasty-hspec.cabal view
@@ -1,5 +1,5 @@ name: tasty-hspec-version: 1.1.3.3+version: 1.1.4 synopsis: Hspec support for the Tasty test framework. description: This package provides a Tasty provider for Hspec test suites.@@ -45,8 +45,8 @@ exposed-modules: Test.Tasty.Hspec hs-source-dirs: src build-depends: base >=4.5 && <5- , hspec >=2 && <2.5- , hspec-core >=2 && <2.5+ , hspec >=2 && <2.6+ , hspec-core >=2 && <2.6 , QuickCheck >=2.7 && <2.12 , tasty >=0.8 && <1.1 , tasty-smallcheck >=0.1 && <0.9@@ -54,6 +54,22 @@ , tasty-quickcheck >=0.3 && <0.9 || >=0.9.1 && <0.10 if impl(ghc < 7.8) build-depends: tagged >= 0.2+ other-extensions: CPP+ , DeriveDataTypeable default-language: Haskell2010 ghc-options: -Wall+ if impl(ghc >= 8.0)+ ghc-options: -Wcompat +-- This is a fake test-suite that I comment in to see the output++-- test-suite tests+-- hs-source-dirs: test+-- main-is: Main.hs+-- type: exitcode-stdio-1.0+-- build-depends: base+-- , hspec+-- , tasty+-- , tasty-hspec+-- default-language: Haskell2010+-- ghc-options: -Wall