| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.Cleveland.Tasty.Internal
Description
This module is the internal implementation of Test.Cleveland.Tasty.
Synopsis
- clevelandMain :: TestTree -> IO ()
- clevelandMainWithIngredients :: [Ingredient] -> TestTree -> IO ()
- clevelandIngredients :: [Ingredient]
- loadTastyEnv :: TestTree -> TestTree
- testScenario :: TestName -> (forall m. MonadFail m => Scenario m) -> TestTree
- testScenarioOnEmulator :: TestName -> Scenario PureM -> TestTree
- testScenarioOnNetwork :: TestName -> Scenario ClientM -> TestTree
- whenNetworkEnabled :: ((forall a. (NetworkEnv -> IO a) -> IO a) -> TestTree) -> TestTree
- modifyNetworkEnv :: (NetworkEnv -> NetworkEnv) -> TestTree -> TestTree
- setAliasPrefix :: Text -> TestTree -> TestTree
- newtype RunOnNetwork = RunOnNetwork (Scenario ClientM)
- newtype RunOnEmulator = RunOnEmulator (Scenario PureM)
- tastyEnvFromOpts :: OptionSet -> TastyEnv
- onNetworkTag :: TestName
- newtype TastyEnvOpt = TastyEnvOpt (Maybe TastyEnv)
- newtype TastyEnv = TastyEnv {
- useNetworkEnv :: forall a. (NetworkEnv -> IO a) -> IO a
- mkTastyEnv :: IO NetworkEnv -> TastyEnv
- mapTastyEnv :: (NetworkEnv -> NetworkEnv) -> TastyEnv -> TastyEnv
- memoize :: forall a. IO a -> IO (IO a)
- loadOptionSwitcher :: Bool -> TestTree -> TestTree
Main
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.
Test cases
testScenario :: TestName -> (forall m. MonadFail 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.
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
...Reading/setting options
modifyNetworkEnv :: (NetworkEnv -> NetworkEnv) -> TestTree -> TestTree Source #
Modifies the NetworkEnv for all the tests in the given test tree.
setAliasPrefix :: Text -> TestTree -> TestTree Source #
Overrides the alias prefix (parsed from --cleveland-alias-prefix or TASTY_CLEVELAND_ALIAS_PREFIX)
for all the tests in the given test tree.
Internals
newtype RunOnNetwork Source #
Constructors
| RunOnNetwork (Scenario ClientM) |
Instances
| IsTest RunOnNetwork Source # | |
Defined in Test.Cleveland.Tasty.Internal | |
newtype RunOnEmulator Source #
Constructors
| RunOnEmulator (Scenario PureM) |
Instances
| IsTest RunOnEmulator Source # | |
Defined in Test.Cleveland.Tasty.Internal | |
tastyEnvFromOpts :: OptionSet -> TastyEnv Source #
Creates a TastyEnv from the passed command line/environment options.
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.
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.
Constructors
| TastyEnvOpt (Maybe TastyEnv) |
Instances
| IsOption TastyEnvOpt Source # | |
Defined in Test.Cleveland.Tasty.Internal Methods parseValue :: String -> Maybe TastyEnvOpt # optionName :: Tagged TastyEnvOpt String # optionHelp :: Tagged TastyEnvOpt String # showDefaultValue :: TastyEnvOpt -> Maybe String # | |
This action will:
- Enter a critical section
Either:
- Create a
NetworkEnvand cache it, if it's the first time being evaluated. - Or reuse an existing cached
NetworkEnvotherwise.
- Create a
- Pass it to the given
networkEnv -> IO afunction. - Exit the critical section
This ensures:
NetworkEnvis only created once (it's a relatively expensive operation).- tests that use
NetworkEnvare run sequentially (see #399, https://gitlab.com/morley-framework/morley/-/issues/399)
Constructors
| TastyEnv | |
Fields
| |
mkTastyEnv :: IO NetworkEnv -> TastyEnv Source #
mapTastyEnv :: (NetworkEnv -> NetworkEnv) -> TastyEnv -> TastyEnv Source #