chell-quickcheck 0.2.5 → 0.2.5.1
raw patch · 3 files changed
+124/−116 lines, 3 filesdep ~QuickCheckPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: QuickCheck
API changes (from Hackage documentation)
Files
- Test/Chell/QuickCheck.hs +118/−0
- chell-quickcheck.cabal +6/−7
- lib/Test/Chell/QuickCheck.hs +0/−109
+ Test/Chell/QuickCheck.hs view
@@ -0,0 +1,118 @@+{-# LANGUAGE CPP #-}++module Test.Chell.QuickCheck+ ( property+ ) where++import Data.Monoid (mempty)+import System.Random (mkStdGen)++import qualified Test.Chell as Chell+import qualified Test.QuickCheck as QuickCheck+import qualified Test.QuickCheck.Gen as Gen+#if MIN_VERSION_QuickCheck(2,7,0)+import Test.QuickCheck.Property (unProperty)+import qualified Test.QuickCheck.Random as QCRandom+#endif+import qualified Test.QuickCheck.State as State+import qualified Test.QuickCheck.Test as Test+import qualified Test.QuickCheck.Text as Text++-- | Convert a QuickCheck property to a Chell 'Chell.Test'.+--+-- @+--import Test.Chell+--import Test.Chell.QuickCheck+--import Test.QuickCheck hiding (property)+--+--test_NullLength :: Test+--test_NullLength = property \"null-length\"+-- (\xs -> not (null xs) ==> length xs > 0)+-- @+property :: QuickCheck.Testable prop => String -> prop -> Chell.Test+#if MIN_VERSION_QuickCheck(2,6,0)+property name prop = Chell.test name $ \opts ->+ Text.withNullTerminal $ \term -> do+#else+property name prop = Chell.test name $ \opts -> do+ term <- Text.newNullTerminal+#endif+ + let seed = Chell.testOptionSeed opts+ + let args = QuickCheck.stdArgs+ let state = State.MkState+ { State.terminal = term+ , State.maxSuccessTests = QuickCheck.maxSuccess args+#if MIN_VERSION_QuickCheck(2,10,1)+ , State.maxDiscardedRatio = QuickCheck.maxDiscardRatio args+#else+ , State.maxDiscardedTests = maxDiscardedTests args prop+#endif++ , State.computeSize = computeSize (QuickCheck.maxSize args) (QuickCheck.maxSuccess args)+ , State.numSuccessTests = 0+ , State.numDiscardedTests = 0+ , State.collected = []+ , State.expectedFailure = False++#if MIN_VERSION_QuickCheck(2,7,0)+ , State.randomSeed = QCRandom.mkQCGen seed+#else+ , State.randomSeed = mkStdGen seed+#endif+ , State.numSuccessShrinks = 0+ , State.numTryShrinks = 0+#if MIN_VERSION_QuickCheck(2,5,0)+ , State.numTotTryShrinks = 0+#endif+#if MIN_VERSION_QuickCheck(2,5,1)+ , State.numRecentlyDiscardedTests = 0+#endif+#if MIN_VERSION_QuickCheck(2,8,0)+ , State.labels = mempty+#endif+#if MIN_VERSION_QuickCheck(2,10,0)+ , State.numTotMaxShrinks = QuickCheck.maxShrinks args+#endif+ }+ +#if MIN_VERSION_QuickCheck(2,7,0)+ let genProp = unProperty (QuickCheck.property prop)+#else+ let genProp = QuickCheck.property prop+#endif+ result <- Test.test state (Gen.unGen genProp)+ let output = Test.output result+ let notes = [("seed", show seed)]+ let failure = Chell.failure { Chell.failureMessage = output }+ return $ case result of+ Test.Success{} -> Chell.TestPassed notes+ Test.Failure{} -> Chell.TestFailed notes [failure]+ Test.GaveUp{} -> Chell.TestAborted notes output+ Test.NoExpectedFailure{} -> Chell.TestFailed notes [failure]++-- copied from quickcheck-2.4.1.1/src/Test/QuickCheck/Test.hs+computeSize :: Int -> Int -> Int -> Int -> Int+computeSize maxSize maxSuccess n d+ -- e.g. with maxSuccess = 250, maxSize = 100, goes like this:+ -- 0, 1, 2, ..., 99, 0, 1, 2, ..., 99, 0, 2, 4, ..., 98.+ | n `roundTo` maxSize + maxSize <= maxSuccess ||+ n >= maxSuccess ||+ maxSuccess `mod` maxSize == 0 = n `mod` maxSize + d `div` 10+ | otherwise =+ (n `mod` maxSize) * maxSize `div` (maxSuccess `mod` maxSize) + d `div` 10++roundTo :: Int -> Int -> Int+roundTo n m = (n `div` m) * m++maxDiscardedTests :: QuickCheck.Testable prop => QuickCheck.Args -> prop -> Int+#if MIN_VERSION_QuickCheck(2,9,0)+maxDiscardedTests args _ = QuickCheck.maxDiscardRatio args+#elif MIN_VERSION_QuickCheck(2,5,0)+maxDiscardedTests args p = if QuickCheck.exhaustive p+ then QuickCheck.maxDiscardRatio args+ else QuickCheck.maxDiscardRatio args * QuickCheck.maxSuccess args+#else+maxDiscardedTests args _ = QuickCheck.maxDiscard args+#endif
chell-quickcheck.cabal view
@@ -1,5 +1,5 @@ name: chell-quickcheck-version: 0.2.5+version: 0.2.5.1 license: MIT license-file: license.txt author: John Millikin <john@john-millikin.com>@@ -14,21 +14,20 @@ source-repository head type: git- location: https://john-millikin.com/code/chell-quickcheck/+ location: https://john-millikin.com/code/chell/ source-repository this type: git- location: https://john-millikin.com/code/chell-quickcheck/- tag: chell-quickcheck_0.2.5+ location: https://john-millikin.com/code/chell/+ tag: chell-quickcheck_0.2.5.1 library- hs-source-dirs: lib- ghc-options: -Wall -O2+ ghc-options: -Wall build-depends: base >= 4.0 && < 5.0 , chell >= 0.3 && < 0.5- , QuickCheck >= 2.3 && < 2.9+ , QuickCheck >= 2.3 && < 2.11 , random exposed-modules:
− lib/Test/Chell/QuickCheck.hs
@@ -1,109 +0,0 @@-{-# LANGUAGE CPP #-}--module Test.Chell.QuickCheck- ( property- ) where--import Data.Monoid (mempty)-import System.Random (mkStdGen)--import qualified Test.Chell as Chell-import qualified Test.QuickCheck as QuickCheck-import qualified Test.QuickCheck.Gen as Gen-#if MIN_VERSION_QuickCheck(2,7,0)-import Test.QuickCheck.Property (unProperty)-import qualified Test.QuickCheck.Random as QCRandom-#endif-import qualified Test.QuickCheck.State as State-import qualified Test.QuickCheck.Test as Test-import qualified Test.QuickCheck.Text as Text---- | Convert a QuickCheck property to a Chell 'Chell.Test'.------ @---import Test.Chell---import Test.Chell.QuickCheck---import Test.QuickCheck hiding (property)------test_NullLength :: Test---test_NullLength = property \"null-length\"--- (\xs -> not (null xs) ==> length xs > 0)--- @-property :: QuickCheck.Testable prop => String -> prop -> Chell.Test-#if MIN_VERSION_QuickCheck(2,6,0)-property name prop = Chell.test name $ \opts ->- Text.withNullTerminal $ \term -> do-#else-property name prop = Chell.test name $ \opts -> do- term <- Text.newNullTerminal-#endif- - let seed = Chell.testOptionSeed opts- - let args = QuickCheck.stdArgs- let state = State.MkState- { State.terminal = term- , State.maxSuccessTests = QuickCheck.maxSuccess args- , State.maxDiscardedTests = maxDiscardedTests args prop-- , State.computeSize = computeSize (QuickCheck.maxSize args) (QuickCheck.maxSuccess args)- , State.numSuccessTests = 0- , State.numDiscardedTests = 0- , State.collected = []- , State.expectedFailure = False--#if MIN_VERSION_QuickCheck(2,7,0)- , State.randomSeed = QCRandom.mkQCGen seed-#else- , State.randomSeed = mkStdGen seed-#endif- , State.numSuccessShrinks = 0- , State.numTryShrinks = 0-#if MIN_VERSION_QuickCheck(2,5,0)- , State.numTotTryShrinks = 0-#endif-#if MIN_VERSION_QuickCheck(2,5,1)- , State.numRecentlyDiscardedTests = 0-#endif-#if MIN_VERSION_QuickCheck(2,8,0)- , State.labels = mempty-#endif- }- -#if MIN_VERSION_QuickCheck(2,7,0)- let genProp = unProperty (QuickCheck.property prop)-#else- let genProp = QuickCheck.property prop-#endif- result <- Test.test state (Gen.unGen genProp)- let output = Test.output result- let notes = [("seed", show seed)]- let failure = Chell.failure { Chell.failureMessage = output }- return $ case result of- Test.Success{} -> Chell.TestPassed notes- Test.Failure{} -> Chell.TestFailed notes [failure]- Test.GaveUp{} -> Chell.TestAborted notes output- Test.NoExpectedFailure{} -> Chell.TestFailed notes [failure]---- copied from quickcheck-2.4.1.1/src/Test/QuickCheck/Test.hs-computeSize :: Int -> Int -> Int -> Int -> Int-computeSize maxSize maxSuccess n d- -- e.g. with maxSuccess = 250, maxSize = 100, goes like this:- -- 0, 1, 2, ..., 99, 0, 1, 2, ..., 99, 0, 2, 4, ..., 98.- | n `roundTo` maxSize + maxSize <= maxSuccess ||- n >= maxSuccess ||- maxSuccess `mod` maxSize == 0 = n `mod` maxSize + d `div` 10- | otherwise =- (n `mod` maxSize) * maxSize `div` (maxSuccess `mod` maxSize) + d `div` 10--roundTo :: Int -> Int -> Int-roundTo n m = (n `div` m) * m--maxDiscardedTests :: QuickCheck.Testable prop => QuickCheck.Args -> prop -> Int-#if MIN_VERSION_QuickCheck(2,5,0)-maxDiscardedTests args p = if QuickCheck.exhaustive p- then QuickCheck.maxDiscardRatio args- else QuickCheck.maxDiscardRatio args * QuickCheck.maxSuccess args-#else-maxDiscardedTests args _ = QuickCheck.maxDiscard args-#endif