tasty-quickcheck-0.8.4/Test/0000755000000000000000000000000012457221174014111 5ustar0000000000000000tasty-quickcheck-0.8.4/Test/Tasty/0000755000000000000000000000000012603745744015224 5ustar0000000000000000tasty-quickcheck-0.8.4/tests/0000755000000000000000000000000012457221174014334 5ustar0000000000000000tasty-quickcheck-0.8.4/Test/Tasty/QuickCheck.hs0000644000000000000000000001353712603745744017603 0ustar0000000000000000-- | This module allows to use QuickCheck properties in tasty. {-# LANGUAGE CPP, GeneralizedNewtypeDeriving, DeriveDataTypeable #-} module Test.Tasty.QuickCheck ( testProperty , QuickCheckTests(..) , QuickCheckReplay(..) , QuickCheckShowReplay(..) , QuickCheckMaxSize(..) , QuickCheckMaxRatio(..) , QuickCheckVerbose(..) , module Test.QuickCheck -- * Internal -- | This is exposed for testing purposes and not considered as a part -- of the public API. -- You probably shouldn't need it. , QC(..) ) where import Test.Tasty.Providers import Test.Tasty.Options import qualified Test.QuickCheck as QC import Test.Tasty.Runners (formatMessage) import Test.QuickCheck hiding -- for re-export ( quickCheck , Args(..) , Result , stdArgs , quickCheckWith , quickCheckWithResult , quickCheckResult , verboseCheck , verboseCheckWith , verboseCheckWithResult , verboseCheckResult , verbose ) import Data.Typeable import Data.Proxy import Data.List import Text.Printf import Control.Applicative #if MIN_VERSION_QuickCheck(2,7,0) import Test.QuickCheck.Random (QCGen) #else import System.Random (StdGen) #endif newtype QC = QC QC.Property deriving Typeable -- | Create a 'Test' for a QuickCheck 'QC.Testable' property testProperty :: QC.Testable a => TestName -> a -> TestTree testProperty name prop = singleTest name $ QC $ QC.property prop -- | Number of test cases for QuickCheck to generate newtype QuickCheckTests = QuickCheckTests Int deriving (Num, Ord, Eq, Real, Enum, Integral, Typeable) -- | Replay a previous test using a replay token #if MIN_VERSION_QuickCheck(2,7,0) newtype QuickCheckReplay = QuickCheckReplay (Maybe (QCGen, Int)) #else newtype QuickCheckReplay = QuickCheckReplay (Maybe (StdGen, Int)) #endif deriving (Typeable) -- | If a test case fails unexpectedly, show the replay token newtype QuickCheckShowReplay = QuickCheckShowReplay Bool deriving (Typeable) -- | Size of the biggest test cases newtype QuickCheckMaxSize = QuickCheckMaxSize Int deriving (Num, Ord, Eq, Real, Enum, Integral, Typeable) -- | Maximum number of of discarded tests per successful test before giving up. newtype QuickCheckMaxRatio = QuickCheckMaxRatio Int deriving (Num, Ord, Eq, Real, Enum, Integral, Typeable) -- | Show the test cases that QuickCheck generates newtype QuickCheckVerbose = QuickCheckVerbose Bool deriving (Typeable) instance IsOption QuickCheckTests where defaultValue = 100 parseValue = fmap QuickCheckTests . safeRead optionName = return "quickcheck-tests" optionHelp = return "Number of test cases for QuickCheck to generate" instance IsOption QuickCheckReplay where defaultValue = QuickCheckReplay Nothing parseValue v = QuickCheckReplay . Just <$> replay -- Reads a replay token in the form "{size} {seed}" where replay = (,) <$> safeRead (intercalate " " seed) <*> safeRead (concat size) (size, seed) = splitAt 1 $ words v optionName = return "quickcheck-replay" optionHelp = return "Replay token to use for replaying a previous test run" instance IsOption QuickCheckShowReplay where defaultValue = QuickCheckShowReplay True parseValue = fmap QuickCheckShowReplay . safeRead optionName = return "quickcheck-show-replay" optionHelp = return "Show a replay token for replaying tests" instance IsOption QuickCheckMaxSize where defaultValue = fromIntegral $ QC.maxSize QC.stdArgs parseValue = fmap QuickCheckMaxSize . safeRead optionName = return "quickcheck-max-size" optionHelp = return "Size of the biggest test cases quickcheck generates" instance IsOption QuickCheckMaxRatio where defaultValue = fromIntegral $ QC.maxDiscardRatio QC.stdArgs parseValue = fmap QuickCheckMaxRatio . safeRead optionName = return "quickcheck-max-ratio" optionHelp = return "Maximum number of discared tests per successful test before giving up" instance IsOption QuickCheckVerbose where defaultValue = QuickCheckVerbose False parseValue = fmap QuickCheckVerbose . safeRead optionName = return "quickcheck-verbose" optionHelp = return "Show the generated test cases" optionCLParser = flagCLParser Nothing (QuickCheckVerbose True) instance IsTest QC where testOptions = return [ Option (Proxy :: Proxy QuickCheckTests) , Option (Proxy :: Proxy QuickCheckReplay) , Option (Proxy :: Proxy QuickCheckShowReplay) , Option (Proxy :: Proxy QuickCheckMaxSize) , Option (Proxy :: Proxy QuickCheckMaxRatio) , Option (Proxy :: Proxy QuickCheckVerbose) ] run opts (QC prop) yieldProgress = do let QuickCheckTests nTests = lookupOption opts QuickCheckReplay replay = lookupOption opts QuickCheckShowReplay showReplay = lookupOption opts QuickCheckMaxSize maxSize = lookupOption opts QuickCheckMaxRatio maxRatio = lookupOption opts QuickCheckVerbose verbose = lookupOption opts args = QC.stdArgs { QC.chatty = False, QC.maxSuccess = nTests, QC.maxSize = maxSize, QC.replay = replay, QC.maxDiscardRatio = maxRatio} testRunner = if verbose then QC.verboseCheckWithResult else QC.quickCheckWithResult r <- testRunner args prop qcOutput <- formatMessage $ QC.output r let qcOutputNl = if "\n" `isSuffixOf` qcOutput then qcOutput else qcOutput ++ "\n" return $ (if successful r then testPassed else testFailed) (qcOutputNl ++ (if showReplay then reproduceMsg r else "")) successful :: QC.Result -> Bool successful r = case r of QC.Success {} -> True _ -> False -- | If the result is a failure, produce a message that explains how to -- reproduce it. If the result is not a failure, return an empty string. reproduceMsg :: QC.Result -> String reproduceMsg QC.Failure { QC.usedSize = size, QC.usedSeed = seed } = printf "Use --quickcheck-replay '%d %s' to reproduce." size (show seed) reproduceMsg _ = "" tasty-quickcheck-0.8.4/tests/test.hs0000644000000000000000000000604212457221174015651 0ustar0000000000000000{-# LANGUAGE RecordWildCards #-} import Test.Tasty import Test.Tasty.Options import Test.Tasty.Providers as Tasty import Test.Tasty.Runners as Tasty import Test.Tasty.QuickCheck import Test.Tasty.HUnit import Data.Monoid import Data.Maybe import Text.Regex.PCRE.Light.Char8 import Text.Printf (=~), (!~) :: String -- ^ text -> String -- ^ regex -> Assertion text =~ regexStr = let msg = printf "Expected /%s/, got %s" regexStr (show text) -- NB show above the intentional -- to add quotes around the string and -- escape newlines etc. in assertBool msg $ match' text regexStr text !~ regexStr = let msg = printf "Did not expect /%s/, got %s" regexStr (show text) in assertBool msg $ not $ match' text regexStr -- note: the order of arguments is reversed relative to match from -- pcre-light, but consistent with =~ and !~ match' :: String -> String -> Bool match' text regexStr = let regex = compile regexStr [] in isJust $ match regex text [] main = defaultMain $ testGroup "Unit tests for Test.Tasty.QuickCheck" [ testCase "Success" $ do Result{..} <- run' $ \x -> x >= (x :: Int) -- there is no instance Show Outcome( -- (because there is no instance Show SomeException), -- so we can't use @?= for this case resultOutcome of Tasty.Success -> return () _ -> assertFailure $ show resultOutcome resultDescription =~ "OK, passed 100 tests" , testCase "Unexpected failure" $ do Result{..} <- run' $ \x -> x > (x :: Int) case resultOutcome of Tasty.Failure {} -> return () _ -> assertFailure $ show resultOutcome resultDescription =~ "Failed" resultDescription =~ "Use .* to reproduce" , testCase "Unexpected failure, no replay message" $ do Result{..} <- runNoReplay $ \x -> x > (x :: Int) case resultOutcome of Tasty.Failure {} -> return () _ -> assertFailure $ show resultOutcome resultDescription =~ "Failed" resultDescription !~ "Use .* to reproduce" , testCase "Gave up" $ do Result{..} <- run' $ \x -> x > x ==> x > (x :: Int) case resultOutcome of Tasty.Failure {} -> return () _ -> assertFailure $ show resultOutcome resultDescription =~ "Gave up" resultDescription !~ "Use .* to reproduce" , testCase "No expected failure" $ do Result{..} <- run' $ expectFailure $ \x -> x >= (x :: Int) case resultOutcome of Tasty.Failure {} -> return () _ -> assertFailure $ show resultOutcome resultDescription =~ "Failed.*expected failure" resultDescription !~ "Use .* to reproduce" ] run' :: Testable p => p -> IO Result run' p = run mempty -- options (QC $ property p) (const $ return ()) -- callback runNoReplay :: Testable p => p -> IO Result runNoReplay p = run (singleOption $ QuickCheckShowReplay False) (QC $ property p) (const $ return ()) tasty-quickcheck-0.8.4/LICENSE0000644000000000000000000000204312457221174014176 0ustar0000000000000000Copyright (c) 2013 Roman Cheplyaka Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tasty-quickcheck-0.8.4/Setup.hs0000644000000000000000000000005612457221174014627 0ustar0000000000000000import Distribution.Simple main = defaultMain tasty-quickcheck-0.8.4/tasty-quickcheck.cabal0000644000000000000000000000315512603746045017440 0ustar0000000000000000-- Initial tasty-quickcheck.cabal generated by cabal init. For further -- documentation, see http://haskell.org/cabal/users-guide/ name: tasty-quickcheck version: 0.8.4 synopsis: QuickCheck support for the Tasty test framework. description: QuickCheck support for the Tasty test framework. license: MIT license-file: LICENSE author: Roman Cheplyaka maintainer: Roman Cheplyaka -- copyright: homepage: http://documentup.com/feuerbach/tasty bug-reports: https://github.com/feuerbach/tasty/issues category: Testing build-type: Simple extra-source-files: CHANGELOG.md cabal-version: >=1.10 Source-repository head type: git location: git://github.com/feuerbach/tasty.git subdir: quickcheck flag old-QuickCheck description: Use Quick-Check < 2.7 default: False library exposed-modules: Test.Tasty.QuickCheck -- other-modules: other-extensions: GeneralizedNewtypeDeriving, DeriveDataTypeable build-depends: base == 4.*, tagged, tasty >= 0.10.1 if flag(old-QuickCheck) build-depends: QuickCheck >= 2.5 && < 2.7, random else build-depends: QuickCheck >= 2.7 && < 3 -- hs-source-dirs: default-language: Haskell2010 test-suite test default-language: Haskell2010 type: exitcode-stdio-1.0 hs-source-dirs: tests main-is: test.hs build-depends: base >= 4 && < 5 , tasty >= 0.10 , tasty-quickcheck , tasty-hunit , pcre-light tasty-quickcheck-0.8.4/CHANGELOG.md0000644000000000000000000000176712603746046015021 0ustar0000000000000000Changes ======= Version 0.8.4 ------------- Add a "--quickcheck-verbose" option Version 0.8.3.2 --------------- * Put correct lower version bound on tasty * Allow use of older QuickCheck for HP compatibility Version 0.8.3.1 --------------- When QC message throws an exception, still print the replay message Version 0.8.3 ------------- * Export 'show replay' option * Fixed a run-time error when using QuickCheck's `expectFailure` Version 0.8.2 ------------- * Allow suppressing the --quickcheck-replay hint * Split the changelog out of the main tasty changelog Version 0.8.1 ------------- Re-export `Gen` from `Test.Tasty.QuickCheck` Version 0.8.0.3 --------------- Upgrade to QuickCheck 2.7 Version 0.8 ----------- Update to tasty-0.8 Version 0.3.1 ------------- Use the original QuickCheck's output format Version 0.3 ----------- Add options for maximum size and maximum ratio; support replay. Version 0.2 ----------- Re-export useful bits of `Test.QuickCheck` from `Test.Tasty.QuickCheck`