tasty-hspec-1.1.5.1/0000755000000000000000000000000000000000000012250 5ustar0000000000000000tasty-hspec-1.1.5.1/.gitignore0000755000000000000000000000006500000000000014244 0ustar0000000000000000.ghc.environment.* .stack-work/ dist/ dist-newstyle/ tasty-hspec-1.1.5.1/.travis.yml0000755000000000000000000001123500000000000014366 0ustar0000000000000000# This Travis job script has been generated by a script via # # runghc make_travis_yml_2.hs 'tasty-hspec.cabal' '-o' '.travis.yml' # # For more information, see https://github.com/haskell-CI/haskell-ci # language: c sudo: false git: submodules: false # whether to recursively clone submodules cache: directories: - $HOME/.cabal/packages - $HOME/.cabal/store before_cache: - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log # remove files that are regenerated by 'cabal update' - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.* - rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx - rm -rfv $HOME/.cabal/packages/head.hackage matrix: include: - compiler: "ghc-8.6.2" # env: TEST=--disable-tests BENCH=--disable-benchmarks addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.2], sources: [hvr-ghc]}} - compiler: "ghc-8.4.4" # env: TEST=--disable-tests BENCH=--disable-benchmarks addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.4], sources: [hvr-ghc]}} - compiler: "ghc-8.2.2" # env: TEST=--disable-tests BENCH=--disable-benchmarks addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.2], sources: [hvr-ghc]}} - compiler: "ghc-8.0.2" # env: TEST=--disable-tests BENCH=--disable-benchmarks addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.2], sources: [hvr-ghc]}} before_install: - HC=${CC} - HCPKG=${HC/ghc/ghc-pkg} - unset CC - ROOTDIR=$(pwd) - mkdir -p $HOME/.local/bin - "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH" - HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') )) - echo $HCNUMVER install: - cabal --version - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]" - BENCH=${BENCH---enable-benchmarks} - TEST=${TEST---enable-tests} - HADDOCK=${HADDOCK-true} - UNCONSTRAINED=${UNCONSTRAINED-true} - NOINSTALLEDCONSTRAINTS=${NOINSTALLEDCONSTRAINTS-false} - GHCHEAD=${GHCHEAD-false} - travis_retry cabal update -v - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config" - rm -fv cabal.project cabal.project.local - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$' - "printf 'packages: \".\"\\n' > cabal.project" - touch cabal.project.local - "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg | grep -vw -- tasty-hspec | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi" - cat cabal.project || true - cat cabal.project.local || true - if [ -f "./configure.ac" ]; then (cd "." && autoreconf -i); fi - rm -f cabal.project.freeze - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all - cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all - rm -rf .ghc.environment.* "."/dist - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX) # Here starts the actual work to be performed for the package under test; # any command which exits with a non-zero exit code causes the build to fail. script: # test that source-distributions can be generated - cabal new-sdist all - mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/ - cd ${DISTDIR} || false - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \; - "printf 'packages: tasty-hspec-*/*.cabal\\n' > cabal.project" - touch cabal.project.local - "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg | grep -vw -- tasty-hspec | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi" - cat cabal.project || true - cat cabal.project.local || true # this builds all libraries and executables (without tests/benchmarks) - cabal new-build -w ${HC} --disable-tests --disable-benchmarks all # build & run tests, build benchmarks - cabal new-build -w ${HC} ${TEST} ${BENCH} all # cabal check - (cd tasty-hspec-* && cabal check) # haddock - if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi # Build without installed constraints for packages in global-db - if $UNCONSTRAINED; then rm -f cabal.project.local; echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks all; else echo "Not building without installed constraints"; fi # REGENDATA ["tasty-hspec.cabal","-o",".travis.yml"] # EOF tasty-hspec-1.1.5.1/CHANGELOG.md0000755000000000000000000000142000000000000014061 0ustar0000000000000000# Changelog All notable changes to this project will be documented in this file. 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.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 ## [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 - 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 tasty-hspec-1.1.5.1/LICENSE0000644000000000000000000000276600000000000013270 0ustar0000000000000000Copyright (c) 2013, 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.1.5.1/README.md0000755000000000000000000000026100000000000013531 0ustar0000000000000000# tasty-hspec Hspec provider for tasty [![Build Status](https://travis-ci.org/mitchellwrosen/tasty-hspec.svg?branch=master)](https://travis-ci.org/mitchellwrosen/tasty-hspec) tasty-hspec-1.1.5.1/Setup.hs0000644000000000000000000000005600000000000013705 0ustar0000000000000000import Distribution.Simple main = defaultMain tasty-hspec-1.1.5.1/cabal.project0000755000000000000000000000001400000000000014700 0ustar0000000000000000packages: . tasty-hspec-1.1.5.1/examples/0000755000000000000000000000000000000000000014066 5ustar0000000000000000tasty-hspec-1.1.5.1/examples/example.hs0000755000000000000000000000057500000000000016067 0ustar0000000000000000import 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.1.5.1/src/Test/Tasty/0000755000000000000000000000000000000000000015062 5ustar0000000000000000tasty-hspec-1.1.5.1/src/Test/Tasty/Hspec.hs0000644000000000000000000001773500000000000016475 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} -- | @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(..) -- * Re-exports , module Test.Hspec -- * Examples -- $examples ) where import Control.Applicative ((<$>)) import Control.Exception (SomeException) import Control.Monad (guard) 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.QuickCheck as QC import qualified Test.Tasty as T import qualified Test.Tasty.SmallCheck as TSC import qualified Test.Tasty.Options as T import qualified Test.Tasty.Providers as T import qualified Test.Tasty.QuickCheck as TQC import qualified Test.Tasty.Runners as T -- For re-export. import Test.Hspec -- $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 'T.TestTree' from an -- 'H.Spec'. testSpec :: T.TestName -> H.Spec -> IO T.TestTree testSpec name spec = T.testGroup name <$> testSpecs spec -- | 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 :: H.Spec -> IO [T.TestTree] testSpecs spec = catMaybes . map specTreeToTestTree <$> -- In hspec 2.6.0, "focus" was introduced. 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. H.runSpecM (doFocus spec) where doFocus :: H.Spec -> H.Spec doFocus = #if MIN_VERSION_hspec(2,6,0) H.focus #else id #endif specTreeToTestTree :: H.SpecTree () -> Maybe T.TestTree specTreeToTestTree spec_tree = case spec_tree of H.Node name spec_trees -> Just (T.testGroup name (mapMaybe specTreeToTestTree spec_trees)) H.NodeWithCleanup cleanup spec_trees -> T.WithResource (T.ResourceSpec (return ()) cleanup) . const <$> test_tree where test_tree :: Maybe T.TestTree test_tree = specTreeToTestTree (H.Node "(unnamed)" spec_trees) H.Leaf item -> do guard (hspecItemIsFocused item) Just (T.singleTest (H.itemRequirement item) (Item item)) newtype Item = Item (H.Item ()) deriving Typeable instance T.IsTest Item where -- run :: T.OptionSet -> Item -> (T.Progress -> IO ()) -> IO T.Result run opts (Item item) progress = do qc_args <- tastyOptionSetToQuickCheckArgs opts let pending_ :: String -> T.Result pending_ = case T.lookupOption opts of Failure -> T.testFailed Success -> T.testPassed let params :: H.Params params = H.Params { H.paramsQuickCheckArgs = qc_args , H.paramsSmallCheckDepth = sc_depth } #if MIN_VERSION_hspec(2,4,0) && !MIN_VERSION_hspec(2,5,0) either handleUncaughtException (hspecResultToTastyResult pending_) #else hspecResultToTastyResult pending_ #endif <$> hspecItemToExample item params ($ ()) hprogress where sc_depth :: Int sc_depth = depth where TSC.SmallCheckDepth depth = T.lookupOption opts hprogress :: H.Progress -> IO () hprogress (x,y) = progress T.Progress { T.progressText = "" , T.progressPercent = fromIntegral x / fromIntegral y } -- testOptions :: Tagged Item [T.OptionDescription] testOptions = return [ 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) ] tastyOptionSetToQuickCheckArgs :: T.OptionSet -> IO QC.Args tastyOptionSetToQuickCheckArgs opts = #if MIN_VERSION_tasty_quickcheck(0,9,1) snd <$> TQC.optionSetToArgs opts #else return (QC.stdArgs { QC.chatty = False , QC.maxDiscardRatio = max_ratio , QC.maxSize = max_size , QC.maxSuccess = num_tests , QC.replay = replay }) where TQC.QuickCheckTests num_tests = T.lookupOption opts TQC.QuickCheckReplay replay = T.lookupOption opts TQC.QuickCheckMaxSize max_size = T.lookupOption opts TQC.QuickCheckMaxRatio max_ratio = T.lookupOption opts #endif hspecResultToTastyResult :: (String -> T.Result) -> H.Result -> T.Result #if MIN_VERSION_hspec(2,5,0) hspecResultToTastyResult pending_ (H.Result _ result) = #else hspecResultToTastyResult pending_ result = #endif case result of H.Success -> T.testPassed "" #if MIN_VERSION_hspec(2,5,0) H.Pending _ x -> #else H.Pending x -> #endif handleResultPending pending_ x #if MIN_VERSION_hspec(2,4,0) 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 hspecItemIsFocused :: H.Item a -> Bool hspecItemIsFocused = #if MIN_VERSION_hspec(2,6,0) H.itemIsFocused #else const True #endif hspecItemToExample :: H.Item a -> H.Params -> (H.ActionWith a -> IO ()) -> H.ProgressCallback -> IO H.Result #if MIN_VERSION_hspec(2,6,0) hspecItemToExample (H.Item _ _ _ _ ex) = ex #else hspecItemToExample (H.Item _ _ _ ex) = ex #endif handleResultPending :: (String -> T.Result) -> Maybe String -> T.Result handleResultPending pending_ x = pending_ ("# 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) -- | 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 = Failure | Success instance T.IsOption TreatPendingAs where defaultValue = Failure parseValue s = case s of "failure" -> Just Failure "success" -> Just Success _ -> Nothing optionName = pure "treat-pending-as" optionHelp = pure "How to treat pending hspec tests ('failure' or 'success')" tasty-hspec-1.1.5.1/tasty-hspec.cabal0000644000000000000000000000377300000000000015512 0ustar0000000000000000cabal-version: 2.0 name: tasty-hspec version: 1.1.5.1 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: BSD3 license-file: LICENSE author: Mitchell Rosen maintainer: mitchellwrosen@gmail.com category: Testing build-type: Simple tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.2 extra-source-files: .gitignore .travis.yml cabal.project CHANGELOG.md examples/example.hs README.md source-repository head type: git location: https://github.com/mitchellwrosen/tasty-hspec.git library exposed-modules: Test.Tasty.Hspec hs-source-dirs: src build-depends: base ^>= 4.9 || ^>= 4.10 || ^>= 4.11 || ^>= 4.12 , hspec >= 2 && < 2.7 , hspec-core >= 2 && < 2.7 , QuickCheck >= 2.7 && < 2.13 , tasty >= 0.8 && < 1.2 , 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 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