HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Moduletasty-hspec-1.2.0.4Haskell2010

Test.Tasty.Hspec

hspec and tasty serve similar purposes; consider using one or the other.

However, in a pinch, this module allows you to run an hspec H.Spec as a tasty T.TestTree.

Contents
  1. Tests
  2. Options
  3. Examples
Synopsis

Tests

Options

datadata TreatPendingAs

How to treat hspec pending tests.

tasty does not have the concept of pending tests, so we must map them to either successes or failures. By default, they are treated as failures.

Set via the command line flag --treat-pending-as (success|failure).

Instances1IsOption

Examples

The simplest usage of this library involves first creating a T.TestTree in IO, then running it with T.defaultMain.

main = do
  spec <- testSpec "spec" mySpec
  T.defaultMain
    (T.testGroup "tests"
      [ spec
      , ...
      ])

You can treat an H.pending/H.pendingWith test as a success instead of a failure (the default):

tests :: TestTree
tests =
  localOption TreatPendingAsSuccess $ testGroup "My Hspec TestTree"
    [ unsafePerformIO (testSpec "My first Hspec test" spec_firstHspecTest)
    , ...
    ]

If you don't do any IO during Spec creation, or the IO need not be performed at any particular time relative to other IO actions, it's perfectly fine to use System.IO.unsafePerformIO.

main = do
  T.defaultMain
    (T.testGroup "tests"
      [ System.IO.unsafePerformIO (testSpec "spec" mySpec)
      , ...
      ])