test-framework-smallcheck (empty) → 0.1
raw patch · 4 files changed
+126/−0 lines, 4 filesdep +basedep +smallcheckdep +test-frameworksetup-changed
Dependencies added: base, smallcheck, test-framework
Files
- LICENSE +28/−0
- Setup.hs +2/−0
- Test/Framework/Providers/SmallCheck.hs +63/−0
- test-framework-smallcheck.cabal +33/−0
+ LICENSE view
@@ -0,0 +1,28 @@+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:++1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.++3. Neither the name of the author nor the names of his contributors+ may be used to endorse or promote products derived from this software+ without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Test/Framework/Providers/SmallCheck.hs view
@@ -0,0 +1,63 @@+--------------------------------------------------------------------+-- |+-- Module : Test.Framework.Providers.SmallCheck+-- Copyright : (c) Roman Cheplyaka+-- License : BSD3+-- Maintainer: Roman Cheplyaka <roma@ro-che.info>+--+-- This module allows to use SmallCheck properties in test-framework.+--------------------------------------------------------------------+{-# LANGUAGE MultiParamTypeClasses #-}+module Test.Framework.Providers.SmallCheck+ ( testProperty+ , withDepth+ ) where++import Test.Framework.Providers.API+import qualified Test.SmallCheck.Property as SC+import Data.Maybe+import Data.List+import Data.Monoid++-- | Create a 'Test' for a SmallCheck 'SC.Testable' property+testProperty :: SC.Testable a => TestName -> a -> Test+testProperty name prop = Test name $ SC.property prop++-- | Change the default maximum test depth for a given 'Test'.+--+-- This is a simple wrapper around 'plusTestOptions'.+withDepth :: SC.Depth -> Test -> Test+withDepth d = plusTestOptions mempty { topt_maximum_test_depth = Just d }++data Result+ = Timeout+ | Pass+ | Fail [String]++instance Show Result where+ show Timeout = "Timed out"+ show Pass = "OK"+ show (Fail s) =+ intercalate "\n" $ "Failed with arguments: " : s++instance TestResultlike Int Result where+ testSucceeded Pass = True+ testSucceeded _ = False++instance Testlike Int Result SC.Property where+ testTypeName _ = "Properties"++ runTest topts prop = runImprovingIO $ do+ let timeout = unK $ topt_timeout topts+ depth = unK $ topt_maximum_test_depth topts+ mb_result <- maybeTimeoutImprovingIO timeout $+ runSmallCheck prop depth+ return $ fromMaybe Timeout mb_result++runSmallCheck :: SC.Property -> SC.Depth -> ImprovingIO Int f Result+runSmallCheck prop depth = foldr go (const $ return Pass) (SC.test prop depth) 1+ where+ go test rest n =+ if SC.resultIsOk (SC.result test)+ then yieldImprovement n >> (rest $! n+1)+ else return $ Fail $ SC.arguments test
+ test-framework-smallcheck.cabal view
@@ -0,0 +1,33 @@+Name: test-framework-smallcheck+Version: 0.1+Cabal-Version: >= 1.6+Category: Testing+Synopsis: SmallCheck support for the test-framework package.+License: BSD3+License-File: LICENSE+Author: Roman Cheplyaka <roma@ro-che.info>+Maintainer: Roman Cheplyaka <roma@ro-che.info>+Homepage: https://github.com/feuerbach/smallcheck+Bug-reports: https://github.com/feuerbach/smallcheck/issues+Build-Type: Simple++Synopsis: Support for SmallCheck tests in test-framework+Description: Support for SmallCheck tests in test-framework++Source-repository head+ type: git+ location: git://github.com/feuerbach/smallcheck.git+ subdir: test-framework-smallcheck++Source-repository this+ type: git+ location: git://github.com/feuerbach/smallcheck.git+ tag: testframework-v0.1+ subdir: test-framework-smallcheck++Library+ Exposed-Modules: Test.Framework.Providers.SmallCheck++ Build-Depends: test-framework >= 0.4.2.0 && < 0.5,+ smallcheck >= 0.6,+ base >= 4 && < 5