th-test-utils-1.1.0: Utility functions for testing Template Haskell code

MaintainerBrandon Chinn <brandon@leapyear.io>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Language.Haskell.TH.TestUtils

Contents

Description

This module defines utilites for testing Template Haskell code.

Synopsis

Configuring TestQ

data QState (mode :: MockedMode) Source #

State information for mocking Q functionality.

Constructors

QState 

Fields

Instances
Show (QState mode) Source # 
Instance details

Defined in Language.Haskell.TH.TestUtils.QState

Methods

showsPrec :: Int -> QState mode -> ShowS #

show :: QState mode -> String #

showList :: [QState mode] -> ShowS #

Lift (QState mode) Source # 
Instance details

Defined in Language.Haskell.TH.TestUtils.QState

Methods

lift :: QState mode -> Q Exp #

data QMode (mode :: MockedMode) where Source #

Constructors

MockQ :: QMode FullyMocked

All Q actions are mocked and IO actions are disallowed.

MockQAllowIO :: QMode FullyMockedWithIO

Same as MockQ, except IO actions are passed through. Useful if your TH code, for example, reads files with runIO.

AllowQ :: QMode NotMocked

No mocking is done. Useful for running Q as normal, but you need to get error messages.

Instances
Show (QMode mode) Source # 
Instance details

Defined in Language.Haskell.TH.TestUtils.QMode

Methods

showsPrec :: Int -> QMode mode -> ShowS #

show :: QMode mode -> String #

showList :: [QMode mode] -> ShowS #

Lift (QMode mode) Source # 
Instance details

Defined in Language.Haskell.TH.TestUtils.QMode

Methods

lift :: QMode mode -> Q Exp #

loadNames :: [Name] -> ExpQ Source #

A helper for loading names for reifyInfo

Usage:

QState
  { reifyInfo = $(loadNames [''Int, ''Maybe])
  , ...
  }

unmockedState :: QState NotMocked Source #

A shortcut for defining an unmocked Q.

Running TestQ

runTestQ :: forall mode a. IsMockedMode mode => QState mode -> Q a -> TestQResult mode a Source #

runTestQErr :: forall mode a. (IsMockedMode mode, Show a) => QState mode -> Q a -> TestQResult mode String Source #

tryTestQ :: forall mode a. IsMockedMode mode => QState mode -> Q a -> TestQResult mode (Either String a) Source #