Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module is the internal implementation of Test.Cleveland.Tasty.
Synopsis
- newtype RunOnEmulator = RunOnEmulator (Scenario PureM)
- newtype RunOnNetwork = RunOnNetwork (Scenario ClientM)
- newtype TastyEnv = TastyEnv {
- useNetworkEnv :: forall a. (NetworkEnv -> IO a) -> IO a
- newtype TastyEnvOpt = TastyEnvOpt (Maybe TastyEnv)
- lock :: MVar ()
- testScenario :: TestName -> (forall m. Scenario m) -> TestTree
- testScenarioOnNetwork :: TestName -> Scenario ClientM -> TestTree
- testScenarioOnEmulator :: TestName -> Scenario PureM -> TestTree
- clevelandMain :: TestTree -> IO ()
- clevelandMainWithIngredients :: [Ingredient] -> TestTree -> IO ()
- clevelandIngredients :: [Ingredient]
- loadTastyEnv :: TestTree -> TestTree
- whenNetworkEnabled :: ((forall a. (NetworkEnv -> IO a) -> IO a) -> TestTree) -> TestTree
- modifyNetworkEnv :: (NetworkEnv -> NetworkEnv) -> TestTree -> TestTree
- onNetworkTag :: TestName
- printFormattedException :: OptionSet -> SomeException -> IO Result
- tastyEnvFromOpts :: OptionSet -> TastyEnv
- withinCI :: IO Bool
- loadOptionSwitcher :: Bool -> TestTree -> TestTree
- setupTempDatadirIfNeeded :: TestTree -> TestTree
- mkTastyEnv :: IO NetworkEnv -> TastyEnv
- mapTastyEnv :: (NetworkEnv -> NetworkEnv) -> TastyEnv -> TastyEnv
- memoize :: forall a. IO a -> IO (IO a)
- runOnlyNetworkExpr :: Expr
- dontRunNetworkExpr :: Expr
Documentation
newtype RunOnEmulator Source #
Instances
IsTest RunOnEmulator Source # | |
Defined in Test.Cleveland.Tasty.Internal |
newtype RunOnNetwork Source #
Instances
IsTest RunOnNetwork Source # | |
Defined in Test.Cleveland.Tasty.Internal |
This action will:
- Enter a critical section
Either:
- Create a
NetworkEnv
and cache it, if it's the first time being evaluated. - Or reuse an existing cached
NetworkEnv
otherwise.
- Create a
- Pass it to the given
networkEnv -> IO a
function. - Exit the critical section
This ensures:
NetworkEnv
is only created once (it's a relatively expensive operation).- tests that use
NetworkEnv
are run sequentially (see #399, https://gitlab.com/morley-framework/morley/-/issues/399)
TastyEnv | |
|
newtype TastyEnvOpt Source #
A pre-loaded TastyEnv
.
It's not an actual command line option, we use it
so we can load a TastyEnv
once, and then cache it
alongside the other options in tasty's OptionSet
.
Kiiiind of a hack, but it works :D
It is purposefully never registered as a CLI option
(e.g. using testOptions
or includingOptions
)
to make sure it doesn't appear in tasty's --help
.
Instances
IsOption TastyEnvOpt Source # | |
Defined in Test.Cleveland.Tasty.Internal |
A global mutex to ensure only one cleveland test is executed at a time.
TODO [#399]: Remove this when is done. https://gitlab.com/morley-framework/morley/-/issues/399
testScenario :: TestName -> (forall m. Scenario m) -> TestTree Source #
Create a tasty test case from a Scenario
.
This will create a test tree with 2 tests:
one that runs the Scenario
on the Morley.Michelson.Runtime emulator,
and another that runs it on a real Tezos network.
The network config is read from the command line/environment variables.
Use --help
to see the available options.
If a TestTree
contains many tests scheduled to run on a real Tezos network,
those tests will be run sequentially.
testScenarioOnEmulator :: TestName -> Scenario PureM -> TestTree Source #
Create a tasty test case from an emulated Scenario
.
This will create a test tree with 1 test,
which will run the Scenario
on the Morley.Michelson.Runtime emulator.
clevelandMain :: TestTree -> IO () Source #
Similar to tasty
defaultMain
, but also preloads TastyEnv
and
registers the necessary command line options/environment variables to configure
Test.Cleveland.
clevelandMainWithIngredients :: [Ingredient] -> TestTree -> IO () Source #
Similar to defaultMainWithIngredients
, but also preloads TastyEnv
and
registers the necessary command line options/environment variables to configure
Test.Cleveland.
clevelandIngredients :: [Ingredient] Source #
A list with all the ingredients necessary to configure Test.Cleveland.
Note: If a test suite uses Scenario
, the relevant command line options
will be automatically added to tasty's --help
.
However, if a test suite intends to not use those functions, and use whenNetworkEnabled
only, then the CLI options need to be registered manually by using this ingredient
(or clevelandMain
/clevelandMainWithIngredients
).
loadTastyEnv :: TestTree -> TestTree Source #
Pre-load TastyEnv
from the passed command line/environment options,
and store it in tasty's OptionSet
to make it available to
all tests within the test tree.
Creating a NetworkEnv
is a relatively expensive operation, when executed hundreds of times.
This function guarantees that only one TastyEnv
is created for this test tree, and
TastyEnv
will, in turn, guarantee that only one NetworkEnv
is created while the tests are running.
whenNetworkEnabled :: ((forall a. (NetworkEnv -> IO a) -> IO a) -> TestTree) -> TestTree Source #
Runs some tests only when network tests are enabled
(i.e., when running in the CI or when --cleveland-mode all
).
Do not use this with a cleveland test (e.g. with testScenario
), as it will
lead to a deadlock.
This is only suitable for HUnitHspecHedgehog/etc tests.
Example usage:
test :: TestTree test = whenNetworkEnabled $ \withEnv -> testCase "a test name" $ withEnv $ \env -> runMorleyClientM (neMorleyClientEnv env) $ do ...
modifyNetworkEnv :: (NetworkEnv -> NetworkEnv) -> TestTree -> TestTree Source #
Modifies the NetworkEnv
for all the tests in the given test tree.
onNetworkTag :: TestName Source #
A name that we use to tag all tests that run on the network.
We use this in a tasty --pattern
in .gitlab-ci.yml to run only network tests.
printFormattedException :: OptionSet -> SomeException -> IO Result Source #
tastyEnvFromOpts :: OptionSet -> TastyEnv Source #
Creates a TastyEnv
from the passed command line/environment options.
Heuristics to check whether we are running within CI. Check the respective env variable which is usually set in all CIs.
loadOptionSwitcher :: Bool -> TestTree -> TestTree Source #
Helper that checks which environment variables / command line options are set, and filters TestTree to run tests according to the decision table at the top of this module.
mkTastyEnv :: IO NetworkEnv -> TastyEnv Source #
mapTastyEnv :: (NetworkEnv -> NetworkEnv) -> TastyEnv -> TastyEnv Source #
memoize :: forall a. IO a -> IO (IO a) Source #
A thread-safe, lazy, write-once cache.
>>>
action <- memoize (putStrLn "hello" $> 3)
>>>
action
hello 3>>>
action
3
runOnlyNetworkExpr :: Expr Source #
Pattern that enables only network tests, all emulator tests will be disabled.
Tasty pattern eDSL version of "$1 == "On network" || $NF == "On network" || $0 ~ .On network."
dontRunNetworkExpr :: Expr Source #
Pattern that disables all network tests, all other tests will be enabled.
Tasty pattern eDSL version of "$1 != "On network" && $NF != "On network" && $0 !~ .On network."