Test.Torch is a simple library (or framework) for unit test.
I assume You want to implement a function that can't find way to test using QuickCheck because for example return type is wrapped by IO or some monads, but for some arguments, you know collect return values. It is time to use Test.Torch. let its function like this:
f :: Int -> IO Bool f n = some_complecated_process
And you know that f 1 is same as return True, and f 0 is same as return False.
You can write unit test monadic way (this monad is acutually Writer monad, and Tests are treated as Monoid).
test_for_f = do b <- liftIO $ f 1 -- you can do IO Action in test using liftIO ok b "f 1 is same as return True" b' <- liftIO $ f 0 notOk b' "f 2 is same as return False"
Then run it.
test = run test_for_f
Test report is displayed to terminal. If second test failed,
Running 2 tests. .f 1 test(s) failed. f 2 is same as return False: failed.
This output means that f 2 returned True.
If all tests are passed,
Running 2 tests. .. Ok, All tests passed.
ok True "'ok' succeeds if given value is True" notOk False "'notOk' succeeds if given value is False"
Second String argument is the test's name, this is used for telling you what test failed if test was failed usually (and every predefined tests in this module, requires test's name).
is 1 1 "test that checks 1 == 1" isn't 1 2 "test that checks 1 /= 2" is (fact 10) 3628800 "check if factorial function works..."
isBottom undefined "for example, this test succeeds"
run takes a builder (do block contains some tests such as is or notOk), and build test from builder, run it, and report to stdout.
|Produced by Haddock version 2.4.2|