tasty-smallcheck-0.8.2/Test/0000755000000000000000000000000012457221174014103 5ustar0000000000000000tasty-smallcheck-0.8.2/Test/Tasty/0000755000000000000000000000000013767077260015221 5ustar0000000000000000tasty-smallcheck-0.8.2/Test/Tasty/SmallCheck.hs0000644000000000000000000000717713767077260017577 0ustar0000000000000000-- | This module allows to use SmallCheck properties in tasty. {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, TypeOperators, DeriveDataTypeable, TypeFamilies, GeneralizedNewtypeDeriving #-} module Test.Tasty.SmallCheck ( testProperty , SmallCheckDepth(..) , module Test.SmallCheck ) where import Test.Tasty.Providers import Test.Tasty.Options import qualified Test.SmallCheck as SC import Test.SmallCheck hiding (smallCheck) -- for re-export import Test.SmallCheck.Drivers as SC import Control.Exception import Control.Monad (when) import Data.Typeable import Data.IORef import Options.Applicative (metavar) import Text.Printf -- | Create a 'Test' for a SmallCheck 'SC.Testable' property testProperty :: SC.Testable IO a => TestName -> a -> TestTree testProperty name prop = singleTest name $ (SC.test prop :: SC.Property IO) -- | The \"depth\" parameter for SmallCheck newtype SmallCheckDepth = SmallCheckDepth Int deriving (Num, Ord, Eq, Real, Enum, Integral, Typeable) instance IsOption SmallCheckDepth where defaultValue = 5 parseValue = fmap SmallCheckDepth . safeRead optionName = return "smallcheck-depth" optionHelp = return "Depth to use for smallcheck tests" optionCLParser = mkOptionCLParser $ metavar "NUMBER" -- | The maximum number of test cases to generate. Can be used as an -- alternative to setting 'SmallCheckDepth'. newtype SmallCheckMaxCount = SmallCheckMaxCount Int deriving (Num, Ord, Eq, Real, Enum, Integral, Typeable) instance IsOption SmallCheckMaxCount where defaultValue = SmallCheckMaxCount maxBound -- disable by default parseValue = fmap SmallCheckMaxCount . safeRead optionName = return "smallcheck-max-count" optionHelp = return "Maximum smallcheck test count" optionCLParser = mkOptionCLParser $ metavar "NUMBER" instance IsTest (SC.Property IO) where testOptions = return [ Option (Proxy :: Proxy SmallCheckDepth) , Option (Proxy :: Proxy SmallCheckMaxCount) ] run opts prop yieldProgress = do let SmallCheckDepth depth = lookupOption opts SmallCheckMaxCount maxCount = lookupOption opts counter <- newIORef (0 :: Int, 0 :: Int) let hook quality = do let inc (total, bad) = case quality of GoodTest -> ((,) $! total + 1) bad BadTest -> ((,) $! total + 1) $! bad + 1 count <- myAtomicModifyIORef' counter (\c -> let c' = inc c in (c', fst c')) when (count >= maxCount) $ throwIO Finish -- submit progress data to tasty yieldProgress $ Progress { progressText = show count , progressPercent = 0 -- we don't know the total number of tests } -- small check does not catch exceptions on its own, so lets do it scResult <- try $ smallCheckWithHook depth hook prop (total, bad) <- readIORef counter let desc | bad == 0 = printf "%d tests completed" total | otherwise = printf "%d tests completed (but %d did not meet the condition)" total bad return $ case scResult of Left e | Just Finish <- fromException e -> testPassed desc | otherwise -> testFailed $ show e Right Nothing -> testPassed desc Right (Just f) -> testFailed $ ppFailure f data Finish = Finish deriving (Eq, Show) instance Exception Finish -- Copied from base to stay compatible with GHC 7.4. myAtomicModifyIORef' :: IORef a -> (a -> (a,b)) -> IO b myAtomicModifyIORef' ref f = do b <- atomicModifyIORef ref (\x -> let (a, b) = f x in (a, a `seq` b)) b `seq` return b tasty-smallcheck-0.8.2/LICENSE0000644000000000000000000000204312457221174014170 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-smallcheck-0.8.2/Setup.hs0000644000000000000000000000005612457221174014621 0ustar0000000000000000import Distribution.Simple main = defaultMain tasty-smallcheck-0.8.2/tasty-smallcheck.cabal0000644000000000000000000000216713767164522017436 0ustar0000000000000000Name: tasty-smallcheck Version: 0.8.2 Cabal-Version: >= 1.10 Category: Testing Synopsis: SmallCheck support for the Tasty test framework. Description: SmallCheck support for the Tasty test framework. License: MIT License-File: LICENSE Author: Roman Cheplyaka Maintainer: Roman Cheplyaka Homepage: https://github.com/feuerbach/tasty Bug-reports: https://github.com/feuerbach/tasty/issues Build-Type: Simple extra-source-files: CHANGELOG.md Source-repository head type: git location: git://github.com/feuerbach/tasty.git subdir: smallcheck Library Exposed-Modules: Test.Tasty.SmallCheck Build-Depends: tasty >= 0.8, smallcheck >= 1.0, base >= 4.7 && < 5, tagged, optparse-applicative ghc-options: -Wall -fno-warn-orphans default-language: Haskell2010 default-extensions: CPP tasty-smallcheck-0.8.2/CHANGELOG.md0000644000000000000000000000106113767164513015003 0ustar0000000000000000 Changes ======= Version 0.8.2 ------------- Add a `--smallcheck-max-count` option, which limits the number of test cases for a given property test Version 0.8.1 ------------- Intercept exceptions thrown by the property, adhering to the new tasty API contract. Version 0.8.0.1 --------------- Split the changelog out of the main tasty changelog Version 0.8 ----------- Update to tasty-0.8 Version 0.2 ----------- * Add an `execRunner` function * Make `Runner` return `IO Bool` * Re-export useful bits of `Test.SmallCheck` from `Test.Tasty.SmallCheck`