hspec-contrib-0.5.1/0000755000000000000000000000000013367446601012455 5ustar0000000000000000hspec-contrib-0.5.1/LICENSE0000644000000000000000000000226113367446601013463 0ustar0000000000000000Copyright (c) 2011-2018 Simon Hengel Copyright (c) 2011-2012 Trystan Spangler Copyright (c) 2011-2011 Greg Weber 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. hspec-contrib-0.5.1/Setup.lhs0000644000000000000000000000011413367446601014261 0ustar0000000000000000#!/usr/bin/env runhaskell > import Distribution.Simple > main = defaultMain hspec-contrib-0.5.1/hspec-contrib.cabal0000644000000000000000000000243013367446601016200 0ustar0000000000000000name: hspec-contrib version: 0.5.1 license: MIT license-file: LICENSE copyright: (c) 2011-2018 Simon Hengel, (c) 2014 Junji Hashimoto maintainer: Simon Hengel build-type: Simple cabal-version: >= 1.10 category: Testing stability: experimental bug-reports: https://github.com/hspec/hspec/issues homepage: http://hspec.github.io/ synopsis: Contributed functionality for Hspec description: Contributed functionality for Hspec source-repository head type: git location: https://github.com/hspec/hspec subdir: hspec-contrib library ghc-options: -Wall hs-source-dirs: src build-depends: base == 4.* , hspec-core >= 2.5.0 , HUnit exposed-modules: Test.Hspec.Contrib.Retry Test.Hspec.Contrib.HUnit other-modules: default-language: Haskell2010 test-suite spec type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Spec.hs other-modules: Helper Test.Hspec.Contrib.RetrySpec Test.Hspec.Contrib.HUnitSpec ghc-options: -Wall build-depends: base == 4.* , hspec-core , HUnit , hspec-contrib , hspec , QuickCheck default-language: Haskell2010 hspec-contrib-0.5.1/test/0000755000000000000000000000000013367446601013434 5ustar0000000000000000hspec-contrib-0.5.1/test/Spec.hs0000644000000000000000000000005413367446601014661 0ustar0000000000000000{-# OPTIONS_GHC -F -pgmF hspec-discover #-} hspec-contrib-0.5.1/test/Helper.hs0000644000000000000000000000036513367446601015213 0ustar0000000000000000module Helper ( module Test.Hspec , module Test.QuickCheck , module Control.Applicative , module Data.IORef ) where import Test.Hspec import Test.QuickCheck import Control.Applicative import Data.IORef hspec-contrib-0.5.1/test/Test/0000755000000000000000000000000013367446601014353 5ustar0000000000000000hspec-contrib-0.5.1/test/Test/Hspec/0000755000000000000000000000000013367446601015415 5ustar0000000000000000hspec-contrib-0.5.1/test/Test/Hspec/Contrib/0000755000000000000000000000000013367446601017015 5ustar0000000000000000hspec-contrib-0.5.1/test/Test/Hspec/Contrib/RetrySpec.hs0000644000000000000000000000070713367446601021275 0ustar0000000000000000module Test.Hspec.Contrib.RetrySpec (spec) where import Helper import Test.Hspec.Contrib.Retry spec :: Spec spec = do describe "retryWith" $ do ref <- runIO $ newIORef (0::Int) it "retry 11 times, then check the value" $ do let incr :: IO Int incr = do val <- readIORef ref writeIORef ref (val+1) return val retryWith 11 $ do incr `shouldReturn` (10::Int) hspec-contrib-0.5.1/test/Test/Hspec/Contrib/HUnitSpec.hs0000644000000000000000000000225413367446601021216 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Test.Hspec.Contrib.HUnitSpec (spec) where import Helper import Test.Hspec.Core.Spec import Test.Hspec.Contrib.HUnit import Test.HUnit shouldYield :: Test -> [Tree () String] -> Expectation a `shouldYield` b = map (bimapTree (const ()) itemRequirement) <$> runSpecM (fromHUnitTest a) `shouldReturn` b spec :: Spec spec = do describe "fromHUnitTest" $ do let e = TestCase $ pure () it "works for a TestCase" $ do e `shouldYield` [Leaf ""] it "works for a labeled TestCase" $ do TestLabel "foo" e `shouldYield` [Leaf "foo"] it "works for a TestCase with nested labels" $ do (TestLabel "foo" . TestLabel "bar") e `shouldYield` [Node "foo" [Leaf "bar"]] it "works for a flat TestList" $ do TestList [e, e, e] `shouldYield` [Leaf "", Leaf "", Leaf ""] it "works for a nested TestList" $ do (TestLabel "foo" . TestLabel "bar" . TestList) [TestLabel "one" e, TestLabel "two" e, TestLabel "three" e] `shouldYield` [Node "foo" [Node "bar" [Leaf "one", Leaf "two", Leaf "three"]]] hspec-contrib-0.5.1/src/0000755000000000000000000000000013367446601013244 5ustar0000000000000000hspec-contrib-0.5.1/src/Test/0000755000000000000000000000000013367446601014163 5ustar0000000000000000hspec-contrib-0.5.1/src/Test/Hspec/0000755000000000000000000000000013367446601015225 5ustar0000000000000000hspec-contrib-0.5.1/src/Test/Hspec/Contrib/0000755000000000000000000000000013367446601016625 5ustar0000000000000000hspec-contrib-0.5.1/src/Test/Hspec/Contrib/HUnit.hs0000644000000000000000000000174713367446601020221 0ustar0000000000000000-- | -- maintainer: Simon Hengel module Test.Hspec.Contrib.HUnit ( -- * Interoperability with HUnit fromHUnitTest , specListFromHUnitTest ) where import Test.Hspec.Core.Spec import Test.HUnit (Test (..)) -- | -- Convert a HUnit test suite to a spec. This can be used to run existing -- HUnit tests with Hspec. fromHUnitTest :: Test -> Spec fromHUnitTest = fromSpecList . specListFromHUnitTest -- | -- @specListFromHUnitTest@ is similar to `fromHUnitTest`, but it constructs a -- list of `SpecTree`s instead of a `Spec`. specListFromHUnitTest :: Test -> [SpecTree ()] specListFromHUnitTest t = case t of TestList xs -> map go xs x -> [go x] where go :: Test -> SpecTree () go t_ = case t_ of TestLabel s (TestCase e) -> specItem s e TestLabel s (TestList xs) -> specGroup s (map go xs) TestLabel s x -> specGroup s [go x] TestList xs -> specGroup "" (map go xs) TestCase e -> specItem "" e hspec-contrib-0.5.1/src/Test/Hspec/Contrib/Retry.hs0000644000000000000000000000171413367446601020271 0ustar0000000000000000{-# LANGUAGE TypeFamilies #-} -- | -- maintainer: Junji Hashimoto module Test.Hspec.Contrib.Retry (retryWith) where import Test.Hspec.Core.Spec data Retry a = Retry Int a instance Example a => Example (Retry a) where type Arg (Retry a) = Arg a evaluateExample (Retry n example) a b c | n > 1 = do result <- safeEvaluateExample example a b c case result of Result _ Success{} -> return result Result _ Pending{} -> return result Result _ Failure{} -> retry | otherwise = evaluateExample example a b c where retry = evaluateExample (Retry (pred n) example) a b c -- | Retry evaluating example that may be failed until success. retryWith :: Int -- ^ number of retries, when this number is 1, just evaluate example and finish. -> a -- ^ retried example -> Retry a -- ^ Retry is instance of Example. retryWith = Retry