Skip to content

Commit

Permalink
Remove support for old compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
qoelet committed Aug 4, 2015
1 parent f525a78 commit 18ef26f
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 440 deletions.
1 change: 1 addition & 0 deletions .ghci
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:set -optP-includedist/build/autogen/cabal_macros.h -i. -itests
45 changes: 19 additions & 26 deletions HUnit.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@ Synopsis: A unit testing framework for Haskell
Description:
HUnit is a unit testing framework for Haskell, inspired by the
JUnit tool for Java, see: <http://www.junit.org>.
Tested-With:
GHC == 7.4.1
GHC == 7.4.2
GHC == 7.7
Build-Type: Simple
Extra-Source-Files:
HUnit.cabal.hugs
HUnit.cabal.tests
Setup.hs.hugs
tests/HUnitTests.hs
tests/HUnitTestBase.lhs
tests/HUnitTestExtended.hs
tests/HUnitTestOptimize.hs
tests/TerminalTest.hs
Data-Files:
doc/Guide.html
examples/Example.hs
Expand All @@ -36,24 +23,30 @@ source-repository head
type: darcs
location: http://code.haskell.org/HUnit/

flag base4

Library
Build-Depends:
base < 5,
Build-Depends:
base == 4.*,
deepseq
if flag(base4)
Build-Depends: base >= 4
CPP-Options: -DBASE4
GHC-Options: -Wall
else
Build-Depends: base < 4
if impl(ghc >= 6.10)
Build-Depends: base >= 4
Exposed-Modules:
Test.HUnit.Base,
Test.HUnit.Lang,
Test.HUnit.Terminal,
Test.HUnit.Text,
Test.HUnit
Extensions: CPP
GHC-Options: -Wall

Test-Suite tests
Type: exitcode-stdio-1.0
Main-Is: HUnitTests.hs
HS-Source-Dirs: tests
Build-Depends:
base == 4.*,
deepseq,
filepath,
HUnit
Other-Modules:
HUnitTests
HUnitTestBase
HUnitTestExtended
TerminalTest
GHC-Options: -Wall
20 changes: 0 additions & 20 deletions HUnit.cabal.hugs

This file was deleted.

122 changes: 0 additions & 122 deletions HUnit.cabal.tests

This file was deleted.

7 changes: 0 additions & 7 deletions Setup.hs.hugs

This file was deleted.

3 changes: 3 additions & 0 deletions Setup.lhs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env runhaskell
> import Distribution.Simple
> main = defaultMain
109 changes: 11 additions & 98 deletions Test/HUnit/Lang.hs
Original file line number Diff line number Diff line change
@@ -1,56 +1,30 @@
-- | This module abstracts the differences between implementations of
-- Haskell (e.g., GHC, Hugs, and NHC).

