-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple unit test library (or framework) -- -- Unit test writing and running with writer monads. @package torch @version 0.1 module Test.Torch.Types class Test t run :: (Test t, MonadIO io) => t -> io Result class Failure f describe :: (Failure f) => f -> FailReason data Result Pass :: Result Fail :: f -> Result type FailReason = String data SomeTest SomeTest :: t -> SomeTest type Tests = [SomeTest] data SomeFailure SomeFailure :: f -> SomeFailure type Failures = [SomeFailure] data Report Report :: Int -> Int -> Int -> Failures -> Report planed :: Report -> Int passed :: Report -> Int failed :: Report -> Int failures :: Report -> Failures data Hook Hook :: IO () -> (SomeFailure -> IO ()) -> (Tests -> IO ()) -> (Report -> IO ()) -> Hook hook_Pass :: Hook -> IO () hook_Fail :: Hook -> SomeFailure -> IO () hook_Pre :: Hook -> Tests -> IO () hook_Post :: Hook -> Report -> IO () module Test.Torch.Types.Instances data Ok Ok :: Bool -> Ok data Is Is :: Bool -> a -> a -> Is data Named Named :: String -> t -> Named data IsBottom IsBottom :: Bool -> a -> IsBottom data SimpleFailure SimpleFailure :: SimpleFailure data UnexpectedValue UnexpectedValue :: Bool -> a -> a -> UnexpectedValue data Bottom Bottom :: SomeException -> Bottom instance Failure SomeFailure instance Failure Bottom instance Failure NamedFailure instance Failure UnexpectedValue instance Failure SimpleFailure instance Test IsBottom instance Test Named instance Test Is instance Test Ok module Test.Torch.Build addTest :: (Test t) => t -> Builder () getTests :: Builder a -> IO Tests ok :: Bool -> String -> Builder () -- | ok and notOk are test for assertion, take a Bool value, -- and then check whether the value is equal to True or False. -- --
--   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). notOk :: Bool -> String -> Builder () is :: (Eq a, Show a) => a -> a -> String -> Builder () -- | is and isn't are test for equality. First argument is -- treated as gotten value, and second is expected value. -- --
--   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..."
--   
isn't :: (Eq a, Show a) => a -> a -> String -> Builder () isBottom :: (NFData a) => a -> String -> Builder () -- | isBottom and isn'tBottom evaluates given value, and -- check if it is Bottom (undefined, error, or some exeptions). -- --
--   isBottom undefined "for example, this test succeeds"
--   
isn'tBottom :: (NFData a) => a -> String -> Builder () data Builder a runBuilder :: Builder a -> WriterT Tests IO a instance Monad Builder instance MonadIO Builder instance MonadWriter Tests Builder module Test.Torch.Hook asHook :: HookWriter a -> Hook onPass :: IO () -> HookWriter () onFail :: (SomeFailure -> IO ()) -> HookWriter () beforeTest :: (Tests -> IO ()) -> HookWriter () afterTest :: (Report -> IO ()) -> HookWriter () zeroHook :: Hook instance Monad HookWriter instance MonadWriter Hook HookWriter instance Monoid Hook module Test.Torch.Report data Report Report :: Int -> Int -> Int -> Failures -> Report planed :: Report -> Int passed :: Report -> Int failed :: Report -> Int failures :: Report -> Failures makeReportWithHook :: (MonadIO io) => Tests -> Hook -> io Report zeroHook :: Hook module Test.Torch.Run -- | 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. -- -- You can define your own run, see makeReportWithHook. run :: Builder a -> IO () -- | Test.Torch is a simple library (or framework) for unit test. -- -- As Library: -- -- 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.
--   
-- -- Output this. -- -- As Framework: -- -- If you think this is not a good format, You can improve output format. -- define some Hook, call it with your test by -- makeReportWithHook. Hook also has monadic interface. -- -- And you can also create your own test constructor, with defining -- Test, Failure, and some Builder. module Test.Torch ok :: Bool -> String -> Builder () -- | ok and notOk are test for assertion, take a Bool value, -- and then check whether the value is equal to True or False. -- --
--   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). notOk :: Bool -> String -> Builder () is :: (Eq a, Show a) => a -> a -> String -> Builder () -- | is and isn't are test for equality. First argument is -- treated as gotten value, and second is expected value. -- --
--   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..."
--   
isn't :: (Eq a, Show a) => a -> a -> String -> Builder () isBottom :: (NFData a) => a -> String -> Builder () -- | isBottom and isn'tBottom evaluates given value, and -- check if it is Bottom (undefined, error, or some exeptions). -- --
--   isBottom undefined "for example, this test succeeds"
--   
isn'tBottom :: (NFData a) => a -> String -> Builder () -- | 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. -- -- You can define your own run, see makeReportWithHook. run :: Builder a -> IO ()