cleveland-0.1.2: Testing framework for Morley.
Safe HaskellNone
LanguageHaskell2010

Test.Cleveland.Tasty.Internal

Description

This module is the internal implementation of Test.Cleveland.Tasty.

Synopsis

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.

testScenarioOnNetwork :: TestName -> Scenario ClientM -> TestTree Source #

Create a tasty test case from a Scenario.

This will create a test tree with 1 test, which will run the Scenario on real Tezos network.

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

Instances details
IsTest RunOnNetwork Source # 
Instance details

Defined in Test.Cleveland.Tasty.Internal

newtype RunOnEmulator Source #

Constructors

RunOnEmulator (Scenario PureM) 

Instances

Instances details
IsTest RunOnEmulator Source # 
Instance details

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) 

newtype TastyEnv Source #

This action will:

  1. Enter a critical section
  2. Either:

    • Create a NetworkEnv and cache it, if it's the first time being evaluated.
    • Or reuse an existing cached NetworkEnv otherwise.
  3. Pass it to the given networkEnv -> IO a function.
  4. Exit the critical section

This ensures:

Constructors

TastyEnv 

Fields

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

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.