{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
module Distribution.TestSuite.QuickCheck
(
getPropertyTest,
getPropertyTestWith,
getPropertyTestUsing,
getPropertyTestWithUsing,
getPropertyTests,
propertyTestGroup,
PropertyTest (..),
TestArgs (..),
Verbosity (..),
argsToTestArgs,
argsToTestArgsWith,
testArgsToArgs,
stdTestArgs,
)
where
import Data.Bool (bool)
import Data.Functor ((<&>))
import qualified Distribution.TestSuite as T
import qualified Test.QuickCheck as QC
import Test.QuickCheck.Random (QCGen)
import Text.Read (readMaybe)
data Verbosity
=
Silent
|
Chatty
|
Verbose
deriving
( Verbosity -> Verbosity -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Verbosity -> Verbosity -> Bool
$c/= :: Verbosity -> Verbosity -> Bool
== :: Verbosity -> Verbosity -> Bool
$c== :: Verbosity -> Verbosity -> Bool
Eq,
Eq Verbosity
Verbosity -> Verbosity -> Bool
Verbosity -> Verbosity -> Ordering
Verbosity -> Verbosity -> Verbosity
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Verbosity -> Verbosity -> Verbosity
$cmin :: Verbosity -> Verbosity -> Verbosity
max :: Verbosity -> Verbosity -> Verbosity
$cmax :: Verbosity -> Verbosity -> Verbosity
>= :: Verbosity -> Verbosity -> Bool
$c>= :: Verbosity -> Verbosity -> Bool
> :: Verbosity -> Verbosity -> Bool
$c> :: Verbosity -> Verbosity -> Bool
<= :: Verbosity -> Verbosity -> Bool
$c<= :: Verbosity -> Verbosity -> Bool
< :: Verbosity -> Verbosity -> Bool
$c< :: Verbosity -> Verbosity -> Bool
compare :: Verbosity -> Verbosity -> Ordering
$ccompare :: Verbosity -> Verbosity -> Ordering
Ord,
Int -> Verbosity -> ShowS
[Verbosity] -> ShowS
Verbosity -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Verbosity] -> ShowS
$cshowList :: [Verbosity] -> ShowS
show :: Verbosity -> String
$cshow :: Verbosity -> String
showsPrec :: Int -> Verbosity -> ShowS
$cshowsPrec :: Int -> Verbosity -> ShowS
Show,
ReadPrec [Verbosity]
ReadPrec Verbosity
Int -> ReadS Verbosity
ReadS [Verbosity]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Verbosity]
$creadListPrec :: ReadPrec [Verbosity]
readPrec :: ReadPrec Verbosity
$creadPrec :: ReadPrec Verbosity
readList :: ReadS [Verbosity]
$creadList :: ReadS [Verbosity]
readsPrec :: Int -> ReadS Verbosity
$creadsPrec :: Int -> ReadS Verbosity
Read,
Int -> Verbosity
Verbosity -> Int
Verbosity -> [Verbosity]
Verbosity -> Verbosity
Verbosity -> Verbosity -> [Verbosity]
Verbosity -> Verbosity -> Verbosity -> [Verbosity]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Verbosity -> Verbosity -> Verbosity -> [Verbosity]
$cenumFromThenTo :: Verbosity -> Verbosity -> Verbosity -> [Verbosity]
enumFromTo :: Verbosity -> Verbosity -> [Verbosity]
$cenumFromTo :: Verbosity -> Verbosity -> [Verbosity]
enumFromThen :: Verbosity -> Verbosity -> [Verbosity]
$cenumFromThen :: Verbosity -> Verbosity -> [Verbosity]
enumFrom :: Verbosity -> [Verbosity]
$cenumFrom :: Verbosity -> [Verbosity]
fromEnum :: Verbosity -> Int
$cfromEnum :: Verbosity -> Int
toEnum :: Int -> Verbosity
$ctoEnum :: Int -> Verbosity
pred :: Verbosity -> Verbosity
$cpred :: Verbosity -> Verbosity
succ :: Verbosity -> Verbosity
$csucc :: Verbosity -> Verbosity
Enum,
Verbosity
forall a. a -> a -> Bounded a
maxBound :: Verbosity
$cmaxBound :: Verbosity
minBound :: Verbosity
$cminBound :: Verbosity
Bounded
)
switchVerbosity :: Verbosity -> Bool -> Verbosity -> Verbosity
switchVerbosity :: Verbosity -> Bool -> Verbosity -> Verbosity
switchVerbosity Verbosity
v' Bool
True Verbosity
v = Verbosity
v'
switchVerbosity Verbosity
v' Bool
False Verbosity
v = forall a. Ord a => a -> a -> a
min (forall a. Enum a => a -> a
pred Verbosity
v') Verbosity
v
data TestArgs = TestArgs
{
TestArgs -> Verbosity
verbosity :: Verbosity,
TestArgs -> Bool
verboseShrinking :: Bool,
TestArgs -> Int
maxDiscardRatio :: Int,
TestArgs -> Bool
noShrinking :: Bool,
TestArgs -> Int
maxShrinks :: Int,
TestArgs -> Int
maxSuccess :: Int,
TestArgs -> Int
maxSize :: Int,
TestArgs -> Int
sizeScale :: Int,
TestArgs -> Maybe (QCGen, Int)
replay :: Maybe (QCGen, Int)
}
argsToTestArgs :: QC.Args -> TestArgs
argsToTestArgs :: Args -> TestArgs
argsToTestArgs = TestArgs -> Args -> TestArgs
argsToTestArgsWith TestArgs
stdTestArgs
argsToTestArgsWith :: TestArgs -> QC.Args -> TestArgs
argsToTestArgsWith :: TestArgs -> Args -> TestArgs
argsToTestArgsWith TestArgs
testArgs QC.Args {Bool
Int
Maybe (QCGen, Int)
replay :: Args -> Maybe (QCGen, Int)
maxSuccess :: Args -> Int
maxDiscardRatio :: Args -> Int
maxSize :: Args -> Int
chatty :: Args -> Bool
maxShrinks :: Args -> Int
maxShrinks :: Int
chatty :: Bool
maxSize :: Int
maxDiscardRatio :: Int
maxSuccess :: Int
replay :: Maybe (QCGen, Int)
..} =
TestArgs
testArgs
{ verbosity :: Verbosity
verbosity = if Bool
chatty then Verbosity
Chatty else Verbosity
Silent,
Int
maxDiscardRatio :: Int
maxDiscardRatio :: Int
maxDiscardRatio,
Int
maxShrinks :: Int
maxShrinks :: Int
maxShrinks,
Int
maxSuccess :: Int
maxSuccess :: Int
maxSuccess,
Int
maxSize :: Int
maxSize :: Int
maxSize,
Maybe (QCGen, Int)
replay :: Maybe (QCGen, Int)
replay :: Maybe (QCGen, Int)
replay
}
testArgsToArgs :: TestArgs -> QC.Args
testArgsToArgs :: TestArgs -> Args
testArgsToArgs TestArgs {Bool
Int
Maybe (QCGen, Int)
Verbosity
replay :: Maybe (QCGen, Int)
sizeScale :: Int
maxSize :: Int
maxSuccess :: Int
maxShrinks :: Int
noShrinking :: Bool
maxDiscardRatio :: Int
verboseShrinking :: Bool
verbosity :: Verbosity
replay :: TestArgs -> Maybe (QCGen, Int)
sizeScale :: TestArgs -> Int
maxSize :: TestArgs -> Int
maxSuccess :: TestArgs -> Int
maxShrinks :: TestArgs -> Int
noShrinking :: TestArgs -> Bool
maxDiscardRatio :: TestArgs -> Int
verboseShrinking :: TestArgs -> Bool
verbosity :: TestArgs -> Verbosity
..} =
QC.Args
{ Maybe (QCGen, Int)
replay :: Maybe (QCGen, Int)
replay :: Maybe (QCGen, Int)
replay,
Int
maxSuccess :: Int
maxSuccess :: Int
maxSuccess,
Int
maxDiscardRatio :: Int
maxDiscardRatio :: Int
maxDiscardRatio,
Int
maxSize :: Int
maxSize :: Int
maxSize,
chatty :: Bool
chatty = Verbosity
verbosity forall a. Ord a => a -> a -> Bool
>= Verbosity
Chatty,
Int
maxShrinks :: Int
maxShrinks :: Int
maxShrinks
}
stdTestArgs :: TestArgs
stdTestArgs :: TestArgs
stdTestArgs =
TestArgs
{ verbosity :: Verbosity
verbosity = Verbosity
Chatty,
verboseShrinking :: Bool
verboseShrinking = Bool
False,
maxDiscardRatio :: Int
maxDiscardRatio = Int
10,
noShrinking :: Bool
noShrinking = Bool
False,
maxShrinks :: Int
maxShrinks = forall a. Bounded a => a
maxBound,
maxSuccess :: Int
maxSuccess = Int
100,
maxSize :: Int
maxSize = Int
100,
sizeScale :: Int
sizeScale = Int
1,
replay :: Maybe (QCGen, Int)
replay = forall a. Maybe a
Nothing
}
switchVIn :: Verbosity -> Bool -> TestArgs -> TestArgs
switchVIn :: Verbosity -> Bool -> TestArgs -> TestArgs
switchVIn Verbosity
v' Bool
q args :: TestArgs
args@TestArgs {Verbosity
verbosity :: Verbosity
verbosity :: TestArgs -> Verbosity
verbosity} = TestArgs
args {verbosity :: Verbosity
verbosity = Verbosity -> Bool -> Verbosity -> Verbosity
switchVerbosity Verbosity
v' Bool
q Verbosity
verbosity}
setArgStr :: String -> String -> Maybe (TestArgs -> TestArgs)
setArgStr :: String -> String -> Maybe (TestArgs -> TestArgs)
setArgStr String
"silent" String
str =
forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Bool
val args :: TestArgs
args@TestArgs {Verbosity
verbosity :: Verbosity
verbosity :: TestArgs -> Verbosity
verbosity} ->
if Bool
val
then TestArgs
args {verbosity :: Verbosity
verbosity = Verbosity
Silent}
else TestArgs
args {verbosity :: Verbosity
verbosity = forall a. Ord a => a -> a -> a
max Verbosity
Chatty Verbosity
verbosity}
setArgStr String
"chatty" String
str = forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> Verbosity -> Bool -> TestArgs -> TestArgs
switchVIn Verbosity
Chatty
setArgStr String
"verbose" String
str = forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> Verbosity -> Bool -> TestArgs -> TestArgs
switchVIn Verbosity
Verbose
setArgStr String
"verboseShrinking" String
str =
forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Bool
val TestArgs
args ->
TestArgs
args {verboseShrinking :: Bool
verboseShrinking = Bool
val}
setArgStr String
"verbosity" String
str =
forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Verbosity
val TestArgs
args ->
TestArgs
args {verbosity :: Verbosity
verbosity = Verbosity
val}
setArgStr String
"maxDiscardRatio" String
str =
forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Int
val TestArgs
args ->
TestArgs
args {maxDiscardRatio :: Int
maxDiscardRatio = Int
val}
setArgStr String
"noShrinking" String
str =
forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Bool
val TestArgs
args ->
TestArgs
args {noShrinking :: Bool
noShrinking = Bool
val}
setArgStr String
"shrinking" String
str =
forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Bool
val TestArgs
args ->
TestArgs
args {noShrinking :: Bool
noShrinking = Bool -> Bool
not Bool
val}
setArgStr String
"maxShrinks" String
str =
forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Int
val TestArgs
args ->
TestArgs
args {maxShrinks :: Int
maxShrinks = Int
val}
setArgStr String
"maxSuccess" String
str =
forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Int
val TestArgs
args ->
TestArgs
args {maxSuccess :: Int
maxSuccess = Int
val}
setArgStr String
"maxSize" String
str =
forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Int
val TestArgs
args ->
TestArgs
args {maxSize :: Int
maxSize = Int
val}
setArgStr String
"sizeScale" String
str =
forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Int
val TestArgs
args ->
TestArgs
args {sizeScale :: Int
sizeScale = Int
val}
setArgStr String
"replay" String
str =
case String
str of
String
"" -> forall a. a -> Maybe a
Just \TestArgs
args -> TestArgs
args {replay :: Maybe (QCGen, Int)
replay = forall a. Maybe a
Nothing}
String
_ ->
forall a. Read a => String -> Maybe a
readMaybe String
str forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(QCGen, Int)
val TestArgs
args ->
TestArgs
args {replay :: Maybe (QCGen, Int)
replay = forall a. a -> Maybe a
Just (QCGen, Int)
val}
setArgStr String
_ String
_ = forall a. Maybe a
Nothing
positiveIntType :: T.OptionType
positiveIntType :: OptionType
positiveIntType =
T.OptionNumber
{ optionNumberIsInt :: Bool
optionNumberIsInt = Bool
True,
optionNumberBounds :: (Maybe String, Maybe String)
optionNumberBounds = (forall a. a -> Maybe a
Just String
"1", forall a. Maybe a
Nothing)
}
getOptionDescrs :: TestArgs -> [T.OptionDescr]
getOptionDescrs :: TestArgs -> [OptionDescr]
getOptionDescrs TestArgs {Bool
Int
Maybe (QCGen, Int)
Verbosity
replay :: Maybe (QCGen, Int)
sizeScale :: Int
maxSize :: Int
maxSuccess :: Int
maxShrinks :: Int
noShrinking :: Bool
maxDiscardRatio :: Int
verboseShrinking :: Bool
verbosity :: Verbosity
replay :: TestArgs -> Maybe (QCGen, Int)
sizeScale :: TestArgs -> Int
maxSize :: TestArgs -> Int
maxSuccess :: TestArgs -> Int
maxShrinks :: TestArgs -> Int
noShrinking :: TestArgs -> Bool
maxDiscardRatio :: TestArgs -> Int
verboseShrinking :: TestArgs -> Bool
verbosity :: TestArgs -> Verbosity
..} =
[ T.OptionDescr
{ optionName :: String
optionName = String
"silent",
optionDescription :: String
optionDescription = String
"Suppress QuickCheck output",
optionType :: OptionType
optionType = OptionType
T.OptionBool,
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$ Verbosity
verbosity forall a. Eq a => a -> a -> Bool
== Verbosity
Silent
},
T.OptionDescr
{ optionName :: String
optionName = String
"chatty",
optionDescription :: String
optionDescription = String
"Print QuickCheck output",
optionType :: OptionType
optionType = OptionType
T.OptionBool,
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$ Verbosity
verbosity forall a. Ord a => a -> a -> Bool
> Verbosity
Chatty
},
T.OptionDescr
{ optionName :: String
optionName = String
"verbose",
optionDescription :: String
optionDescription = String
"Print checked values",
optionType :: OptionType
optionType = OptionType
T.OptionBool,
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$ Verbosity
verbosity forall a. Ord a => a -> a -> Bool
> Verbosity
Verbose
},
T.OptionDescr
{ optionName :: String
optionName = String
"verboseShrinking",
optionDescription :: String
optionDescription = String
"Print all checked and shrunk values",
optionType :: OptionType
optionType = OptionType
T.OptionBool,
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$ Bool
verboseShrinking
},
T.OptionDescr
{ optionName :: String
optionName = String
"verbosity",
optionDescription :: String
optionDescription = String
"Verbosity level",
optionType :: OptionType
optionType = [String] -> OptionType
T.OptionEnum [String
"Silent", String
"Chatty", String
"Verbose", String
"VerboseShrinking"],
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Verbosity
verbosity
},
T.OptionDescr
{ optionName :: String
optionName = String
"maxDiscardRatio",
optionDescription :: String
optionDescription = String
"Maximum number of discarded tests per successful test before giving up",
optionType :: OptionType
optionType = OptionType
positiveIntType,
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Int
maxDiscardRatio
},
T.OptionDescr
{ optionName :: String
optionName = String
"noShrinking",
optionDescription :: String
optionDescription = String
"Disable shrinking",
optionType :: OptionType
optionType = OptionType
T.OptionBool,
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Bool
noShrinking
},
T.OptionDescr
{ optionName :: String
optionName = String
"shrinking",
optionDescription :: String
optionDescription = String
"Enable shrinking",
optionType :: OptionType
optionType = OptionType
T.OptionBool,
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
noShrinking
},
T.OptionDescr
{ optionName :: String
optionName = String
"maxShrinks",
optionDescription :: String
optionDescription = String
"Maximum number of shrinks before giving up or zero to disable shrinking",
optionType :: OptionType
optionType =
T.OptionNumber
{ optionNumberIsInt :: Bool
optionNumberIsInt = Bool
True,
optionNumberBounds :: (Maybe String, Maybe String)
optionNumberBounds = (forall a. a -> Maybe a
Just String
"0", forall a. Maybe a
Nothing)
},
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Int
maxShrinks
},
T.OptionDescr
{ optionName :: String
optionName = String
"maxSuccess",
optionDescription :: String
optionDescription = String
"Maximum number of successful tests before succeeding",
optionType :: OptionType
optionType = OptionType
positiveIntType,
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Int
maxSuccess
},
T.OptionDescr
{ optionName :: String
optionName = String
"maxSize",
optionDescription :: String
optionDescription = String
"Size to use for the biggest test cases",
optionType :: OptionType
optionType = OptionType
positiveIntType,
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Int
maxSize
},
T.OptionDescr
{ optionName :: String
optionName = String
"sizeScale",
optionDescription :: String
optionDescription = String
"Scale all sizes by a number",
optionType :: OptionType
optionType = OptionType
positiveIntType,
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Int
sizeScale
},
T.OptionDescr
{ optionName :: String
optionName = String
"replay",
optionDescription :: String
optionDescription = String
"Replay a previous test",
optionType :: OptionType
optionType = Bool -> OptionType
T.OptionString Bool
False,
optionDefault :: Maybe String
optionDefault = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show @(Maybe (QCGen, Int)) forall a. Maybe a
Nothing
}
]
getModifiers :: QC.Testable a => TestArgs -> a -> QC.Property
getModifiers :: forall a. Testable a => TestArgs -> a -> Property
getModifiers TestArgs {Verbosity
verbosity :: Verbosity
verbosity :: TestArgs -> Verbosity
verbosity, Bool
noShrinking :: Bool
noShrinking :: TestArgs -> Bool
noShrinking, Bool
verboseShrinking :: Bool
verboseShrinking :: TestArgs -> Bool
verboseShrinking, Int
sizeScale :: Int
sizeScale :: TestArgs -> Int
sizeScale} =
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) forall prop. Testable prop => prop -> Property
QC.property forall a b. (a -> b) -> a -> b
$
forall a b. (a, b) -> b
snd
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. (a -> Bool) -> [a] -> [a]
filter
forall a b. (a, b) -> a
fst
[ (Verbosity
verbosity forall a. Eq a => a -> a -> Bool
== Verbosity
Verbose, forall prop. Testable prop => prop -> Property
QC.verbose),
(Bool
verboseShrinking, forall prop. Testable prop => prop -> Property
QC.verboseShrinking),
(Bool
noShrinking, forall prop. Testable prop => prop -> Property
QC.noShrinking),
(Int
sizeScale forall a. Eq a => a -> a -> Bool
/= Int
1, forall prop. Testable prop => (Int -> Int) -> prop -> Property
QC.mapSize (forall a. Num a => a -> a -> a
* Int
sizeScale))
]
data PropertyTest prop = PropertyTest
{
forall prop. PropertyTest prop -> String
name :: String,
forall prop. PropertyTest prop -> [String]
tags :: [String],
forall prop. PropertyTest prop -> prop
property :: prop
}
qcTestArgs :: QC.Testable a => TestArgs -> a -> IO QC.Result
qcTestArgs :: forall a. Testable a => TestArgs -> a -> IO Result
qcTestArgs TestArgs
args a
property = forall prop. Testable prop => Args -> prop -> IO Result
QC.quickCheckWithResult (TestArgs -> Args
testArgsToArgs TestArgs
args) (forall a. Testable a => TestArgs -> a -> Property
getModifiers TestArgs
args a
property)
getPropertyTestWithUsing ::
QC.Testable prop =>
TestArgs ->
PropertyTest (TestArgs -> prop) ->
T.Test
getPropertyTestWithUsing :: forall prop.
Testable prop =>
TestArgs -> PropertyTest (TestArgs -> prop) -> Test
getPropertyTestWithUsing TestArgs
originalArgs PropertyTest {String
[String]
TestArgs -> prop
property :: TestArgs -> prop
tags :: [String]
name :: String
property :: forall prop. PropertyTest prop -> prop
tags :: forall prop. PropertyTest prop -> [String]
name :: forall prop. PropertyTest prop -> String
..} =
let withArgs :: TestArgs -> TestInstance
withArgs TestArgs
args =
T.TestInstance
{ run :: IO Progress
run = do
Result
result <- forall a. Testable a => TestArgs -> a -> IO Result
qcTestArgs TestArgs
args (TestArgs -> prop
property TestArgs
args)
let resultStr :: String
resultStr = String
"\n" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Result
result
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Result -> Progress
T.Finished case Result
result of
QC.Success {} -> Result
T.Pass
QC.GaveUp {} ->
String -> Result
T.Error forall a b. (a -> b) -> a -> b
$ String
"GaveUp: QuickCheck gave up" forall a. [a] -> [a] -> [a]
++ String
resultStr
QC.Failure {} ->
String -> Result
T.Fail forall a b. (a -> b) -> a -> b
$ String
"Failure: A property failed" forall a. [a] -> [a] -> [a]
++ String
resultStr
QC.NoExpectedFailure {} ->
String -> Result
T.Fail forall a b. (a -> b) -> a -> b
$ String
"NoExpectedFailure: A property that should have failed did not" forall a. [a] -> [a] -> [a]
++ String
resultStr,
String
name :: String
name :: String
name,
[String]
tags :: [String]
tags :: [String]
tags,
options :: [OptionDescr]
options = TestArgs -> [OptionDescr]
getOptionDescrs TestArgs
originalArgs,
setOption :: String -> String -> Either String TestInstance
setOption = \String
opt String
str -> case String -> String -> Maybe (TestArgs -> TestArgs)
setArgStr String
opt String
str of
Maybe (TestArgs -> TestArgs)
Nothing -> forall a b. a -> Either a b
Left String
"Parse error"
Just TestArgs -> TestArgs
f -> forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. TestArgs -> TestInstance
withArgs forall a b. (a -> b) -> a -> b
$ TestArgs -> TestArgs
f TestArgs
args
}
in TestInstance -> Test
T.Test forall a b. (a -> b) -> a -> b
$ TestArgs -> TestInstance
withArgs TestArgs
originalArgs
getPropertyTestUsing ::
QC.Testable prop =>
PropertyTest (TestArgs -> prop) ->
T.Test
getPropertyTestUsing :: forall prop.
Testable prop =>
PropertyTest (TestArgs -> prop) -> Test
getPropertyTestUsing = forall prop.
Testable prop =>
TestArgs -> PropertyTest (TestArgs -> prop) -> Test
getPropertyTestWithUsing TestArgs
stdTestArgs
discardingTestArgs :: PropertyTest prop -> PropertyTest (TestArgs -> prop)
discardingTestArgs :: forall prop. PropertyTest prop -> PropertyTest (TestArgs -> prop)
discardingTestArgs test :: PropertyTest prop
test@PropertyTest {prop
property :: prop
property :: forall prop. PropertyTest prop -> prop
property} = PropertyTest prop
test {property :: TestArgs -> prop
property = forall a b. a -> b -> a
const prop
property}
getPropertyTestWith ::
QC.Testable prop =>
TestArgs ->
PropertyTest prop ->
T.Test
getPropertyTestWith :: forall prop. Testable prop => TestArgs -> PropertyTest prop -> Test
getPropertyTestWith TestArgs
args = forall prop.
Testable prop =>
TestArgs -> PropertyTest (TestArgs -> prop) -> Test
getPropertyTestWithUsing TestArgs
args forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall prop. PropertyTest prop -> PropertyTest (TestArgs -> prop)
discardingTestArgs
getPropertyTest :: QC.Testable prop => PropertyTest prop -> T.Test
getPropertyTest :: forall prop. Testable prop => PropertyTest prop -> Test
getPropertyTest = forall prop.
Testable prop =>
TestArgs -> PropertyTest (TestArgs -> prop) -> Test
getPropertyTestWithUsing TestArgs
stdTestArgs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall prop. PropertyTest prop -> PropertyTest (TestArgs -> prop)
discardingTestArgs
getPropertyTests :: QC.Testable prop => [PropertyTest prop] -> [T.Test]
getPropertyTests :: forall prop. Testable prop => [PropertyTest prop] -> [Test]
getPropertyTests = (forall prop. Testable prop => PropertyTest prop -> Test
getPropertyTest forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>)
propertyTestGroup :: QC.Testable prop => String -> [PropertyTest prop] -> T.Test
propertyTestGroup :: forall prop. Testable prop => String -> [PropertyTest prop] -> Test
propertyTestGroup String
name = String -> [Test] -> Test
T.testGroup String
name forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall prop. Testable prop => [PropertyTest prop] -> [Test]
getPropertyTests