Run the spec, configuring the options from the command line.
Modulesandwich-0.3.1.0Haskell2010
Test.Sandwich
- 1 type
- 30 values
- Packagesandwich-0.3.1.0
- Exports31
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceSandwich.hs
Sandwich is a test framework for Haskell. See the documentation for details and usage examples.
Running tests with command line args
3 declarationsThese functions will read command line arguments when setting up your tests. These flags allow you filter the test tree, configure formatters, and pass your own custom options.
# Run using the terminal UI formatter, webdriver headless mode, filtering to nodes matching "Login"
stack run my-tests -- --tui --headless -f Login
Run the spec, configuring the options from the command line and adding user-configured command line options. The options will become available as a test context, which you can access by calling getCommandLineOptions.
Running tests
2 declarationsRun the spec with the given Options.
Run the spec with optional custom CommandLineOptions. When finished, return the exit reason, the number of "it" nodes which failed, and the total failed nodes (which includes "it" nodes, and may also include other nodes like "introduce" nodes).
Basic nodes
3 declarationsThe basic building blocks of tests.
it :: HasCallStack=> StringLabel for the example.
-> ExampleT context m ()The test example
-> Free (SpecCommand context m) ()
Define a single test example.
describe :: HasCallStack=> StringLabel for this group
-> SpecFree context m ()Child spec tree
-> SpecFree context m ()
Define a group of tests.
Run a group of tests in parallel.
Context manager nodes
8 declarationsFor introducing new contexts into tests and doing setup/teardown.
introduce :: (HasCallStack, Typeable intro)=> StringString label for this node
-> Label l introLabel under which to introduce the value
-> ExampleT context m introAction to produce the new value (of type
intro)-> (HasCallStack => intro -> ExampleT context m ())Action to clean up the new value
-> SpecFree (LabelValue l intro :> context) m ()Child spec tree
-> SpecFree context m ()
Introduce a new value and make it available to the child spec tree.
introduceWith :: HasCallStack=> StringString label for this node
-> Label l introLabel under which to introduce the value
-> ((HasCallStack => intro -> ExampleT context m [Result]) -> ExampleT context m ())Callback to receive the new value and the child tree.
-> SpecFree (LabelValue l intro :> context) m ()Child spec tree
-> SpecFree context m ()
Introduce a new value in an around fashion, so it can be used with context managers like withFile or bracket.
before :: HasCallStack=> StringLabel for this context manager
-> ExampleT context m ()Action to perform
-> SpecFree context m ()Child spec tree
-> SpecFree context m ()
Perform an action before a given spec tree.
beforeEach :: HasCallStack=> StringString label for this context manager
-> ExampleT context m ()Action to perform
-> SpecFree context m ()Child spec tree
-> SpecFree context m ()
after :: HasCallStack=> StringLabel for this context manager
-> ExampleT context m ()Action to perform
-> SpecFree context m ()Child spec tree
-> SpecFree context m ()
Perform an action after a given spec tree.
around Run an action around the given child subtree. Useful for context managers like withFile or bracket.
aroundEach Parallel nodes
7 declarationsWrapper around parallel. Introduces a semaphore to limit the parallelism to N threads.
parallelN' :: MonadUnliftIO m=> NodeOptionsNode options
-> IntNumber of threads
-> SpecFree (LabelValue"parallelSemaphore"
QSem :> context) m ()-> SpecFree context m ()
parallelNFromArgs :: (MonadUnliftIO m, HasCommandLineOptions context a)=> (CommandLineOptions a -> Int)Callback to extract the semaphore size
-> SpecFree (LabelValue"parallelSemaphore"
QSem :> context) m ()-> SpecFree context m ()
Same as parallelN, but extracts the semaphore size from the command line options.
parallelNFromArgs' :: (MonadUnliftIO m, HasCommandLineOptions context a)=> NodeOptionsNode options
-> (CommandLineOptions a -> Int)Callback to extract the semaphore size
-> SpecFree (LabelValue"parallelSemaphore"
QSem :> context) m ()-> SpecFree context m ()
Timing
4 declarationsFor timing actions within your tests. Test tree nodes are timed by default.
timeActionByProfile :: (MonadUnliftIO m, MonadReader context m, HasTestTimer context)=> ProfileNameProfile name
-> EventNameEvent name
-> m a-> m a
Time a given action with a given profile name and event name. Use when you want to manually specify the profile name.
timeAction :: (MonadUnliftIO m, HasBaseContextMonad context m, HasTestTimer context)=> EventNameEvent name
-> m a-> m a
Time a given action with a given event name. This name will be the "stack frame" of the given action in the profiling results. This function will use the current timing profile name.
withTimingProfile :: Monad m=> ProfileNameProfile name
-> SpecFree (LabelValue"testTimerProfile"
TestTimerProfile :> context) m ()-> SpecFree context m ()
Introduce a new timing profile name.
withTimingProfile' Introduce a new timing profile name dynamically. The given ExampleT should come up with the name and return it.
Managed async
4 declarationsIf you want to run asyncs within your tests, we can help keep track of them and make sure they get cleaned up.
Launch a managed async thread, tracking it with the run ID from BaseContext.
Like managedAsync, but the action receives an unmask function.
Run a managed async thread scoped to a callback.
Like managedWithAsync, but ignores the Async handle.
Exports
0 declarationsmodule Test.Sandwich.Contexts
module Test.Sandwich.Expectations
module Test.Sandwich.Logging
module Test.Sandwich.Misc
module Test.Sandwich.Nodes
module Test.Sandwich.Options
module Test.Sandwich.TH