{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Test.Syd.Modify
(
modifyMaxSuccess,
modifyMaxDiscardRatio,
modifyMaxSize,
modifyMaxShrinks,
modifyRunSettings,
TestRunSettings (..),
sequential,
parallel,
withParallelism,
Parallelism (..),
randomiseExecutionOrder,
doNotRandomiseExecutionOrder,
withExecutionOrderRandomisation,
ExecutionOrderRandomisation (..),
modifyTimeout,
withoutTimeout,
withTimeout,
modifyRetries,
withoutRetries,
withRetries,
flaky,
flakyWith,
notFlaky,
potentiallyFlaky,
potentiallyFlakyWith,
withFlakiness,
FlakinessMode (..),
expectPassing,
expectFailing,
withExpectationMode,
ExpectationMode (..),
)
where
import Control.Monad.RWS.Strict
import Test.QuickCheck.IO ()
import Test.Syd.Def
import Test.Syd.OptParse
import Test.Syd.Run
import Test.Syd.SpecDef
modifyRunSettings :: (TestRunSettings -> TestRunSettings) -> TestDefM a b c -> TestDefM a b c
modifyRunSettings :: forall (a :: [*]) b c.
(TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c
modifyRunSettings TestRunSettings -> TestRunSettings
func = (TestDefEnv -> TestDefEnv) -> TestDefM a b c -> TestDefM a b c
forall a.
(TestDefEnv -> TestDefEnv) -> TestDefM a b a -> TestDefM a b a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\TestDefEnv
tde -> TestDefEnv
tde {testDefEnvTestRunSettings = func $ testDefEnvTestRunSettings tde})
modifyMaxSuccess :: (Int -> Int) -> TestDefM a b c -> TestDefM a b c
modifyMaxSuccess :: forall (a :: [*]) b c.
(Int -> Int) -> TestDefM a b c -> TestDefM a b c
modifyMaxSuccess Int -> Int
func = (TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
(TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c
modifyRunSettings ((TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c)
-> (TestRunSettings -> TestRunSettings)
-> TestDefM a b c
-> TestDefM a b c
forall a b. (a -> b) -> a -> b
$ \TestRunSettings
trs -> TestRunSettings
trs {testRunSettingMaxSuccess = func (testRunSettingMaxSuccess trs)}
modifyMaxDiscardRatio :: (Int -> Int) -> TestDefM a b c -> TestDefM a b c
modifyMaxDiscardRatio :: forall (a :: [*]) b c.
(Int -> Int) -> TestDefM a b c -> TestDefM a b c
modifyMaxDiscardRatio Int -> Int
func = (TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
(TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c
modifyRunSettings ((TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c)
-> (TestRunSettings -> TestRunSettings)
-> TestDefM a b c
-> TestDefM a b c
forall a b. (a -> b) -> a -> b
$ \TestRunSettings
trs -> TestRunSettings
trs {testRunSettingMaxDiscardRatio = func (testRunSettingMaxDiscardRatio trs)}
modifyMaxSize :: (Int -> Int) -> TestDefM a b c -> TestDefM a b c
modifyMaxSize :: forall (a :: [*]) b c.
(Int -> Int) -> TestDefM a b c -> TestDefM a b c
modifyMaxSize Int -> Int
func = (TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
(TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c
modifyRunSettings ((TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c)
-> (TestRunSettings -> TestRunSettings)
-> TestDefM a b c
-> TestDefM a b c
forall a b. (a -> b) -> a -> b
$ \TestRunSettings
trs -> TestRunSettings
trs {testRunSettingMaxSize = func (testRunSettingMaxSize trs)}
modifyMaxShrinks :: (Int -> Int) -> TestDefM a b c -> TestDefM a b c
modifyMaxShrinks :: forall (a :: [*]) b c.
(Int -> Int) -> TestDefM a b c -> TestDefM a b c
modifyMaxShrinks Int -> Int
func = (TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
(TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c
modifyRunSettings ((TestRunSettings -> TestRunSettings)
-> TestDefM a b c -> TestDefM a b c)
-> (TestRunSettings -> TestRunSettings)
-> TestDefM a b c
-> TestDefM a b c
forall a b. (a -> b) -> a -> b
$ \TestRunSettings
trs -> TestRunSettings
trs {testRunSettingMaxShrinks = func (testRunSettingMaxShrinks trs)}
sequential :: TestDefM a b c -> TestDefM a b c
sequential :: forall (a :: [*]) b c. TestDefM a b c -> TestDefM a b c
sequential = Parallelism -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
Parallelism -> TestDefM a b c -> TestDefM a b c
withParallelism Parallelism
Sequential
parallel :: TestDefM a b c -> TestDefM a b c
parallel :: forall (a :: [*]) b c. TestDefM a b c -> TestDefM a b c
parallel = Parallelism -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
Parallelism -> TestDefM a b c -> TestDefM a b c
withParallelism Parallelism
Parallel
withParallelism :: Parallelism -> TestDefM a b c -> TestDefM a b c
withParallelism :: forall (a :: [*]) b c.
Parallelism -> TestDefM a b c -> TestDefM a b c
withParallelism Parallelism
p = ([SpecDefTree a b ()] -> [SpecDefTree a b ()])
-> TestDefM a b c -> TestDefM a b c
forall w (m :: * -> *) a. MonadWriter w m => (w -> w) -> m a -> m a
censor ((SpecDefTree a b () -> [SpecDefTree a b ()] -> [SpecDefTree a b ()]
forall a. a -> [a] -> [a]
: []) (SpecDefTree a b () -> [SpecDefTree a b ()])
-> ([SpecDefTree a b ()] -> SpecDefTree a b ())
-> [SpecDefTree a b ()]
-> [SpecDefTree a b ()]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parallelism -> [SpecDefTree a b ()] -> SpecDefTree a b ()
forall (outers :: [*]) inner extra.
Parallelism
-> SpecDefForest outers inner extra
-> SpecDefTree outers inner extra
DefParallelismNode Parallelism
p)
doNotRandomiseExecutionOrder :: TestDefM a b c -> TestDefM a b c
doNotRandomiseExecutionOrder :: forall (a :: [*]) b c. TestDefM a b c -> TestDefM a b c
doNotRandomiseExecutionOrder = ExecutionOrderRandomisation -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
ExecutionOrderRandomisation -> TestDefM a b c -> TestDefM a b c
withExecutionOrderRandomisation ExecutionOrderRandomisation
DoNotRandomiseExecutionOrder
randomiseExecutionOrder :: TestDefM a b c -> TestDefM a b c
randomiseExecutionOrder :: forall (a :: [*]) b c. TestDefM a b c -> TestDefM a b c
randomiseExecutionOrder = ExecutionOrderRandomisation -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
ExecutionOrderRandomisation -> TestDefM a b c -> TestDefM a b c
withExecutionOrderRandomisation ExecutionOrderRandomisation
RandomiseExecutionOrder
withExecutionOrderRandomisation :: ExecutionOrderRandomisation -> TestDefM a b c -> TestDefM a b c
withExecutionOrderRandomisation :: forall (a :: [*]) b c.
ExecutionOrderRandomisation -> TestDefM a b c -> TestDefM a b c
withExecutionOrderRandomisation ExecutionOrderRandomisation
p = ([SpecDefTree a b ()] -> [SpecDefTree a b ()])
-> TestDefM a b c -> TestDefM a b c
forall w (m :: * -> *) a. MonadWriter w m => (w -> w) -> m a -> m a
censor ((SpecDefTree a b () -> [SpecDefTree a b ()] -> [SpecDefTree a b ()]
forall a. a -> [a] -> [a]
: []) (SpecDefTree a b () -> [SpecDefTree a b ()])
-> ([SpecDefTree a b ()] -> SpecDefTree a b ())
-> [SpecDefTree a b ()]
-> [SpecDefTree a b ()]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExecutionOrderRandomisation
-> [SpecDefTree a b ()] -> SpecDefTree a b ()
forall (outers :: [*]) inner extra.
ExecutionOrderRandomisation
-> SpecDefForest outers inner extra
-> SpecDefTree outers inner extra
DefRandomisationNode ExecutionOrderRandomisation
p)
modifyTimeout :: (Timeout -> Timeout) -> TestDefM a b c -> TestDefM a b c
modifyTimeout :: forall (a :: [*]) b c.
(Timeout -> Timeout) -> TestDefM a b c -> TestDefM a b c
modifyTimeout Timeout -> Timeout
modTimeout = ([SpecDefTree a b ()] -> [SpecDefTree a b ()])
-> TestDefM a b c -> TestDefM a b c
forall w (m :: * -> *) a. MonadWriter w m => (w -> w) -> m a -> m a
censor ((SpecDefTree a b () -> [SpecDefTree a b ()] -> [SpecDefTree a b ()]
forall a. a -> [a] -> [a]
: []) (SpecDefTree a b () -> [SpecDefTree a b ()])
-> ([SpecDefTree a b ()] -> SpecDefTree a b ())
-> [SpecDefTree a b ()]
-> [SpecDefTree a b ()]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Timeout -> Timeout) -> [SpecDefTree a b ()] -> SpecDefTree a b ()
forall (outers :: [*]) inner extra.
(Timeout -> Timeout)
-> SpecDefForest outers inner extra
-> SpecDefTree outers inner extra
DefTimeoutNode Timeout -> Timeout
modTimeout)
withoutTimeout :: TestDefM a b c -> TestDefM a b c
withoutTimeout :: forall (a :: [*]) b c. TestDefM a b c -> TestDefM a b c
withoutTimeout = (Timeout -> Timeout) -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
(Timeout -> Timeout) -> TestDefM a b c -> TestDefM a b c
modifyTimeout (Timeout -> Timeout -> Timeout
forall a b. a -> b -> a
const Timeout
DoNotTimeout)
withTimeout :: Int -> TestDefM a b c -> TestDefM a b c
withTimeout :: forall (a :: [*]) b c. Int -> TestDefM a b c -> TestDefM a b c
withTimeout Int
i = (Timeout -> Timeout) -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
(Timeout -> Timeout) -> TestDefM a b c -> TestDefM a b c
modifyTimeout (Timeout -> Timeout -> Timeout
forall a b. a -> b -> a
const (Int -> Timeout
TimeoutAfterMicros Int
i))
modifyRetries :: (Word -> Word) -> TestDefM a b c -> TestDefM a b c
modifyRetries :: forall (a :: [*]) b c.
(Word -> Word) -> TestDefM a b c -> TestDefM a b c
modifyRetries Word -> Word
modRetries = ([SpecDefTree a b ()] -> [SpecDefTree a b ()])
-> TestDefM a b c -> TestDefM a b c
forall w (m :: * -> *) a. MonadWriter w m => (w -> w) -> m a -> m a
censor ((SpecDefTree a b () -> [SpecDefTree a b ()] -> [SpecDefTree a b ()]
forall a. a -> [a] -> [a]
: []) (SpecDefTree a b () -> [SpecDefTree a b ()])
-> ([SpecDefTree a b ()] -> SpecDefTree a b ())
-> [SpecDefTree a b ()]
-> [SpecDefTree a b ()]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word -> Word) -> [SpecDefTree a b ()] -> SpecDefTree a b ()
forall (outers :: [*]) inner extra.
(Word -> Word)
-> SpecDefForest outers inner extra
-> SpecDefTree outers inner extra
DefRetriesNode Word -> Word
modRetries)
withoutRetries :: TestDefM a b c -> TestDefM a b c
withoutRetries :: forall (a :: [*]) b c. TestDefM a b c -> TestDefM a b c
withoutRetries = (Word -> Word) -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
(Word -> Word) -> TestDefM a b c -> TestDefM a b c
modifyRetries (Word -> Word -> Word
forall a b. a -> b -> a
const Word
0)
withRetries :: Word -> TestDefM a b c -> TestDefM a b c
withRetries :: forall (a :: [*]) b c. Word -> TestDefM a b c -> TestDefM a b c
withRetries Word
w = (Word -> Word) -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
(Word -> Word) -> TestDefM a b c -> TestDefM a b c
modifyRetries (Word -> Word -> Word
forall a b. a -> b -> a
const Word
w)
flaky :: Word -> TestDefM a b c -> TestDefM a b c
flaky :: forall (a :: [*]) b c. Word -> TestDefM a b c -> TestDefM a b c
flaky Word
i = Word -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c. Word -> TestDefM a b c -> TestDefM a b c
withRetries Word
i (TestDefM a b c -> TestDefM a b c)
-> (TestDefM a b c -> TestDefM a b c)
-> TestDefM a b c
-> TestDefM a b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlakinessMode -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
FlakinessMode -> TestDefM a b c -> TestDefM a b c
withFlakiness (Maybe String -> FlakinessMode
MayBeFlaky Maybe String
forall a. Maybe a
Nothing)
flakyWith :: Word -> String -> TestDefM a b c -> TestDefM a b c
flakyWith :: forall (a :: [*]) b c.
Word -> String -> TestDefM a b c -> TestDefM a b c
flakyWith Word
i String
message = (Word -> Word) -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
(Word -> Word) -> TestDefM a b c -> TestDefM a b c
modifyRetries (Word -> Word -> Word
forall a b. a -> b -> a
const Word
i) (TestDefM a b c -> TestDefM a b c)
-> (TestDefM a b c -> TestDefM a b c)
-> TestDefM a b c
-> TestDefM a b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlakinessMode -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
FlakinessMode -> TestDefM a b c -> TestDefM a b c
withFlakiness (Maybe String -> FlakinessMode
MayBeFlaky (String -> Maybe String
forall a. a -> Maybe a
Just String
message))
notFlaky :: TestDefM a b c -> TestDefM a b c
notFlaky :: forall (a :: [*]) b c. TestDefM a b c -> TestDefM a b c
notFlaky = FlakinessMode -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
FlakinessMode -> TestDefM a b c -> TestDefM a b c
withFlakiness FlakinessMode
MayNotBeFlaky
potentiallyFlaky :: TestDefM a b c -> TestDefM a b c
potentiallyFlaky :: forall (a :: [*]) b c. TestDefM a b c -> TestDefM a b c
potentiallyFlaky = FlakinessMode -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
FlakinessMode -> TestDefM a b c -> TestDefM a b c
withFlakiness (Maybe String -> FlakinessMode
MayBeFlaky Maybe String
forall a. Maybe a
Nothing)
potentiallyFlakyWith :: String -> TestDefM a b c -> TestDefM a b c
potentiallyFlakyWith :: forall (a :: [*]) b c. String -> TestDefM a b c -> TestDefM a b c
potentiallyFlakyWith String
message = FlakinessMode -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
FlakinessMode -> TestDefM a b c -> TestDefM a b c
withFlakiness (Maybe String -> FlakinessMode
MayBeFlaky (String -> Maybe String
forall a. a -> Maybe a
Just String
message))
withFlakiness :: FlakinessMode -> TestDefM a b c -> TestDefM a b c
withFlakiness :: forall (a :: [*]) b c.
FlakinessMode -> TestDefM a b c -> TestDefM a b c
withFlakiness FlakinessMode
f = ([SpecDefTree a b ()] -> [SpecDefTree a b ()])
-> TestDefM a b c -> TestDefM a b c
forall w (m :: * -> *) a. MonadWriter w m => (w -> w) -> m a -> m a
censor ((SpecDefTree a b () -> [SpecDefTree a b ()] -> [SpecDefTree a b ()]
forall a. a -> [a] -> [a]
: []) (SpecDefTree a b () -> [SpecDefTree a b ()])
-> ([SpecDefTree a b ()] -> SpecDefTree a b ())
-> [SpecDefTree a b ()]
-> [SpecDefTree a b ()]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlakinessMode -> [SpecDefTree a b ()] -> SpecDefTree a b ()
forall (outers :: [*]) inner extra.
FlakinessMode
-> SpecDefForest outers inner extra
-> SpecDefTree outers inner extra
DefFlakinessNode FlakinessMode
f)
expectPassing :: TestDefM a b c -> TestDefM a b c
expectPassing :: forall (a :: [*]) b c. TestDefM a b c -> TestDefM a b c
expectPassing = ExpectationMode -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
ExpectationMode -> TestDefM a b c -> TestDefM a b c
withExpectationMode ExpectationMode
ExpectPassing
expectFailing :: TestDefM a b c -> TestDefM a b c
expectFailing :: forall (a :: [*]) b c. TestDefM a b c -> TestDefM a b c
expectFailing = ExpectationMode -> TestDefM a b c -> TestDefM a b c
forall (a :: [*]) b c.
ExpectationMode -> TestDefM a b c -> TestDefM a b c
withExpectationMode ExpectationMode
ExpectFailing
withExpectationMode :: ExpectationMode -> TestDefM a b c -> TestDefM a b c
withExpectationMode :: forall (a :: [*]) b c.
ExpectationMode -> TestDefM a b c -> TestDefM a b c
withExpectationMode ExpectationMode
em = ([SpecDefTree a b ()] -> [SpecDefTree a b ()])
-> TestDefM a b c -> TestDefM a b c
forall w (m :: * -> *) a. MonadWriter w m => (w -> w) -> m a -> m a
censor ((SpecDefTree a b () -> [SpecDefTree a b ()] -> [SpecDefTree a b ()]
forall a. a -> [a] -> [a]
: []) (SpecDefTree a b () -> [SpecDefTree a b ()])
-> ([SpecDefTree a b ()] -> SpecDefTree a b ())
-> [SpecDefTree a b ()]
-> [SpecDefTree a b ()]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpectationMode -> [SpecDefTree a b ()] -> SpecDefTree a b ()
forall (outers :: [*]) inner extra.
ExpectationMode
-> SpecDefForest outers inner extra
-> SpecDefTree outers inner extra
DefExpectationNode ExpectationMode
em)