tasty-smallcheck-0.8.1/Test/0000755000000000000000000000000012457221174014102 5ustar0000000000000000tasty-smallcheck-0.8.1/Test/Tasty/0000755000000000000000000000000012622727256015214 5ustar0000000000000000tasty-smallcheck-0.8.1/Test/Tasty/SmallCheck.hs0000644000000000000000000000535212622727256017563 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 qualified Test.SmallCheck.Drivers as SC import Test.SmallCheck hiding (smallCheck) -- for re-export import Test.SmallCheck.Drivers import Control.Exception import Data.Typeable import Data.Proxy import Data.IORef 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" instance IsTest (SC.Property IO) where testOptions = return [Option (Proxy :: Proxy SmallCheckDepth)] run opts prop yieldProgress = do let SmallCheckDepth depth = 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')) -- 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 -> testFailed $ show (e :: SomeException) Right Nothing -> testPassed desc Right (Just f) -> testFailed $ ppFailure f -- 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.1/LICENSE0000644000000000000000000000204312457221174014167 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.1/Setup.hs0000644000000000000000000000005612457221174014620 0ustar0000000000000000import Distribution.Simple main = defaultMain tasty-smallcheck-0.8.1/tasty-smallcheck.cabal0000644000000000000000000000176512625637114017432 0ustar0000000000000000Name: tasty-smallcheck Version: 0.8.1 Cabal-Version: >= 1.6 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: http://documentup.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 && < 5, async, tagged tasty-smallcheck-0.8.1/CHANGELOG.md0000644000000000000000000000065412625637101014777 0ustar0000000000000000 Changes ======= 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`