Safe Haskell | None |
---|---|
Language | Haskell2010 |
Usage
Write your tests
You can use any object deriving from Show and Eq as an argument for tests. ==== Normal Tests In any file, you can specify tests above a function declaration, like:
--[list of args] [exceptedResult] --[1 2] [3] add x y = x+y
Overrided tests
With this syntax, testCom will only compare the two provided expression
--O[Expression with the same type than the result] [exceptedResult] --O[add 1 2] [3] add x y = x+y
Tests by specification
--S[expressionInvolvingYourFunction] [OtherExpression] [Integer] --S[xInt y
Int] [x+ y
] [100] add x y = x+y
Here, testCom will build N tests with random arguments (specified by nameOfTheArgs@Type). Random arguments MUST be separated by spaces. For now, only base types are supported: Char, Int and Bool
Build your tests
Later, on your test file, you can build tests functions with
{-# LANGUAGE TemplateHaskell #-} $(makeAllTests "some/Path/File.hs")
and use the produced function in your main:
import System.Exit main :: IO () main = do let (str,res) = _TEST_some_Path_File putStrLn str if res then exitSuccess else exitFailure
If you want to make tests on the actual file, you can use
$(makeAllTestsHere)
the function produced will be equivalent to the one produced by
$(makeAllTests "path/to/file/known/by/ghc")
String produced
Considering the given file:
--[1 2] [3] --[1 2] [4] add x y = x+y
The string produced will be:
Test passed: add 1 2 == 3 Error: add 1 2 /= 4 BUT == 3
- makeAllTests :: FilePath -> Q [Dec]
- makeAllTestsHere :: Q [Dec]
Documentation
makeAllTests :: FilePath -> Q [Dec] Source #
With a path like some/Path/File.hs, Create a function
_TEST_some_Path_File :: (String,Bool)
with the string containing the result of all tests, and the boolean set to True
if and only if all tests passed
This also create sub-functions that each produce a Eihter String String
makeAllTestsHere :: Q [Dec] Source #