-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A unit testing framework for Haskell -- @package HUnit @version 1.3.0.0 -- | This module handles the complexities of writing information to the -- terminal, including modifying text in place. module Test.HUnit.Terminal -- | Simplifies the input string by interpreting \r and -- \b characters specially so that the result string has the -- same final (or terminal, pun intended) appearance as would the -- input string when written to a terminal that overwrites character -- positions following carriage returns and backspaces. terminalAppearance :: String -> String module Test.HUnit.Lang -- | When an assertion is evaluated, it will output a message if and only -- if the assertion fails. -- -- Test cases are composed of a sequence of one or more assertions. type Assertion = IO () -- | Unconditionally signals that a failure has occured. All other -- assertions can be expressed with the form: -- --
-- if conditionIsMet -- then IO () -- else assertFailure msg --assertFailure :: String -> Assertion data Location Location :: FilePath -> Int -> Int -> Location locationFile :: Location -> FilePath locationLine :: Location -> Int locationColumn :: Location -> Int data Result Success :: Result Failure :: (Maybe Location) -> String -> Result Error :: (Maybe Location) -> String -> Result -- | Performs a single test case. performTestCase :: Assertion -> IO Result data HUnitFailure HUnitFailure :: (Maybe Location) -> String -> HUnitFailure instance Typeable HUnitFailure instance Eq Location instance Ord Location instance Show Location instance Eq HUnitFailure instance Ord HUnitFailure instance Show HUnitFailure instance Eq Result instance Ord Result instance Show Result instance Exception HUnitFailure -- | Basic definitions for the HUnit library. -- -- This module contains what you need to create assertions and test cases -- and combine them into test suites. -- -- This module also provides infrastructure for implementing test -- controllers (which are used to execute tests). See -- Test.HUnit.Text for a great example of how to implement a test -- controller. module Test.HUnit.Base -- | The basic structure used to create an annotated tree of test cases. data Test -- | A single, independent test case composed. TestCase :: Assertion -> Test -- | A set of Tests sharing the same level in the hierarchy. TestList :: [Test] -> Test -- | A name or description for a subtree of the Tests. TestLabel :: String -> Test -> Test -- | Shorthand for a test case that asserts equality (with the expected -- value on the left-hand side, and the actual value on the right-hand -- side). (~=?) :: (Eq a, Show a) => a -> a -> Test -- | Shorthand for a test case that asserts equality (with the actual value -- on the left-hand side, and the expected value on the right-hand side). (~?=) :: (Eq a, Show a) => a -> a -> Test -- | Creates a test from the specified Testable, with the specified -- label attached to it. -- -- Since Test is Testable, this can be used as a -- shorthand way of attaching a TestLabel to one or more tests. (~:) :: Testable t => String -> t -> Test -- | Creates a test case resulting from asserting the condition obtained -- from the specified AssertionPredicable. (~?) :: AssertionPredicable t => t -> String -> Test -- | Unconditionally signals that a failure has occured. All other -- assertions can be expressed with the form: -- --
-- if conditionIsMet -- then IO () -- else assertFailure msg --assertFailure :: String -> Assertion -- | Asserts that the specified condition holds. assertBool :: String -> Bool -> Assertion -- | Asserts that the specified actual value is equal to the expected -- value. The output message will contain the prefix, the expected value, -- and the actual value. -- -- If the prefix is the empty string (i.e., ""), then the prefix -- is omitted and only the expected and actual values are output. assertEqual :: (Eq a, Show a) => String -> a -> a -> Assertion -- | Signals an assertion failure if a non-empty message (i.e., a message -- other than "") is passed. assertString :: String -> Assertion -- | When an assertion is evaluated, it will output a message if and only -- if the assertion fails. -- -- Test cases are composed of a sequence of one or more assertions. type Assertion = IO () -- | Asserts that the specified actual value is equal to the expected value -- (with the expected value on the left-hand side). (@=?) :: (Eq a, Show a) => a -> a -> Assertion -- | Asserts that the specified actual value is equal to the expected value -- (with the actual value on the left-hand side). (@?=) :: (Eq a, Show a) => a -> a -> Assertion -- | Asserts that the condition obtained from the specified -- AssertionPredicable holds. (@?) :: AssertionPredicable t => t -> String -> Assertion -- | Allows the extension of the assertion mechanism. -- -- Since an Assertion can be a sequence of Assertions and -- IO actions, there is a fair amount of flexibility of what can -- be achieved. As a rule, the resulting Assertion should be the -- body of a TestCase or part of a TestCase; it should -- not be used to assert multiple, independent conditions. -- -- If more complex arrangements of assertions are needed, Tests -- and Testable should be used. class Assertable t assert :: Assertable t => t -> Assertion -- | A specialized form of Assertable to handle lists. class ListAssertable t listAssert :: ListAssertable t => [t] -> Assertion -- | The result of an assertion that hasn't been evaluated yet. -- -- Most test cases follow the following steps: -- --
-- import Test.HUnit ---- -- Define test cases as appropriate: -- --
-- test1 = TestCase (assertEqual "for (foo 3)," (1,2) (foo 3))
-- test2 = TestCase (do (x,y) <- partA 3
-- assertEqual "for the first result of partA," 5 x
-- b <- partB y
-- assertBool ("(partB " ++ show y ++ ") failed") b)
--
--
-- Name the test cases and group them together:
--
-- -- tests = TestList [TestLabel "test1" test1, TestLabel "test2" test2] ---- -- Run the tests as a group. At a Haskell interpreter prompt, apply the -- function runTestTT to the collected tests. (The TT -- suggests Text orientation with output to the Terminal.) -- --
-- > runTestTT tests -- Cases: 2 Tried: 2 Errors: 0 Failures: 0 -- > ---- -- If the tests are proving their worth, you might see: -- --
-- > runTestTT tests -- ### Failure in: 0:test1 -- for (foo 3), -- expected: (1,2) -- but got: (1,3) -- Cases: 2 Tried: 2 Errors: 0 Failures: 1 -- > ---- -- You can specify tests even more succinctly using operators and -- overloaded functions that HUnit provides: -- --
-- tests = test [ "test1" ~: "(foo 3)" ~: (1,2) ~=? (foo 3), -- "test2" ~: do (x, y) <- partA 3 -- assertEqual "for the first result of partA," 5 x -- partB y @? "(partB " ++ show y ++ ") failed" ] ---- -- Assuming the same test failures as before, you would see: -- --
-- > runTestTT tests -- ### Failure in: 0:test1:(foo 3) -- expected: (1,2) -- but got: (1,3) -- Cases: 2 Tried: 2 Errors: 0 Failures: 1 -- > --module Test.HUnit