{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 707
{-# LANGUAGE DeriveDataTypeable #-}
#endif

module Test.HUnit.Lang
(
module Test.HUnit.Lang (
Assertion,
assertFailure,
performTestCase,
#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
-- * Internals
-- |
-- /Note:/ This is not part of the public API! It is exposed so that you can
-- tinker with the internals of HUnit, but do not expect it to be stable!
HUnitFailure (..)
#endif
)
where


-- When adapting this module for other Haskell language systems, change
-- the imports and the implementations but not the interfaces.



-- Imports
-- -------

#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
import Data.Dynamic
import Control.Exception as E
#else
import Data.List (isPrefixOf)
import System.IO.Error (ioeGetErrorString, try)
#endif

import Control.DeepSeq
) where


-- Interfaces
-- ----------
import Control.DeepSeq
import Control.Exception as E
import Data.Typeable

-- | 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 ()

data HUnitFailure = HUnitFailure String
deriving (Show, Typeable)

instance Exception HUnitFailure

-- | Unconditionally signals that a failure has occured. All
-- other assertions can be expressed with the form:
--
Expand All @@ -59,9 +33,9 @@ type Assertion = IO ()
-- then IO ()
-- else assertFailure msg
-- @

assertFailure :: String -- ^ A message that is displayed with the assertion failure
-> Assertion
assertFailure msg = msg `deepseq` E.throwIO (HUnitFailure msg)

-- | Performs a single test case. The meaning of the result is as follows:
--
Expand All @@ -70,38 +44,8 @@ assertFailure :: String -- ^ A message that is displayed with the assertion fail
-- [@Just (True, msg)@] test case failure with the given message
--
-- [@Just (False, msg)@] test case error with the given message

performTestCase :: Assertion -- ^ an assertion to be made during the test case run
-> IO (Maybe (Bool, String))


-- Implementations
-- ---------------

#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
data HUnitFailure = HUnitFailure String
#if __GLASGOW_HASKELL__ >= 707
deriving (Show, Typeable)
#else
deriving Show

hunitFailureTc :: TyCon
#if MIN_VERSION_base(4,4,0)
hunitFailureTc = mkTyCon3 "HUnit" "Test.HUnit.Lang" "HUnitFailure"
#else
hunitFailureTc = mkTyCon "HUnitFailure"
#endif
{-# NOINLINE hunitFailureTc #-}

instance Typeable HUnitFailure where
typeOf _ = mkTyConApp hunitFailureTc []
#endif

#ifdef BASE4
instance Exception HUnitFailure

assertFailure msg = msg `deepseq` E.throwIO (HUnitFailure msg)

performTestCase action =
do action
return Nothing
Expand All @@ -116,34 +60,3 @@ performTestCase action =
E.Handler (\e -> throw (e :: E.AsyncException)),

E.Handler (\e -> return $ Just (False, show (e :: E.SomeException)))]
#else
assertFailure msg = msg `deepseq` E.throwDyn (HUnitFailure msg)

performTestCase action =
do r <- E.try action
case r of
Right () -> return Nothing
Left e@(E.DynException dyn) ->
case fromDynamic dyn of
Just (HUnitFailure msg) -> return $ Just (True, msg)
Nothing -> return $ Just (False, show e)
Left e -> return $ Just (False, show e)
#endif
#else
hunitPrefix = "HUnit:"

nhc98Prefix = "I/O error (user-defined), call to function `userError':\n "

assertFailure msg = msg `deepseq` ioError (userError (hunitPrefix ++ msg))

performTestCase action = do r <- try action
case r of Right () -> return Nothing
Left e -> return (Just (decode e))
where
decode e = let s0 = ioeGetErrorString e
(_, s1) = dropPrefix nhc98Prefix s0
in dropPrefix hunitPrefix s1
dropPrefix pref str = if pref `isPrefixOf` str
then (True, drop (length pref) str)
else (False, str)
#endif
8 changes: 0 additions & 8 deletions tests/HUnitTestBase.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ HUnitTestBase.lhs -- test support and basic tests (Haskell 98 compliant)
> "null" ~: expectSuccess ok,

> "userError" ~:
#if defined(__GLASGOW_HASKELL__)
> expectError "user error (error)" (TestCase (ioError (userError "error"))),
#else
> expectError "error" (TestCase (ioError (userError "error"))),
#endif

> "IO error (file missing)" ~:
> expectUnspecifiedError
Expand Down Expand Up @@ -270,11 +266,7 @@ HUnitTestBase.lhs -- test support and basic tests (Haskell 98 compliant)

> "lone error" ~:
> expectText (Counts 1 1 1 0)
#if defined(__GLASGOW_HASKELL__)
> "### Error:\nuser error (xyz)\nCases: 1 Tried: 1 Errors: 1 Failures: 0\n"
#else
> "### Error:\nxyz\nCases: 1 Tried: 1 Errors: 1 Failures: 0\n"
#endif
> (test (do _ <- ioError (userError "xyz"); return ())),

> "lone failure" ~:
Expand Down
Loading

0 comments on commit 18ef26f

Please sign in to comment.