test-framework-hunit-0.3.0.1/0000755000000000000000000000000012225121446014135 5ustar0000000000000000test-framework-hunit-0.3.0.1/LICENSE0000644000000000000000000000276612225121446015155 0ustar0000000000000000Copyright (c) 2008, Maximilian Bolingbroke All rights reserved. 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. * Neither the name of Maximilian Bolingbroke nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 OWNER OR CONTRIBUTORS 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.test-framework-hunit-0.3.0.1/Setup.lhs0000644000000000000000000000011512225121446015742 0ustar0000000000000000#! /usr/bin/env runhaskell > import Distribution.Simple > main = defaultMaintest-framework-hunit-0.3.0.1/test-framework-hunit.cabal0000644000000000000000000000257012225121446021224 0ustar0000000000000000Name: test-framework-hunit Version: 0.3.0.1 Cabal-Version: >= 1.6 Category: Testing Synopsis: HUnit support for the test-framework package. License: BSD3 License-File: LICENSE Author: Max Bolingbroke Maintainer: Haskell Libraries Homepage: https://batterseapower.github.io/test-framework/ Bug-Reports: https://github.com/haskell/test-framework/ Build-Type: Simple Description: HUnit support for the test-framework package. Flag Base4 Description: Choose base version 4 Default: True Flag Base3 Description: Choose base version 3 Default: False Library Exposed-Modules: Test.Framework.Providers.HUnit Build-Depends: test-framework >= 0.2.0, HUnit >= 1.2 && < 2, extensible-exceptions >= 0.1.1 && < 0.2.0 if flag(base3) Build-Depends: base >= 3 && < 4 else if flag(base4) Build-Depends: base >= 4 && < 5 Extensions: TypeOperators MultiParamTypeClasses Ghc-Options: -Wall Source-Repository head Type: git Location: https://github.com/haskell/test-framework test-framework-hunit-0.3.0.1/Test/0000755000000000000000000000000012225121446015054 5ustar0000000000000000test-framework-hunit-0.3.0.1/Test/Framework/0000755000000000000000000000000012225121446017011 5ustar0000000000000000test-framework-hunit-0.3.0.1/Test/Framework/Providers/0000755000000000000000000000000012225121446020766 5ustar0000000000000000test-framework-hunit-0.3.0.1/Test/Framework/Providers/HUnit.hs0000644000000000000000000000563412225121446022361 0ustar0000000000000000{-# LANGUAGE DeriveDataTypeable #-} -- | Allows HUnit test cases to be used with the test-framework package. -- -- For an example of how to use test-framework, please see module Test.Framework.Providers.HUnit ( testCase, hUnitTestToTests, ) where import Test.Framework.Providers.API import qualified Test.HUnit.Base import Test.HUnit.Lang import Data.Typeable -- | Create a 'Test' for a HUnit 'Assertion' testCase :: TestName -> Assertion -> Test testCase name = Test name . TestCase -- | Adapt an existing HUnit test into a list of test-framework tests. -- This is useful when migrating your existing HUnit test suite to test-framework. hUnitTestToTests :: Test.HUnit.Base.Test -> [Test] hUnitTestToTests = go "" where go desc (Test.HUnit.Base.TestCase a) = [testCase desc a] go desc (Test.HUnit.Base.TestLabel s t) = go (desc ++ ":" ++ s) t go desc (Test.HUnit.Base.TestList ts) -- If the list occurs at the top level (with no description above it), -- just return that list straightforwardly | null desc = concatMap (go desc) ts -- If the list occurs with a description, turn that into a honest-to-god -- test group. This is heuristic, but likely to give good results | otherwise = [testGroup desc (concatMap (go "") ts)] instance TestResultlike TestCaseRunning TestCaseResult where testSucceeded = testCaseSucceeded data TestCaseRunning = TestCaseRunning instance Show TestCaseRunning where show TestCaseRunning = "Running" data TestCaseResult = TestCasePassed | TestCaseFailed String | TestCaseError String instance Show TestCaseResult where show result = case result of TestCasePassed -> "OK" TestCaseFailed message -> message TestCaseError message -> "ERROR: " ++ message testCaseSucceeded :: TestCaseResult -> Bool testCaseSucceeded TestCasePassed = True testCaseSucceeded _ = False newtype TestCase = TestCase Assertion deriving Typeable instance Testlike TestCaseRunning TestCaseResult TestCase where runTest topts (TestCase assertion) = runTestCase topts assertion testTypeName _ = "Test Cases" runTestCase :: CompleteTestOptions -> Assertion -> IO (TestCaseRunning :~> TestCaseResult, IO ()) runTestCase topts assertion = runImprovingIO $ do yieldImprovement TestCaseRunning mb_result <- maybeTimeoutImprovingIO (unK $ topt_timeout topts) $ liftIO (myPerformTestCase assertion) return (mb_result `orElse` TestCaseError "Timed out") myPerformTestCase :: Assertion -> IO TestCaseResult myPerformTestCase assertion = do result <- performTestCase assertion return $ case result of Nothing -> TestCasePassed Just (True, message) -> TestCaseFailed message Just (False, message) -> TestCaseError message