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

Moduletasty-inspection-testing-0.2.1Haskell2010

Test.Tasty.Inspection

Integrate inspection-testing into tasty test suites.

  • 2 types
  • 16 values
valueinspectTest :: Obligation -> Q Exp
#

Create a tasty TestTree from an Obligation:

{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -O -dsuppress-all -dno-suppress-type-signatures -fplugin=Test.Tasty.Inspection.Plugin #-}

import Test.Tasty
import Test.Tasty.Inspection

lhs :: (a -> b) -> Maybe a -> Bool
lhs f x = case fmap f x of
  Nothing -> True
  Just{}  -> False

rhs :: (a -> b) -> Maybe a -> Bool
rhs _ Nothing = True
rhs _ Just{}  = False

main :: IO ()
main = defaultMain $(inspectTest $ 'lhs === 'rhs)

This is not the same function as Test.Inspection.inspectTest: both return Q Exp, but this one represents TestTree instead of Result.

If you are unhappy with an autogenerated test name, amend it using testName:

inspectTest (obl { testName = Just "foo" })

To invert an obligation apply Test.Tasty.ExpectedFailure.expectFail.

Obligations

15 declarations

Mostly reexported from Test.Inspection.

datadata Obligation
#

This data type describes an inspection testing obligation.

It is recommended to build it using mkObligation, for backwards compatibility when new fields are added. You can also use the more mnemonic convenience functions like (===) or hasNoType.

The obligation needs to be passed to inspect or inspectTest.

Instances1Data
datadata Property
#

Properties of the obligation target to be checked.

Constructors

  • EqualTo Name Equivalence

    Are the two functions equal?

    More precisely: f is equal to g if either the definition of f is f = g, or the definition of g is g = f, or if the definitions are f = e and g = e.

    In general f and g need to be defined in this module, so that their actual defintions can be inspected.

    The Equivalence indicates how strict to check for equality

  • NoTypes [Name]

    Do none of these types appear anywhere in the definition of the function (neither locally bound nor passed as arguments)

  • NoAllocation

    Does this function perform no heap allocations.

  • NoTypeClasses [Name]

    Does this value contain dictionaries (except of the listed classes).

  • NoUseOf [Name]

    Does not contain this value (in terms or patterns)

  • CoreOf

    Always satisfied, but dumps the value in non-quiet mode.

Instances1Data
  • Data PropertyDefined in inspection-testing-0.6.2 · Test.Inspection
value(==-) :: Name -> Name -> Obligation
#

Declare two functions to be equal, but ignoring type lambdas, type arguments, type casts and hpc ticks (see EqualTo). Note that -fhpc can prevent some optimizations; build without for more reliable analysis.

valuehasNoType :: Name -> Name -> Obligation
#

Declare that in a function’s implementation, the given type does not occur.

More precisely: No locally bound variable (let-bound, lambda-bound or pattern-bound) has a type that contains the given type constructor.

inspect $ fusedFunction `hasNoType` ''[]

Declare that a function’s implementation does not contain any generic types. This is just hasNoType applied to the usual type constructors used in GHC.Generics.

inspect $ hasNoGenerics genericFunction

Declare that a function's implementation does not include dictionaries.

More precisely: No locally bound variable (let-bound, lambda-bound or pattern-bound) has a type that contains a type that mentions a type class.

inspect $ hasNoTypeClasses specializedFunction
valuedoesNotUse :: Name -> Name -> Obligation
#

Declare that a function's implementation does not use the given variable (either in terms or -- if it is a constructor -- in patterns).

inspect $ foo `doesNotUse` 'error