tasty-smallcheck 0.8.1 → 0.8.2
raw patch · 3 files changed
+47/−11 lines, 3 filesdep +optparse-applicativedep −asyncdep ~base
Dependencies added: optparse-applicative
Dependencies removed: async
Dependency ranges changed: base
Files
- CHANGELOG.md +6/−0
- Test/Tasty/SmallCheck.hs +32/−5
- tasty-smallcheck.cabal +9/−6
CHANGELOG.md view
@@ -2,6 +2,12 @@ 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 -------------
Test/Tasty/SmallCheck.hs view
@@ -11,13 +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@@ -33,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) @@ -53,6 +70,8 @@ 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@@ -72,9 +91,17 @@ return $ case scResult of- Left e -> testFailed $ show (e :: SomeException)+ 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,6 +1,6 @@ Name: tasty-smallcheck-Version: 0.8.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.@@ -8,7 +8,7 @@ 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