packages feed

quickcheck-simple (empty) → 0.0.1.0

raw patch · 5 files changed

+192/−0 lines, 5 filesdep +QuickCheckdep +basesetup-changed

Dependencies added: QuickCheck, base

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Kei Hibino++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * 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.++    * Neither the name of Kei Hibino nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"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 COPYRIGHT+OWNER 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
+ example/e0.hs view
@@ -0,0 +1,31 @@++import Test.QuickCheck.Simple++int1 :: Int+int1 = 1++stringHello :: String+stringHello = "Hello"++prop_int1 :: Bool+prop_int1 = int1 == 1++prop_stringHelloBad :: Bool+prop_stringHelloBad = stringHello == "Hellox"++prop_intComBad :: Int -> Int -> Bool+prop_intComBad i j = i + j == j + i + 1++prop_intCom2Bad :: Int -> Int -> Bool+prop_intCom2Bad i j = i + j == j + i + 2++tests :: [Test]+tests =+  [ boolTest "int1"             prop_int1+  , boolTest "stringHelloBad"   prop_stringHelloBad+  , qcTest   "intComBad"        prop_intComBad+  , qcTest   "intCom2Bad"       prop_intCom2Bad+  ]++main :: IO ()+main = defaultMain' True tests
+ quickcheck-simple.cabal view
@@ -0,0 +1,29 @@+name:                quickcheck-simple+version:             0.0.1.0+synopsis:            Test properties and default-mains for QuickCheck+description:         This package contains definitions of test properties and default-mains+                     using QuickCheck library.+license:             BSD3+license-file:        LICENSE+author:              Kei Hibino+maintainer:          ex8k.hibino@gmail.com+copyright:           Copyright (c) 2015 Kei Hibino+category:            Testing+build-type:          Simple+extra-source-files:  example/e0.hs+cabal-version:       >=1.10++library+  exposed-modules:     Test.QuickCheck.Simple+  build-depends:       base <5, QuickCheck >=2+  hs-source-dirs:      src+  ghc-options:         -Wall+  default-language:    Haskell2010++source-repository head+  type:       git+  location:   https://github.com/khibino/haskell-quickcheck-simple++source-repository head+  type:       mercurial+  location:   https://bitbucket.org/khibino/haskell-quickcheck-simple
+ src/Test/QuickCheck/Simple.hs view
@@ -0,0 +1,100 @@+-- |+-- Module      : Test.QuickCheck.Simple+-- Copyright   : 2015 Kei Hibino+-- License     : BSD3+--+-- Maintainer  : ex8k.hibino@gmail.com+-- Stability   : experimental+-- Portability : unknown+--+-- This module contains definitions of test properties and default-mains+-- using QuickCheck library.+module Test.QuickCheck.Simple+       ( Property (..), boolTest, qcTest+       , Test, TestError (..)+       , runTest+       , defaultMain', defaultMain+       ) where++import Control.Applicative ((<$>))+import Control.Monad (when, unless)+import Data.Maybe (catMaybes)+import Data.Monoid ((<>))+import Test.QuickCheck+  (Testable, Result (..), quickCheckResult, label)+import qualified Test.QuickCheck as QC+++-- | Property type. 'Bool' or 'Testable' of QuickCheck.+data Property+  = Bool Bool+  | QuickCheck QC.Property++-- | Property with label string+type Test = (String, Property)++-- | Test error result.+data TestError+  = BFalse+  | QCError Result+  deriving Show++-- | 'Bool' specialized property+boolTest :: String+         -> Bool+         -> Test+boolTest n = ((,) n) . Bool++-- | QuickCheck 'Testable' property+qcTest :: Testable prop+       => String+       -> prop+       -> Test+qcTest n = ((,) n) . QuickCheck . label n++putErrorLn :: String -> IO ()+putErrorLn = putStrLn . ("*** " <>)++runBool :: String -> Bool -> IO (Maybe TestError)+runBool n = d  where+  d True  =  do+    putStrLn $ "+++ OK, success (" <> n <> ")"+    return   Nothing+  d False =  do+    putErrorLn $ "Failed! (" <> n <> ")"+    return . Just $ BFalse++runQcProp :: String -> QC.Property -> IO (Maybe TestError)+runQcProp n p = err =<< quickCheckResult p  where+  err (Success {})  =+    return   Nothing+  err x             =  do+    putErrorLn $ "  label: " <> n+    return . Just $ QCError x++runProp :: String -> Property -> IO (Maybe TestError)+runProp n = d  where+  d (Bool b)         =  runBool n b+  d (QuickCheck p)   =  runQcProp n p++-- | Run a single test suite.+runTest :: Test+        -> IO (Maybe TestError)+runTest = uncurry runProp++runPropL :: String -> Property -> IO (Maybe (String, TestError))+runPropL n p = do+  me <- runProp n p+  return $ fmap ((,) n) me++-- | Default main to run test suites.+defaultMain' :: Bool -> [Test] -> IO ()+defaultMain' verbose xs = do+  es <- catMaybes <$> mapM (uncurry runPropL) xs+  let rlines m r = (m <> ":") : [ "  " <> x | x <- lines $ show r ]+  when verbose $ mapM_ (\(m, r) -> mapM_ putStrLn $ rlines m r) es+  unless (null es) $ fail "Some failures are found."++-- | Not verbose version of 'defaultMain''.+defaultMain :: [Test] -> IO ()+defaultMain = defaultMain' False