-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A unit testing framework for Haskell -- -- HUnit is a unit testing framework for Haskell, inspired by the JUnit -- tool for Java, see: http://www.junit.org. @package HUnit @version 1.5.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 :: HasCallStack => String -> 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 :: (HasCallStack, Eq a, Show a) => String -> a -> a -> Assertion data Result Success :: Result Failure :: (Maybe SrcLoc) -> String -> Result Error :: (Maybe SrcLoc) -> String -> Result -- | Performs a single test case. performTestCase :: Assertion -> IO Result data HUnitFailure HUnitFailure :: (Maybe SrcLoc) -> FailureReason -> HUnitFailure data FailureReason Reason :: String -> FailureReason ExpectedButGot :: (Maybe String) -> String -> String -> FailureReason formatFailureReason :: FailureReason -> String instance GHC.Show.Show Test.HUnit.Lang.Result instance GHC.Classes.Eq Test.HUnit.Lang.Result instance GHC.Show.Show Test.HUnit.Lang.HUnitFailure instance GHC.Classes.Eq Test.HUnit.Lang.HUnitFailure instance GHC.Show.Show Test.HUnit.Lang.FailureReason instance GHC.Classes.Eq Test.HUnit.Lang.FailureReason instance GHC.Exception.Exception Test.HUnit.Lang.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). (~=?) :: (HasCallStack, Eq a, Show a) => a -> a -> Test infix 1 ~=? -- | 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). (~?=) :: (HasCallStack, Eq a, Show a) => a -> a -> Test infix 1 ~?= -- | 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. (~:) :: (HasCallStack, Testable t) => String -> t -> Test infixr 0 ~: -- | Creates a test case resulting from asserting the condition obtained -- from the specified AssertionPredicable. (~?) :: (HasCallStack, AssertionPredicable t) => t -> String -> Test infix 1 ~? -- | Unconditionally signals that a failure has occured. All other -- assertions can be expressed with the form: -- --
-- if conditionIsMet -- then IO () -- else assertFailure msg --assertFailure :: HasCallStack => String -> Assertion -- | Asserts that the specified condition holds. assertBool :: HasCallStack => 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 :: (HasCallStack, 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 :: HasCallStack => 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). (@=?) :: (HasCallStack, Eq a, Show a) => a -> a -> Assertion infix 1 @=? -- | Asserts that the specified actual value is equal to the expected value -- (with the actual value on the left-hand side). (@?=) :: (HasCallStack, Eq a, Show a) => a -> a -> Assertion infix 1 @?= -- | Asserts that the condition obtained from the specified -- AssertionPredicable holds. (@?) :: (HasCallStack, AssertionPredicable t) => t -> String -> Assertion infix 1 @? -- | 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, HasCallStack) => t -> Assertion -- | A specialized form of Assertable to handle lists. class ListAssertable t listAssert :: (ListAssertable t, HasCallStack) => [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