HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulesydtest-0.22.0.0Haskell2010

Test.Syd.Def.AroundAll

This module defines all the functions you will use to define your test suite.

  • 11 values
  • Packagesydtest-0.22.0.0
  • Exports11
  • LanguageHaskell2010
  • LicenceLicenseRef-OtherLicense
  • SourceAroundAll.hs
valuebeforeAll_
  1. :: IO ()

    The function to run (once), beforehand.

  2. -> TestDefM outers inner result
  3. -> TestDefM outers inner result
#

Run a custom action before all spec items in a group without setting up any outer resources.

valuebeforeAll
  1. :: IO outer

    The function to run (once), beforehand, to produce the outer resource.

  2. -> TestDefM (outer ': otherOuters) inner result
  3. -> TestDefM otherOuters inner result
#

Run a custom action before all spec items in a group, to set up an outer resource a.

valuebeforeAllWith
  1. :: (previousOuter -> IO newOuter)

    The function to run (once), beforehand, to produce a new outer resource while using a previous outer resource

  2. -> TestDefM (newOuter ': previousOuter ': otherOuters) inner result
  3. -> TestDefM (previousOuter ': otherOuters) inner result
#

Run a custom action before all spec items in a group, to set up an outer resource b by using the outer resource a.

valueafterAll_
  1. :: IO ()

    The function to run (once), afterwards.

  2. -> TestDefM outers inner result
  3. -> TestDefM outers inner result
#

Run a custom action after all spec items without using any outer resources.

valueafterAll
  1. :: (outer -> IO ())

    The function to run (once), afterwards, using the outer resource.

  2. -> TestDefM (outer ': otherOuters) inner result
  3. -> TestDefM (outer ': otherOuters) inner result
#

Run a custom action after all spec items, using the outer resource a.

valueafterAll'
  1. :: (HList outers -> IO ())

    The function to run (once), afterwards, using all outer resources.

  2. -> TestDefM outers inner result
  3. -> TestDefM outers inner result
#

Run a custom action after all spec items, using all the outer resources.

valuearoundAll_
  1. :: (IO () -> IO ())

    The function that wraps running the tests.

  2. -> TestDefM outers inner result
  3. -> TestDefM outers inner result
#

Run a custom action before and/or after all spec items in a group without accessing any resources.

FOOTGUN

This combinator gives the programmer a lot of power. In fact, it gives the programmer enough power to break the test framework. Indeed, you can provide a wrapper function that just _doesn't_ run the function like this:

spec :: Spec
spec = do
   let don'tDo :: IO () -> IO ()
       don'tDo _ = pure ()
   aroundAll_ don'tDo $ do
     it "should pass" True

During execution, you'll then get an error like this:

thread blocked indefinitely in an MVar operation

The same problem exists when using around_.

Something even more pernicious goes wrong when you run the given action more than once like this:

spec :: Spec
spec = do
   let doTwice :: IO () -> IO ()
       doTwice f = f >> f
   aroundAll_ doTwice $ do
     it "should pass" True

In this case, the test will "just work", but it will be executed twice even if the output reports that it only passed once.

Note: If you're interested in fixing this, talk to me, but only after GHC has gotten impredicative types because that will likely be a requirement.

valuearoundAll
  1. :: ((outer -> IO ()) -> IO ())

    The function that provides the outer resource (once), around the tests.

  2. -> TestDefM (outer ': otherOuters) inner result
  3. -> TestDefM otherOuters inner result
#

Run a custom action before and/or after all spec items in group, to provide access to a resource a.

See the FOOTGUN note in the docs for around_.

valuearoundAllWith
  1. :: ((newOuter -> IO ()) -> oldOuter -> IO ())

    The function that provides the new outer resource (once), using the old outer resource.

  2. -> TestDefM (newOuter ': oldOuter ': otherOuters) inner result
  3. -> TestDefM (oldOuter ': otherOuters) inner result
#

Run a custom action before and/or after all spec items in a group to provide access to a resource a while using a resource b

See the FOOTGUN note in the docs for around_.

valuearoundAllWithAll
  1. :: ((newOuter -> IO ()) -> HList (oldOuter ': otherOuters) -> IO ())

    The function that provides the new outer resource (once), using the old outer resource.

  2. -> TestDefM (newOuter ': oldOuter ': otherOuters) inner result
  3. -> TestDefM (oldOuter ': otherOuters) inner result
#

Run a custom action before and/or after all spec items in a group to provide access to a resource a while using all outer resources.