Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module allows the use of Test.Cleveland tests in tasty
.
These tests can be run on:
- the Morley.Michelson.Runtime emulator using
testScenarioOnEmulator
/scenarioEmulated
- both on the emulator and a real Tezos network using
testScenario
/scenario
.
whenNetworkEnabled
can be used to write tests that need
to run a Tezos network, but are not necessarily written using Test.Cleveland.
If a TestTree
contains many tests scheduled to run on a real Tezos network,
those tests will be run sequentially.
Example:
import Test.Cleveland import Test.Cleveland.Tasty main :: IO () main = clevelandMain test test :: TestTree test = testScenario "storage is 1" $ scenario do addr <- originate OriginateData {..} getStorage addr @@== 1
A cleveland/tasty test suite can be run in one of three modes, by setting either the --cleveland-mode
command line option or the TASTY_CLEVELAND_MODE
environment variable to:
all
- runs all tests: non-cleveland tests, cleveland emulator tests and cleveland network tests.disable-network
- skips cleveland network tests.only-network
- runs only cleveland network tests and skips all other tests.
In a CI environment (i.e. if the CI
environment variable is set to true
(case-insensitive) or 1
),
the default mode is all
.
Otherwise, the default mode is disable-network
.
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
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.