tasty-th-0.1.7: Automatic tasty test case discovery using TH

Safe HaskellNone
LanguageHaskell98

Test.Tasty.TH

Description

This module provides TemplateHaskell functions to automatically generate tasty TestTrees from specially named functions. See the README of the package for examples.

Important: due to to the GHC staging restriction, you must put any uses of these functions at the end of the file, or you may get errors due to missing definitions.

Synopsis

Documentation

testGroupGenerator :: ExpQ Source

This function generates a TestTree from functions in the current module. The test tree is named after the current module.

The following definitions are collected by testGroupGenerator:

  • a test_something definition in the current module creates a sub-testGroup with the name "something"
  • a prop_something definition in the current module is added as a QuickCheck property named "something"
  • a case_something definition leads to a HUnit-Assertion test with the name "something"

Example usage:

prop_example :: Int -> Int -> Bool
prop_example a b = a + b == b + a

tests :: TestTree
tests = $(testGroupGenerator)

defaultMainGenerator :: ExpQ Source

Convenience function that directly generates an IO action that may be used as the main function. It's just a wrapper that applies defaultMain to the TestTree generated by testGroupGenerator.

Example usage:

-- properties, test cases, ....

main :: IO ()
main = $(defaultMainGenerator)

testGroupGeneratorFor Source

Arguments

:: String

The name of the test group itself

-> [String]

The names of the functions which should be included in the test group

-> ExpQ 

Like testGroupGenerator, but generates a test group only including the specified function names. The function names still need to follow the pattern of starting with one of prop_, case_ or test_.

defaultMainGeneratorFor Source

Arguments

:: String

The name of the top-level test group

-> [String]

The names of the functions which should be included in the test group

-> ExpQ 

Like defaultMainGenerator, but only includes the specific function names in the test group. The function names still need to follow the pattern of starting with one of prop_, case_ or test_.

extractTestFunctions :: FilePath -> IO [String] Source

Retrieves all function names from the given file that would be discovered by testGroupGenerator.

locationModule :: ExpQ Source

Extract the name of the current module.