Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- defaultMain :: TestTree -> IO ()
- defaultMainWithIngredients :: [Ingredient] -> TestTree -> IO ()
- defaultIngredients :: [Ingredient]
- rerunningTests :: [Ingredient] -> Ingredient
- testGroup :: TestName -> [TestTree] -> TestTree
- testCase :: TestName -> Assertion -> TestTree
- shouldBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
- shouldSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
- shouldReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
- testProperty :: TestName -> Property -> TestTree
- module Hedgehog
Running tests
defaultMain :: TestTree -> IO () #
Parse the command line arguments and run the tests.
When the tests finish, this function calls exitWith
with the exit code
that indicates whether any tests have failed. Most external systems
(stack, cabal, travis-ci, jenkins etc.) rely on the exit code to detect
whether the tests pass. If you want to do something else after
defaultMain
returns, you need to catch the exception and then re-throw
it. Example:
import Test.Tasty import Test.Tasty.HUnit import System.Exit import Control.Exception test = testCase "Test 1" (2 @?= 3) main = defaultMain test `catch` (\e -> do if e == ExitSuccess then putStrLn "Yea" else putStrLn "Nay" throwIO e)
defaultMainWithIngredients :: [Ingredient] -> TestTree -> IO () #
Parse the command line arguments and run the tests using the provided ingredient list.
When the tests finish, this function calls exitWith
with the exit code
that indicates whether any tests have failed. See defaultMain
for
details.
defaultIngredients :: [Ingredient] #
List of the default ingredients. This is what defaultMain
uses.
At the moment it consists of listingTests
and consoleTestReporter
.
rerunningTests :: [Ingredient] -> Ingredient #
This Ingredient
transformer adds various --rerun
options to your
test program. These flags add stateful execution of your test suite, allowing
you to rerun only tests that are failing from the previous run, or tests that
that have been added since the last test ran, once the TestTree
has
been filtered.
The input list of Ingredient
s specifies the Ingredients
s that
will actually work with the filtered TestTree
. Normally, you'll want
at least consoleTestReporter
.
Unit tests
shouldBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation infix 1 #
actual `shouldBe` expected
sets the expectation that actual
is equal
to expected
.
shouldSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation infix 1 #
v `shouldSatisfy` p
sets the expectation that p v
is True
.
shouldReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation infix 1 #
action `shouldReturn` expected
sets the expectation that action
returns expected
.
Property tests
module Hedgehog