packages feed

quickcheck-simple 0.0.1.0 → 0.1.0.0

raw patch · 3 files changed

+40/−12 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Test.QuickCheck.Simple: boolTest' :: String -> String -> Bool -> Test
+ Test.QuickCheck.Simple: eqTest :: (Eq a, Show a) => String -> a -> a -> Test
+ Test.QuickCheck.Simple: eqTest' :: (a -> a -> Bool) -> (a -> String) -> String -> a -> a -> Test
- Test.QuickCheck.Simple: BFalse :: TestError
+ Test.QuickCheck.Simple: BFalse :: (Maybe String) -> TestError
- Test.QuickCheck.Simple: Bool :: Bool -> Property
+ Test.QuickCheck.Simple: Bool :: (Maybe String) -> Bool -> Property

Files

example/e0.hs view
@@ -22,7 +22,8 @@ tests :: [Test] tests =   [ boolTest "int1"             prop_int1-  , boolTest "stringHelloBad"   prop_stringHelloBad+  , boolTest' "stringHelloBad"  "Hello =/= Hellox" prop_stringHelloBad+  , eqTest    "stringHelloBad"  stringHello "Hellox"   , qcTest   "intComBad"        prop_intComBad   , qcTest   "intCom2Bad"       prop_intCom2Bad   ]
quickcheck-simple.cabal view
@@ -1,5 +1,5 @@ name:                quickcheck-simple-version:             0.0.1.0+version:             0.1.0.0 synopsis:            Test properties and default-mains for QuickCheck description:         This package contains definitions of test properties and default-mains                      using QuickCheck library.
src/Test/QuickCheck/Simple.hs view
@@ -10,7 +10,10 @@ -- This module contains definitions of test properties and default-mains -- using QuickCheck library. module Test.QuickCheck.Simple-       ( Property (..), boolTest, qcTest+       ( Property (..)+       , boolTest', boolTest+       , eqTest', eqTest+       , qcTest        , Test, TestError (..)        , runTest        , defaultMain', defaultMain@@ -18,7 +21,7 @@  import Control.Applicative ((<$>)) import Control.Monad (when, unless)-import Data.Maybe (catMaybes)+import Data.Maybe (fromMaybe, catMaybes) import Data.Monoid ((<>)) import Test.QuickCheck   (Testable, Result (..), quickCheckResult, label)@@ -27,7 +30,7 @@  -- | Property type. 'Bool' or 'Testable' of QuickCheck. data Property-  = Bool Bool+  = Bool (Maybe String) Bool   | QuickCheck QC.Property  -- | Property with label string@@ -35,16 +38,35 @@  -- | Test error result. data TestError-  = BFalse+  = 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 = ((,) n) . Bool+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@@ -55,14 +77,14 @@ putErrorLn :: String -> IO () putErrorLn = putStrLn . ("*** " <>) -runBool :: String -> Bool -> IO (Maybe TestError)-runBool n = d  where+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+    return . Just $ BFalse m  runQcProp :: String -> QC.Property -> IO (Maybe TestError) runQcProp n p = err =<< quickCheckResult p  where@@ -74,7 +96,7 @@  runProp :: String -> Property -> IO (Maybe TestError) runProp n = d  where-  d (Bool b)         =  runBool n b+  d (Bool m b)       =  runBool n m b   d (QuickCheck p)   =  runQcProp n p  -- | Run a single test suite.@@ -87,11 +109,16 @@   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 $ show r ]+  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."