tasty-hunit-0.9.2/0000755000000000000000000000000012502013651012174 5ustar0000000000000000tasty-hunit-0.9.2/LICENSE0000644000000000000000000000511212502013651013200 0ustar0000000000000000Copyright (c) 2013 Roman Cheplyaka Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- HUnit is Copyright (c) Dean Herington, 2002, all rights reserved, and is distributed as free software under the following license. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution. - The names of the copyright holders may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. tasty-hunit-0.9.2/CHANGELOG.md0000644000000000000000000000205012502013651014002 0ustar0000000000000000Changes ======= Version 0.9.2 ------------- Add `testCaseInfo` for tests that return some information upon success Version 0.9.1 ------------- Add `testCaseSteps` for multi-step tests Version 0.9.0.1 --------------- Split the changelog out of the main tasty changelog Version 0.9 ----------- tasty-hunit now does not depend on the original HUnit package. The functions that were previously re-exported from HUnit have been simply copied to tasty-hunit. This is motivated by: * efficiency (one less package to compile/install) * reliability (if something happens with HUnit, we won't be affected) The two packages are still compatible, except for the name clashes and distinct exception types being thrown on assertion failures. Version 0.8.0.1 --------------- Fix unbuildable haddock Version 0.8 ----------- * Exceptions are now handled by tasty rather than by HUnit * Update to tasty-0.8 Version 0.4.1 ------------- Do not re-export HUnit's `Testable` class Version 0.2 ----------- Re-export useful bits of `Test.HUnit` from `Test.Tasty.HUnit` tasty-hunit-0.9.2/tasty-hunit.cabal0000644000000000000000000000224112502013651015450 0ustar0000000000000000-- Initial tasty-hunit.cabal generated by cabal init. For further -- documentation, see http://haskell.org/cabal/users-guide/ name: tasty-hunit version: 0.9.2 synopsis: HUnit support for the Tasty test framework. description: HUnit support for the Tasty test framework. license: MIT license-file: LICENSE author: Roman Cheplyaka maintainer: Roman Cheplyaka homepage: http://documentup.com/feuerbach/tasty bug-reports: https://github.com/feuerbach/tasty/issues -- copyright: category: Testing build-type: Simple extra-source-files: CHANGELOG.md cabal-version: >=1.10 Source-repository head type: git location: git://github.com/feuerbach/tasty.git subdir: hunit library exposed-modules: Test.Tasty.HUnit other-modules: Test.Tasty.HUnit.Orig Test.Tasty.HUnit.Steps other-extensions: TypeFamilies, DeriveDataTypeable build-depends: base ==4.*, tasty >= 0.8 -- hs-source-dirs: default-language: Haskell2010 ghc-options: -Wall tasty-hunit-0.9.2/Setup.hs0000644000000000000000000000005612502013651013631 0ustar0000000000000000import Distribution.Simple main = defaultMain tasty-hunit-0.9.2/Test/0000755000000000000000000000000012502013651013113 5ustar0000000000000000tasty-hunit-0.9.2/Test/Tasty/0000755000000000000000000000000012502013651014217 5ustar0000000000000000tasty-hunit-0.9.2/Test/Tasty/HUnit.hs0000644000000000000000000000333412502013651015605 0ustar0000000000000000-- | Unit testing support for tasty, inspired by the HUnit package {-# LANGUAGE TypeFamilies, DeriveDataTypeable #-} module Test.Tasty.HUnit ( testCase , testCaseInfo , testCaseSteps , module Test.Tasty.HUnit.Orig ) where import Test.Tasty.Providers import Test.Tasty.HUnit.Orig import Test.Tasty.HUnit.Steps import Data.Typeable import Control.Exception -- | Create a 'Test' for a HUnit 'Assertion' testCase :: TestName -> Assertion -> TestTree testCase name = singleTest name . TestCase . (fmap (const "")) -- | Like 'testCase', except in case the test succeeds, the returned string -- will be shown as the description. If the empty string is returned, it -- will be ignored. testCaseInfo :: TestName -> IO String -> TestTree testCaseInfo name = singleTest name . TestCase -- IO String is a computation that throws an exception upon failure or -- returns an informational string otherwise. This allows us to unify the -- implementation of 'testCase' and 'testCaseInfo'. -- -- In case of testCase, we simply make the result string empty, which makes -- tasty ignore it. newtype TestCase = TestCase (IO String) deriving Typeable instance IsTest TestCase where run _ (TestCase assertion) _ = do -- The standard HUnit's performTestCase catches (almost) all exceptions. -- -- This is bad for a few reasons: -- - it interferes with timeout handling -- - it makes exception reporting inconsistent across providers -- - it doesn't provide enough information for ingredients such as -- tasty-rerun -- -- So we do it ourselves. hunitResult <- try assertion return $ case hunitResult of Right info -> testPassed info Left (HUnitFailure message) -> testFailed message testOptions = return [] tasty-hunit-0.9.2/Test/Tasty/HUnit/0000755000000000000000000000000012502013651015246 5ustar0000000000000000tasty-hunit-0.9.2/Test/Tasty/HUnit/Steps.hs0000644000000000000000000000446512502013651016711 0ustar0000000000000000{-# LANGUAGE DeriveDataTypeable #-} module Test.Tasty.HUnit.Steps (testCaseSteps) where import Control.Applicative import Control.Exception import Data.IORef import Data.Typeable (Typeable) import Test.Tasty.HUnit.Orig import Test.Tasty.Providers newtype TestCaseSteps = TestCaseSteps ((String -> IO ()) -> Assertion) deriving Typeable instance IsTest TestCaseSteps where run _ (TestCaseSteps assertionFn) _ = do ref <- newIORef [] let stepFn :: String -> IO () stepFn msg = atomicModifyIORef ref (\l -> (msg:l, ())) hunitResult <- try (assertionFn stepFn) msgs <- reverse <$> readIORef ref return $ case hunitResult of Right {} -> testPassed (unlines msgs) Left (HUnitFailure errMsg) -> testFailed $ if null msgs then errMsg else -- Indent the error msg w.r.t. step messages unlines $ msgs ++ map (" " ++) (lines errMsg) testOptions = return [] -- | Create a multi-step unit test. -- -- Example: -- -- >main = defaultMain $ testCaseSteps "Multi-step test" $ \step -> do -- > step "Preparing..." -- > -- do something -- > -- > step "Running part 1" -- > -- do something -- > -- > step "Running part 2" -- > -- do something -- > assertFailure "BAM!" -- > -- > step "Running part 3" -- > -- do something -- -- The @step@ calls are mere annotations. They let you see which steps were -- performed successfully, and which step failed. -- -- You can think of @step@ -- as 'putStrLn', except 'putStrLn' would mess up the output with the -- console reporter and get lost with the others. -- -- For the example above, the output will be -- -- >Multi-step test: FAIL -- > Preparing... -- > Running part 1 -- > Running part 2 -- > BAM! -- > -- >1 out of 1 tests failed (0.00s) -- -- Note that: -- -- * Tasty still treats this as a single test, even though it consists of -- multiple steps. -- -- * The execution stops after the first failure. When we are looking at -- a failed test, we know that all /displayed/ steps but the last one were -- successful, and the last one failed. The steps /after/ the failed one -- are /not displayed/, since they didn't run. testCaseSteps :: TestName -> ((String -> IO ()) -> Assertion) -> TestTree testCaseSteps name = singleTest name . TestCaseSteps tasty-hunit-0.9.2/Test/Tasty/HUnit/Orig.hs0000644000000000000000000001277312502013651016514 0ustar0000000000000000{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, TypeSynonymInstances #-} -- | This is the code copied from the original hunit package (v. 1.2.5.2). -- with minor modifications module Test.Tasty.HUnit.Orig where import qualified Control.Exception as E import Control.Monad import Data.Typeable (Typeable) -- Interfaces -- ---------- -- | 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 -- ^ A message that is displayed with the assertion failure -> Assertion assertFailure msg = E.throwIO (HUnitFailure msg) -- Conditional Assertion Functions -- ------------------------------- -- | Asserts that the specified condition holds. assertBool :: String -- ^ The message that is displayed if the assertion fails -> Bool -- ^ The condition -> Assertion assertBool msg b = unless b (assertFailure msg) -- | Signals an assertion failure if a non-empty message (i.e., a message -- other than @\"\"@) is passed. assertString :: String -- ^ The message that is displayed with the assertion failure -> Assertion assertString s = unless (null s) (assertFailure s) -- | 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 -- ^ The message prefix -> a -- ^ The expected value -> a -- ^ The actual value -> Assertion assertEqual preface expected actual = unless (actual == expected) (assertFailure msg) where msg = (if null preface then "" else preface ++ "\n") ++ "expected: " ++ show expected ++ "\n but got: " ++ show actual -- Overloaded `assert` Function -- ---------------------------- -- | Allows the extension of the assertion mechanism. -- -- Since an 'Assertion' can be a sequence of @Assertion@s 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, 'Test's and -- 'Testable' should be used. class Assertable t where assert :: t -> Assertion instance Assertable () where assert = return instance Assertable Bool where assert = assertBool "" instance (Assertable t) => Assertable (IO t) where assert = (>>= assert) instance Assertable String where assert = assertString -- Overloaded `assertionPredicate` Function -- ---------------------------------------- -- | The result of an assertion that hasn't been evaluated yet. -- -- Most test cases follow the following steps: -- -- 1. Do some processing or an action. -- -- 2. Assert certain conditions. -- -- However, this flow is not always suitable. @AssertionPredicate@ allows for -- additional steps to be inserted without the initial action to be affected -- by side effects. Additionally, clean-up can be done before the test case -- has a chance to end. A potential work flow is: -- -- 1. Write data to a file. -- -- 2. Read data from a file, evaluate conditions. -- -- 3. Clean up the file. -- -- 4. Assert that the side effects of the read operation meet certain conditions. -- -- 5. Assert that the conditions evaluated in step 2 are met. type AssertionPredicate = IO Bool -- | Used to signify that a data type can be converted to an assertion -- predicate. class AssertionPredicable t where assertionPredicate :: t -> AssertionPredicate instance AssertionPredicable Bool where assertionPredicate = return instance (AssertionPredicable t) => AssertionPredicable (IO t) where assertionPredicate = (>>= assertionPredicate) -- Assertion Construction Operators -- -------------------------------- infix 1 @?, @=?, @?= -- | Asserts that the condition obtained from the specified -- 'AssertionPredicable' holds. (@?) :: (AssertionPredicable t) => t -- ^ A value of which the asserted condition is predicated -> String -- ^ A message that is displayed if the assertion fails -> Assertion predi @? msg = assertionPredicate predi >>= assertBool msg -- | 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 -- ^ The expected value -> a -- ^ The actual value -> Assertion expected @=? actual = assertEqual "" expected actual -- | 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 -- ^ The actual value -> a -- ^ The expected value -> Assertion actual @?= expected = assertEqual "" expected actual -- | Exception thrown by 'assertFailure' etc. data HUnitFailure = HUnitFailure String deriving (Show, Typeable) instance E.Exception HUnitFailure