quickcheck-simple-0.1.0.2/0000755000000000000000000000000013132307055013436 5ustar0000000000000000quickcheck-simple-0.1.0.2/LICENSE0000644000000000000000000000275613132307055014455 0ustar0000000000000000Copyright (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. quickcheck-simple-0.1.0.2/Setup.hs0000644000000000000000000000005613132307055015073 0ustar0000000000000000import Distribution.Simple main = defaultMain quickcheck-simple-0.1.0.2/quickcheck-simple.cabal0000644000000000000000000000250413132307055020024 0ustar0000000000000000name: quickcheck-simple version: 0.1.0.2 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-2017 Kei Hibino category: Testing build-type: Simple extra-source-files: example/e0.hs cabal-version: >=1.10 tested-with: GHC == 8.2.1 , GHC == 8.0.1, GHC == 8.0.2 , GHC == 7.10.1, GHC == 7.10.2, GHC == 7.10.3 , GHC == 7.8.1, GHC == 7.8.2, GHC == 7.8.3, GHC == 7.8.4 , GHC == 7.6.1, GHC == 7.6.2, GHC == 7.6.3 , GHC == 7.4.1, GHC == 7.4.2 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 quickcheck-simple-0.1.0.2/src/0000755000000000000000000000000013132307055014225 5ustar0000000000000000quickcheck-simple-0.1.0.2/src/Test/0000755000000000000000000000000013132307055015144 5ustar0000000000000000quickcheck-simple-0.1.0.2/src/Test/QuickCheck/0000755000000000000000000000000013132307055017156 5ustar0000000000000000quickcheck-simple-0.1.0.2/src/Test/QuickCheck/Simple.hs0000644000000000000000000000665413132307055020756 0ustar0000000000000000-- | -- 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', boolTest , eqTest', eqTest , qcTest , Test, TestError (..) , runTest , defaultMain', defaultMain ) where import Control.Applicative ((<$>)) import Control.Monad (when, unless) import Data.Maybe (fromMaybe, 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 (Maybe String) Bool | QuickCheck QC.Property -- | Property with label string type Test = (String, Property) -- | Test error result. data TestError = BFalse (Maybe String) | QCError Result deriving Show mkBoolTest :: String -> Maybe String -> Bool -> Test mkBoolTest n m = ((,) n) . Bool m -- | 'Bool' specialized property with message for False case boolTest' :: String -> String -> Bool -> Test boolTest' n m = mkBoolTest n (Just m) -- | 'Bool' specialized property boolTest :: String -> Bool -> Test boolTest n = mkBoolTest n Nothing -- | 'Eq' specialized property with explicit passing eqTest' :: (a -> a -> Bool) -> (a -> String) -> String -> a -> a -> Test eqTest' eq show' n x y = boolTest' n msg $ x `eq` y where msg = unlines [show' x, "** NOT EQUALS **", show' y] -- | 'Eq' specialized property eqTest :: (Eq a, Show a) => String -> a -> a -> Test eqTest = eqTest' (==) show -- | QuickCheck 'Testable' property qcTest :: Testable prop => String -> prop -> Test qcTest n = ((,) n) . QuickCheck . label n putErrorLn :: String -> IO () putErrorLn = putStrLn . ("*** " <>) runBool :: String -> Maybe String -> Bool -> IO (Maybe TestError) runBool n m = d where d True = do putStrLn $ "+++ OK, success (" <> n <> ")" return Nothing d False = do putErrorLn $ "Failed! (" <> n <> ")" return . Just $ BFalse m 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 m b) = runBool n m 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 showTestError :: TestError -> String showTestError = d where d (BFalse m) = fromMaybe "" m d (QCError r) = show r -- | 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 $ showTestError 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 quickcheck-simple-0.1.0.2/example/0000755000000000000000000000000013132307055015071 5ustar0000000000000000quickcheck-simple-0.1.0.2/example/e0.hs0000644000000000000000000000130413132307055015727 0ustar0000000000000000 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" "Hello =/= Hellox" prop_stringHelloBad , eqTest "stringHelloBad" stringHello "Hellox" , qcTest "intComBad" prop_intComBad , qcTest "intCom2Bad" prop_intCom2Bad ] main :: IO () main = defaultMain' True tests