packages feed

tasty-smallcheck (empty) → 0.1

raw patch · 4 files changed

+123/−0 lines, 4 filesdep +asyncdep +basedep +smallchecksetup-changed

Dependencies added: async, base, smallcheck, tagged, tasty

Files

+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Test/Tasty/SmallCheck.hs view
@@ -0,0 +1,80 @@+-- | This module allows to use SmallCheck properties in tasty.+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts,+             TypeOperators, DeriveDataTypeable, TypeFamilies,+             GeneralizedNewtypeDeriving #-}+module Test.Tasty.SmallCheck+  ( testProperty+  , SmallCheckDepth(..)+  ) 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.Drivers+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+          }++    scResult <- 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+        Nothing -> Result { resultSuccessful = True,  resultDescription = desc }+        Just f ->  Result { resultSuccessful = False, resultDescription = 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.cabal view
@@ -0,0 +1,22 @@+Name:                tasty-smallcheck+Version:             0.1+Cabal-Version:       >= 1.6+Category:            Testing+Synopsis:            SmallCheck support for the Tasty test framework.+Description:         SmallCheck support for the Tasty test framework.+License:             BSD3+License-File:        LICENSE+Author:              Roman Cheplyaka <roma@ro-che.info>+Maintainer:          Roman Cheplyaka <roma@ro-che.info>+Homepage:            https://github.com/feuerbach/tasty+Bug-reports:         https://github.com/feuerbach/tasty/issues+Build-Type:          Simple++Library+        Exposed-Modules:        Test.Tasty.SmallCheck++        Build-Depends:          tasty,+                                smallcheck >= 1.0,+                                base >= 4 && < 5,+                                async,+                                tagged