tasty-smallcheck 0.8.0.1 → 0.8.2
raw patch · 3 files changed
Files
- CHANGELOG.md +12/−0
- Test/Tasty/SmallCheck.hs +37/−7
- tasty-smallcheck.cabal +10/−7
CHANGELOG.md view
@@ -2,6 +2,18 @@ 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 ---------------
Test/Tasty/SmallCheck.hs view
@@ -11,12 +11,13 @@ 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 Test.SmallCheck.Drivers as SC+import Control.Exception+import Control.Monad (when) import Data.Typeable-import Data.Proxy import Data.IORef+import Options.Applicative (metavar) import Text.Printf -- | Create a 'Test' for a SmallCheck 'SC.Testable' property@@ -32,13 +33,30 @@ 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)]+ 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) @@ -52,13 +70,16 @@ 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 } - scResult <- smallCheckWithHook depth hook prop+ -- small check does not catch exceptions on its own, so lets do it+ scResult <- try $ smallCheckWithHook depth hook prop (total, bad) <- readIORef counter let@@ -70,8 +91,17 @@ return $ case scResult of- Nothing -> testPassed desc- Just f -> testFailed $ ppFailure f+ 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
tasty-smallcheck.cabal view
@@ -1,14 +1,14 @@ Name: tasty-smallcheck-Version: 0.8.0.1-Cabal-Version: >= 1.6+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: BSD3+License: MIT License-File: LICENSE Author: Roman Cheplyaka <roma@ro-che.info> Maintainer: Roman Cheplyaka <roma@ro-che.info>-Homepage: http://documentup.com/feuerbach/tasty+Homepage: https://github.com/feuerbach/tasty Bug-reports: https://github.com/feuerbach/tasty/issues Build-Type: Simple extra-source-files: CHANGELOG.md@@ -23,6 +23,9 @@ Build-Depends: tasty >= 0.8, smallcheck >= 1.0,- base >= 4 && < 5,- async,- tagged+ base >= 4.7 && < 5,+ tagged,+ optparse-applicative+ ghc-options: -Wall -fno-warn-orphans+ default-language: Haskell2010+ default-extensions: CPP