tasty-quickcheck-0.3.1/0000755000000000000000000000000012226710466013163 5ustar0000000000000000tasty-quickcheck-0.3.1/LICENSE0000644000000000000000000000204312226710466014167 0ustar0000000000000000Copyright (c) 2013 Roman Cheplyaka 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. tasty-quickcheck-0.3.1/tasty-quickcheck.cabal0000644000000000000000000000160412226710466017424 0ustar0000000000000000-- Initial tasty-quickcheck.cabal generated by cabal init. For further -- documentation, see http://haskell.org/cabal/users-guide/ name: tasty-quickcheck version: 0.3.1 synopsis: QuickCheck support for the Tasty test framework. description: QuickCheck support for the Tasty test framework. license: MIT license-file: LICENSE author: Roman Cheplyaka maintainer: roma@ro-che.info -- copyright: category: Testing build-type: Simple -- extra-source-files: cabal-version: >=1.10 library exposed-modules: Test.Tasty.QuickCheck -- other-modules: other-extensions: GeneralizedNewtypeDeriving, DeriveDataTypeable build-depends: base == 4.*, tasty, QuickCheck >= 2.5 && < 3, tagged, random -- hs-source-dirs: default-language: Haskell2010 tasty-quickcheck-0.3.1/Setup.hs0000644000000000000000000000005612226710466014620 0ustar0000000000000000import Distribution.Simple main = defaultMain tasty-quickcheck-0.3.1/Test/0000755000000000000000000000000012226710466014102 5ustar0000000000000000tasty-quickcheck-0.3.1/Test/Tasty/0000755000000000000000000000000012226710466015206 5ustar0000000000000000tasty-quickcheck-0.3.1/Test/Tasty/QuickCheck.hs0000644000000000000000000001021012226710466017546 0ustar0000000000000000-- | This module allows to use QuickCheck properties in tasty. {-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-} module Test.Tasty.QuickCheck ( testProperty , QuickCheckTests(..) , QuickCheckReplay(..) , QuickCheckMaxSize(..) , QuickCheckMaxRatio(..) , module Test.QuickCheck ) where import Test.Tasty.Providers import Test.Tasty.Options import qualified Test.QuickCheck as QC import Test.QuickCheck hiding -- for re-export ( quickCheck , Args(..) , Result , stdArgs , quickCheckWith , quickCheckWithResult , quickCheckResult , verboseCheck , verboseCheckWith , verboseCheckWithResult , verboseCheckResult , verbose , Gen ) import Data.Typeable import Data.Proxy import Data.List import Text.Printf import System.Random import Control.Applicative newtype QC = QC QC.Property deriving Typeable -- | Create a 'Test' for a QuickCheck 'QC.Testable' property testProperty :: QC.Testable a => TestName -> a -> TestTree testProperty name prop = singleTest name $ QC $ QC.property prop -- | Number of test cases for QuickCheck to generate newtype QuickCheckTests = QuickCheckTests Int deriving (Num, Ord, Eq, Real, Enum, Integral, Typeable) -- | Replay a previous test using a replay token newtype QuickCheckReplay = QuickCheckReplay (Maybe (StdGen, Int)) deriving (Typeable) -- | Size of the biggest test cases newtype QuickCheckMaxSize = QuickCheckMaxSize Int deriving (Num, Ord, Eq, Real, Enum, Integral, Typeable) -- | Maximum number of of discarded tests per successful test before giving up. newtype QuickCheckMaxRatio = QuickCheckMaxRatio Int deriving (Num, Ord, Eq, Real, Enum, Integral, Typeable) instance IsOption QuickCheckTests where defaultValue = 100 parseValue = fmap QuickCheckTests . safeRead optionName = return "quickcheck-tests" optionHelp = return "Number of test cases for QuickCheck to generate" instance IsOption QuickCheckReplay where defaultValue = QuickCheckReplay Nothing parseValue v = QuickCheckReplay . Just <$> replay -- Reads a replay token in the form "{size} {seed}" where replay = (,) <$> safeRead (intercalate " " seed) <*> safeRead (concat size) (size, seed) = splitAt 1 $ words v optionName = return "quickcheck-replay" optionHelp = return "Replay token to use for replaying a previous test run" instance IsOption QuickCheckMaxSize where defaultValue = fromIntegral $ QC.maxSize QC.stdArgs parseValue = fmap QuickCheckMaxSize . safeRead optionName = return "quickcheck-max-size" optionHelp = return "Size of the biggest test cases quickcheck generates" instance IsOption QuickCheckMaxRatio where defaultValue = fromIntegral $ QC.maxDiscardRatio QC.stdArgs parseValue = fmap QuickCheckMaxRatio . safeRead optionName = return "quickcheck-max-ratio" optionHelp = return "Maximum number of discared tests per successful test before giving up" instance IsTest QC where testOptions = return [ Option (Proxy :: Proxy QuickCheckTests) , Option (Proxy :: Proxy QuickCheckReplay) , Option (Proxy :: Proxy QuickCheckMaxSize) , Option (Proxy :: Proxy QuickCheckMaxRatio) ] run opts (QC prop) yieldProgress = do let QuickCheckTests nTests = lookupOption opts QuickCheckReplay replay = lookupOption opts QuickCheckMaxSize maxSize = lookupOption opts QuickCheckMaxRatio maxRatio = lookupOption opts args = QC.stdArgs { QC.chatty = False, QC.maxSuccess = nTests, QC.maxSize = maxSize, QC.replay = replay, QC.maxDiscardRatio = maxRatio} -- TODO yield progress r <- QC.quickCheckWithResult args prop return $ Result { resultSuccessful = successful r , resultDescription = if unexpected r then QC.output r ++ reproduceMsg r else QC.output r } successful :: QC.Result -> Bool successful r = case r of QC.Success {} -> True _ -> False unexpected :: QC.Result -> Bool unexpected r = case r of QC.Failure {} -> True QC.NoExpectedFailure {} -> True _ -> False reproduceMsg :: QC.Result -> String reproduceMsg r = printf "Use --quickcheck-replay '%d %s' to reproduce." (QC.usedSize r) (show $ QC.usedSeed r)