tasty-hspec-1.2.0.3/0000755000000000000000000000000007346545000012310 5ustar0000000000000000tasty-hspec-1.2.0.3/.gitignore0000644000000000000000000000005107346545000014274 0ustar0000000000000000.ghc.environment.* .ghcid dist-newstyle/ tasty-hspec-1.2.0.3/CHANGELOG.md0000644000000000000000000000252207346545000014122 0ustar0000000000000000# Changelog ## [1.2.0.3] - 2023-01-11 - Drop support for `hspec < 2.10`, `hspec-core < 2.10`, `tasty < 1.3`, and `tasty-quickcheck < 0.9.1`. This was done to eliminate CPP and reduce maintenance burden. Moving forward, this library will opt to tighten compatibility bounds when dependencies make breaking changes, rather than reintroduce CPP. ## [1.2.0.2] - 2023-01-10 - Fix build when `tasty-quickcheck < 0.9.1` ## [1.2.0.1] - 2022-05-14 - Support hspec-2.10.0 ## [1.2] - 2021-05-28 - No changes, but 1.1.7 should have been a major version bump due to dropping the `Test.Hspec` re-export. ## [1.1.7] - 2021-05-12 - Support hspec-2.8.0 - Remove re-export of `Test.Hspec` - Drop support for hspec < 2.5 ## [1.1.6-r1] - 2021-03-13 - Support base-4.15 ## [1.1.6] - 2020-11-11 - Rename `Success`/`Failure` to `TreatPendingAsSuccess`/`TreatPendingAsFailure` - Support tasty-1.4 ## [1.1.5.1] - 2018-11-15 - Support hspec-2.6.0 ## [1.1.5] - 2018-06-27 - Add `TreatPendingAs` option, for allowing pending tests to be treated as successes ## [1.1.4] - 2018-3-18 - Support hspec-2.5.0 - Remove re-exports of QuickCheck and SmallCheck options ## [1.1.3.3] - 2018-1-26 - Remove redundant `random` dependency ## [1.1.3.2] - 2017-6-20 - Support tasty-0.9.1 - More accurate dependency version bounds ## [1.1.3.1] - 2017-1-25 - Support hspec-2.4.0 tasty-hspec-1.2.0.3/LICENSE0000644000000000000000000000277307346545000013326 0ustar0000000000000000Copyright (c) 2013-2022, Mitchell Rosen All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Mitchell Rosen nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. tasty-hspec-1.2.0.3/README.md0000644000000000000000000000122707346545000013571 0ustar0000000000000000# tasty-hspec [![Build Status](https://travis-ci.org/mitchellwrosen/tasty-hspec.svg?branch=master)](https://travis-ci.org/mitchellwrosen/tasty-hspec) [![Hackage](https://img.shields.io/hackage/v/tasty-hspec.svg)](https://hackage.haskell.org/package/tasty-hspec) [![Stackage LTS](https://stackage.org/package/tasty-hspec/badge/lts)](https://www.stackage.org/lts/package/tasty-hspec) [![Stackage Nightly](https://stackage.org/package/tasty-hspec/badge/nightly)](https://www.stackage.org/nightly/package/tasty-hspec) [![Dependencies](https://img.shields.io/hackage-deps/v/tasty-hspec)](https://packdeps.haskellers.com/reverse/tasty-hspec) Hspec provider for tasty tasty-hspec-1.2.0.3/Setup.hs0000644000000000000000000000005607346545000013745 0ustar0000000000000000import Distribution.Simple main = defaultMain tasty-hspec-1.2.0.3/examples/0000755000000000000000000000000007346545000014126 5ustar0000000000000000tasty-hspec-1.2.0.3/examples/example.hs0000644000000000000000000000061707346545000016121 0ustar0000000000000000import Test.Hspec import Test.Tasty import Test.Tasty.Hspec main :: IO () main = do tree <- testSpec "hspec tests" hspecSuite defaultMain tree hspecSuite :: Spec hspecSuite = do describe "passing test" $ it "5 == 5" $ 5 `shouldBe` (5 :: Int) describe "pending test" $ it "pending" $ pending describe "failing test" $ it "5 == 6" $ 5 `shouldBe` (6 :: Int) tasty-hspec-1.2.0.3/src/Test/Tasty/0000755000000000000000000000000007346545000015122 5ustar0000000000000000tasty-hspec-1.2.0.3/src/Test/Tasty/Hspec.hs0000644000000000000000000001552607346545000016531 0ustar0000000000000000-- | @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 ( -- * Tests testSpec, testSpecs, -- * Options TreatPendingAs (..), -- * Examples -- $examples ) where import Control.Monad (guard) import Data.Maybe (catMaybes, fromMaybe, mapMaybe) import Data.Proxy import Data.Typeable (Typeable) 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 qualified Test.Tasty.Options as Tasty.Options import qualified Test.Tasty.Providers as Tasty.Providers import qualified Test.Tasty.QuickCheck as Tasty.QuickCheck import qualified Test.Tasty.Runners as Tasty.Runners import qualified Test.Tasty.SmallCheck as Tasty.SmallCheck -- $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 -- , ... -- ]) -- @ -- -- You can treat an 'H.pending'/'H.pendingWith' test as a success instead of a -- failure (the default): -- -- @ -- tests :: TestTree -- tests = -- localOption TreatPendingAsSuccess $ testGroup "My Hspec TestTree" -- [ unsafePerformIO (testSpec "My first Hspec test" spec_firstHspecTest) -- , ... -- ] -- @ -- -- 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 'T.TestTree' from an -- 'H.Spec'. testSpec :: Tasty.TestName -> Hspec.Spec -> IO Tasty.TestTree testSpec name spec = do trees <- testSpecs spec pure (Tasty.testGroup name trees) -- | Create a list of 'T.TestTree' from an -- 'H.Spec'. This returns the same tests as 'testSpec' -- but doesn't create a test group from them. 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. (_configBuilder, trees) <- Hspec.Core.Spec.runSpecM (Hspec.focus spec) pure (mapMaybe specTreeToTestTree trees) specTreeToTestTree :: Hspec.Core.Spec.SpecTree () -> Maybe Tasty.TestTree specTreeToTestTree = \case Hspec.Core.Spec.Node name trees -> pure (Tasty.testGroup name (mapMaybe specTreeToTestTree trees)) Hspec.Core.Spec.NodeWithCleanup _loc cleanup trees -> do tree <- specTreeToTestTree (Hspec.Core.Spec.Node "(unnamed)" trees) pure (Tasty.Runners.WithResource (Tasty.Runners.ResourceSpec (pure ()) (const cleanup)) (const tree)) Hspec.Core.Spec.Leaf item -> do guard (Hspec.Core.Spec.itemIsFocused item) pure (Tasty.Providers.singleTest (Hspec.Core.Spec.itemRequirement item) (Item item)) newtype Item = Item (Hspec.Core.Spec.Item ()) deriving (Typeable) instance Tasty.Providers.IsTest Item where run opts (Item item) progress = do (_, qcArgs) <- Tasty.QuickCheck.optionSetToArgs opts -- optionSetToQuickCheckArgs :: Tasty.OptionSet -> IO QuickCheck.Args -- optionSetToQuickCheckArgs opts = -- snd <$> Tasty.QuickCheck.optionSetToArgs opts let params = Hspec.Core.Spec.Params { Hspec.Core.Spec.paramsQuickCheckArgs = qcArgs, Hspec.Core.Spec.paramsSmallCheckDepth = case Tasty.Options.lookupOption opts of Tasty.SmallCheck.SmallCheckDepth depth -> Just depth } Hspec.Core.Spec.Result _ result <- Hspec.Core.Spec.itemExample item params ($ ()) progress' pure ( case result of 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 Hspec.Core.Spec.Failure _ reason -> case reason of 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) ] Hspec.Core.Spec.Error _ exception -> Tasty.Providers.testFailed ("uncaught exception: " ++ Hspec.Core.Formatters.formatException exception) ) where progress' (x, y) = progress Tasty.Runners.Progress { Tasty.Runners.progressText = "", Tasty.Runners.progressPercent = fromIntegral x / fromIntegral y } testOptions = pure [ Tasty.Options.Option (Proxy :: Proxy TreatPendingAs), Tasty.Options.Option (Proxy :: Proxy Tasty.QuickCheck.QuickCheckTests), Tasty.Options.Option (Proxy :: Proxy Tasty.QuickCheck.QuickCheckReplay), Tasty.Options.Option (Proxy :: Proxy Tasty.QuickCheck.QuickCheckMaxSize), Tasty.Options.Option (Proxy :: Proxy Tasty.QuickCheck.QuickCheckMaxRatio), Tasty.Options.Option (Proxy :: Proxy Tasty.SmallCheck.SmallCheckDepth) ] -- | How to treat @hspec@ pending tests. -- -- @tasty@ does not have the concept of pending tests, so we must map them to -- either successes or failures. By default, they are treated as failures. -- -- Set via the command line flag @--treat-pending-as (success|failure)@. data TreatPendingAs = -- | Default. TreatPendingAsFailure | TreatPendingAsSuccess instance Tasty.Options.IsOption TreatPendingAs where defaultValue = TreatPendingAsFailure parseValue = \case "failure" -> Just TreatPendingAsFailure "success" -> Just TreatPendingAsSuccess _ -> Nothing optionName = pure "treat-pending-as" optionHelp = pure "How to treat pending hspec tests ('failure' or 'success')" showDefaultValue _ = Just "failure" tasty-hspec-1.2.0.3/tasty-hspec.cabal0000644000000000000000000000265207346545000015545 0ustar0000000000000000cabal-version: 2.2 name: tasty-hspec version: 1.2.0.3 synopsis: Hspec support for the Tasty test framework. description: This package provides a Tasty provider for Hspec test suites. homepage: https://github.com/mitchellwrosen/tasty-hspec license: BSD-3-Clause license-file: LICENSE author: Mitchell Rosen maintainer: mitchellwrosen@gmail.com category: Testing build-type: Simple tested-with: GHC == 9.0.2, GHC == 9.2.5, GHC == 9.4.4 extra-source-files: .gitignore CHANGELOG.md examples/example.hs README.md source-repository head type: git location: https://github.com/mitchellwrosen/tasty-hspec.git library build-depends: base ^>= 4.9 || ^>= 4.10 || ^>= 4.11 || ^>= 4.12 || ^>= 4.13 || ^>= 4.14 || ^>= 4.15 || ^>= 4.16 || ^>= 4.17, hspec ^>= 2.10, hspec-core ^>= 2.10, QuickCheck ^>= 2.7 || ^>= 2.8 || ^>= 2.9 || ^>= 2.10 || ^>= 2.11 || ^>= 2.12 || ^>= 2.13 || ^>= 2.14, tasty ^>= 1.3 || ^>= 1.4, tasty-smallcheck >= 0.1 && < 0.9, tasty-quickcheck ^>= 0.9.1 || ^>= 0.10, if impl(ghc < 7.8) build-depends: tagged >= 0.2 default-extensions: LambdaCase ScopedTypeVariables default-language: Haskell2010 exposed-modules: Test.Tasty.Hspec ghc-options: -Wall if impl(ghc >= 8.0) ghc-options: -Wcompat hs-source-dirs: src