hspec-contrib-0.4.0/0000755000000000000000000000000013050207567012446 5ustar0000000000000000hspec-contrib-0.4.0/LICENSE0000644000000000000000000000226113050207567013454 0ustar0000000000000000Copyright (c) 2011-2017 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.4.0/Setup.lhs0000644000000000000000000000011413050207567014252 0ustar0000000000000000#!/usr/bin/env runhaskell > import Distribution.Simple > main = defaultMain hspec-contrib-0.4.0/hspec-contrib.cabal0000644000000000000000000000241713050207567016176 0ustar0000000000000000name: hspec-contrib version: 0.4.0 license: MIT license-file: LICENSE copyright: (c) 2011-2017 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 , 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.4.0/test/0000755000000000000000000000000013050207567013425 5ustar0000000000000000hspec-contrib-0.4.0/test/Spec.hs0000644000000000000000000000005413050207567014652 0ustar0000000000000000{-# OPTIONS_GHC -F -pgmF hspec-discover #-} hspec-contrib-0.4.0/test/Helper.hs0000644000000000000000000000036513050207567015204 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.4.0/test/Test/0000755000000000000000000000000013050207567014344 5ustar0000000000000000hspec-contrib-0.4.0/test/Test/Hspec/0000755000000000000000000000000013050207567015406 5ustar0000000000000000hspec-contrib-0.4.0/test/Test/Hspec/Contrib/0000755000000000000000000000000013050207567017006 5ustar0000000000000000hspec-contrib-0.4.0/test/Test/Hspec/Contrib/RetrySpec.hs0000644000000000000000000000075613050207567021272 0ustar0000000000000000module Test.Hspec.Contrib.RetrySpec (main, spec) where import Helper import Test.Hspec.Contrib.Retry main :: IO () main = hspec spec 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.4.0/test/Test/Hspec/Contrib/HUnitSpec.hs0000644000000000000000000000261113050207567021204 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Test.Hspec.Contrib.HUnitSpec (main, spec) where import Helper import Test.Hspec.Core.Spec import Test.Hspec.Contrib.HUnit import Test.HUnit main :: IO () main = hspec spec shouldYield :: Test -> [Tree (ActionWith ()) String] -> Expectation a `shouldYield` b = map (Blind . fmap itemRequirement) <$> runSpecM (fromHUnitTest a) `shouldReturn` map Blind b instance Eq a => Eq (Tree c a) where x == y = case (x, y) of (Node s1 xs, Node s2 ys) -> s1 == s2 && xs == ys (Leaf x1, Leaf x2) -> x1 == x2 _ -> False 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.4.0/src/0000755000000000000000000000000013050207567013235 5ustar0000000000000000hspec-contrib-0.4.0/src/Test/0000755000000000000000000000000013050207567014154 5ustar0000000000000000hspec-contrib-0.4.0/src/Test/Hspec/0000755000000000000000000000000013050207567015216 5ustar0000000000000000hspec-contrib-0.4.0/src/Test/Hspec/Contrib/0000755000000000000000000000000013050207567016616 5ustar0000000000000000hspec-contrib-0.4.0/src/Test/Hspec/Contrib/HUnit.hs0000644000000000000000000000174713050207567020212 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.4.0/src/Test/Hspec/Contrib/Retry.hs0000644000000000000000000000176013050207567020263 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 r <- safeEvaluateExample example a b c case r of Right result -> case result of Success{} -> return result Pending{} -> return result Failure{} -> retry Left _ -> 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