HUnit 1.2.4.3 → 1.2.5.0
raw patch · 11 files changed
+188/−359 lines, 11 filesdep ~basesetup-changedPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Test.HUnit.Lang: HUnitFailure :: String -> HUnitFailure
+ Test.HUnit.Lang: data HUnitFailure
Files
- HUnit.cabal +5/−70
- HUnit.cabal.tests +0/−160
- Setup.hs +1/−20
- Test/HUnit/Lang.hs +12/−1
- tests/HUnitTest98.lhs +0/−9
- tests/HUnitTestExtended.hs +63/−0
- tests/HUnitTestExtended.lhs +0/−39
- tests/HUnitTestOptimize.hs +58/−36
- tests/HUnitTests.hs +26/−0
- tests/TerminalTest.hs +23/−0
- tests/TerminalTest.lhs +0/−24
HUnit.cabal view
@@ -1,6 +1,6 @@ Name: HUnit-Version: 1.2.4.3-Cabal-Version: >= 1.6+Version: 1.2.5.0+Cabal-Version: >= 1.8 License: BSD3 License-File: LICENSE Author: Dean Herington@@ -17,12 +17,11 @@ GHC == 7.4.1 Build-Type: Custom Extra-Source-Files:- HUnit.cabal.tests- tests/HUnitTest98.lhs+ tests/HUnitTests.hs tests/HUnitTestBase.lhs- tests/HUnitTestExtended.lhs+ tests/HUnitTestExtended.hs tests/HUnitTestOptimize.hs- tests/TerminalTest.lhs+ tests/TerminalTest.hs Data-Files: doc/Guide.html examples/Example.hs@@ -54,67 +53,3 @@ Test.HUnit.Text, Test.HUnit Extensions: CPP--Executable basic-tests- Main-Is: HUnitTest98.lhs- HS-Source-Dirs: . tests- Build-Depends: - base < 5,- 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- Extensions: CPP--Executable extended-tests- Main-Is: HUnitTestExtended.lhs- HS-Source-Dirs: . tests- Build-Depends: - base < 5,- 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- Extensions: CPP--Executable terminal-tests- Main-Is: TerminalTest.lhs- HS-Source-Dirs: . tests- Build-Depends: - base < 5,- deepseq- if flag(base4)- Build-Depends: base >= 4- CPP-Options: -DBASE4- else- Build-Depends: base < 4- if impl(ghc >= 6.10)- Build-Depends: base >= 4- Extensions: CPP- -Executable optimize-tests- Main-Is: HUnitTestOptimize.hs- HS-Source-Dirs: . tests- Build-Depends: - base < 5,- 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- Extensions: CPP-
− HUnit.cabal.tests
@@ -1,160 +0,0 @@--- This CABAL file is used to build and run all of the various tests for the --- project. This separate file is necessary because Hackage does not allow--- the optimization level to be specified when building executables and some--- tests require different optimization levels to be set.------ To use this file, simply copy it to HUnit.cabal, then build as normal. You--- may rename the existing version of HUnit.cabal first, if you like.-Name: HUnit-Version: 1.2.4.3-Cabal-Version: >= 1.6-License: BSD3-License-File: LICENSE-Author: Dean Herington-Maintainer: hunit@richardg.name-Stability: stable-Homepage: http://hunit.sourceforge.net/-Category: Testing-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.0.4- GHC == 7.4.1-Build-Type: Custom-Extra-Source-Files:- tests/HUnitTest98.lhs- tests/HUnitTestBase.lhs- tests/HUnitTestExtended.lhs- tests/HUnitTestOptimize.hs- tests/TerminalTest.lhs-Data-Files:- doc/Guide.html- examples/Example.hs- prologue.txt- README-source-repository head- type: darcs- location: http://code.haskell.org/HUnit/--flag base4--Library- Build-Depends: - base < 5,- 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--Executable basic-tests- Main-Is: HUnitTest98.lhs- HS-Source-Dirs: . tests- Build-Depends: - base < 5,- 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- Extensions: CPP--Executable extended-tests- Main-Is: HUnitTestExtended.lhs- HS-Source-Dirs: . tests- Build-Depends: - base < 5,- 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- Extensions: CPP--Executable terminal-tests- Main-Is: TerminalTest.lhs- HS-Source-Dirs: . tests- Build-Depends: - base < 5,- deepseq- if flag(base4)- Build-Depends: base >= 4- CPP-Options: -DBASE4- else- Build-Depends: base < 4- if impl(ghc >= 6.10)- Build-Depends: base >= 4- Extensions: CPP--Executable optimize-0-tests- Main-Is: HUnitTestOptimize.hs- HS-Source-Dirs: . tests- Build-Depends: - base < 5,- deepseq- GHC-Options: -O0- if flag(base4)- Build-Depends: base >= 4- CPP-Options: -DBASE4 -DO0- GHC-Options: -Wall- else- Build-Depends: base < 4- if impl(ghc >= 6.10)- Build-Depends: base >= 4- Extensions: CPP- -Executable optimize-1-tests- Main-Is: HUnitTestOptimize.hs- HS-Source-Dirs: . tests- Build-Depends: - base < 5,- deepseq- GHC-Options: -O1- if flag(base4)- Build-Depends: base >= 4- CPP-Options: -DBASE4 -DO1- GHC-Options: -Wall- else- Build-Depends: base < 4- if impl(ghc >= 6.10)- Build-Depends: base >= 4- Extensions: CPP- -Executable optimize-2-tests- Main-Is: HUnitTestOptimize.hs- HS-Source-Dirs: . tests- Build-Depends: - base < 5,- deepseq- GHC-Options: -O2- if flag(base4)- Build-Depends: base >= 4- CPP-Options: -DBASE4 -DO2- GHC-Options: -Wall- else- Build-Depends: base < 4- if impl(ghc >= 6.10)- Build-Depends: base >= 4- Extensions: CPP-
Setup.hs view
@@ -1,26 +1,7 @@ #!/usr/bin/env runhaskell module Main (main) where -import Data.List (isSuffixOf)-import Distribution.PackageDescription import Distribution.Simple-import System.FilePath-import System.Process main :: IO ()-main = defaultMainWithHooks (simpleUserHooks {runTests = _runTests, instHook = _instHook})- where- -- Run all executables with names that end in -tests- _runTests _ _ pd _ = do- let exeNames = ["dist" </> "build" </> fp </> fp | fp <- map exeName (executables pd)]- sequence [_runTest e | e <- exeNames, isSuffixOf "-tests" e]- return ()- _runTest fp = do- ph <- runCommand fp- waitForProcess ph- - -- Only install executables that don't end in -tests- _instHook pd lbi uhs ifs = do- let execs = filter (\e -> not $ isSuffixOf "-tests" (exeName e)) (executables pd)- (instHook simpleUserHooks) (pd {executables = execs}) lbi uhs ifs - +main = defaultMain
Test/HUnit/Lang.hs view
@@ -5,7 +5,14 @@ ( Assertion, assertFailure, - performTestCase + 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 @@ -71,7 +78,11 @@ 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
− tests/HUnitTest98.lhs
@@ -1,9 +0,0 @@-HUnitTest98.lhs -- test for HUnit, using Haskell language system "98"--> module Main (main) where--> import Test.HUnit-> import HUnitTestBase--> main :: IO Counts-> main = runTestTT (test [baseTests])
+ tests/HUnitTestExtended.hs view
@@ -0,0 +1,63 @@+module HUnitTestExtended (+ extendedTests+ ) where++import Test.HUnit+import HUnitTestBase++-- Notes:+-- * Assertion testing is only performed on GHC. If you want this to be enabled+-- for other compilers, email the HUnit maintainer.++#ifdef __GLASGOW_HASKELL__+import qualified Control.Exception (assert)++#ifdef O0+import System.FilePath++assertionMessage :: String+assertionMessage = concat [+ "tests",+ [pathSeparator],+ "HUnitTestExtended.hs:27:13-36: Assertion failed\n"+ ]+#endif++assertion :: IO ()+assertion = Control.Exception.assert False (return ())+#endif+++extendedTests :: Test+extendedTests = test [++ -- Hugs doesn't currently catch arithmetic exceptions.+ + "div by 0" ~:+ expectUnspecifiedError (TestCase ((3 `div` 0 :: Integer) `seq` return ())),++ "list ref out of bounds" ~:+ expectUnspecifiedError (TestCase ([1 .. 4 :: Integer] !! 10 `seq` return ())),++ "error" ~:+ expectError "error" (TestCase (error "error")),++ "tail []" ~:+ expectUnspecifiedError (TestCase (tail [] `seq` return ()))++#ifdef __GLASGOW_HASKELL__+#ifdef O0+-- Run with no optimization (-O0)+ ,+ "assert" ~:+ expectError assertionMessage (TestCase assertion)+#else+-- #ifdef O0+-- Run with optimization (-O1 or -O2)+ ,+ "assert" ~: TestCase assertion+-- #ifdef O0+#endif+-- #ifdef __GLASGOW_HASKELL__+#endif+ ]
− tests/HUnitTestExtended.lhs
@@ -1,39 +0,0 @@-HUnitTestExc.lhs -- test for HUnit, using Haskell language system "Exc"--> module Main (main) where--> import Test.HUnit-> import HUnitTestBase-- import qualified Control.Exception (assert)-- assertionMessage = "HUnitTestExc.lhs:13: Assertion failed\n"- assertion = Control.Exception.assert False (return ())---> main :: IO Counts-> main = runTestTT (test [baseTests, excTests])--> excTests :: Test-> excTests = test [-- -- Hugs doesn't currently catch arithmetic exceptions.- -> "div by 0" ~:-> expectUnspecifiedError (TestCase ((3 `div` 0 :: Integer) `seq` return ())),--> "list ref out of bounds" ~:-> expectUnspecifiedError (TestCase ([1 .. 4 :: Integer] !! 10 `seq` return ())),--> "error" ~:-> expectError "error" (TestCase (error "error")),--> "tail []" ~:-> expectUnspecifiedError (TestCase (tail [] `seq` return ()))-- -- Hugs doesn't provide `assert` and GHC's type system doesn't allow this- -- to compile.- "assert" ~:- expectError assertionMessage (TestCase assertion)--> ]
tests/HUnitTestOptimize.hs view
@@ -6,9 +6,13 @@ -- With some versions and optimization levels of HUnit and GHC, tests were getting -- optimized out. This is a very bad thing and needs to be tested for. -module Main (main) where+module HUnitTestOptimize (+ optimizationTests,+ undefinedSwallowsTests+ ) where -import Control.Monad (unless)+import Control.Applicative+import Control.Monad import Test.HUnit -- Used to include the optimization level in the test results@@ -36,7 +40,7 @@ -- Some combinations of HUnit, GHC, and optimization levels cause tests to be -- optimized away. This section verifies that all tests of a type are -- performed.-optimizationTests :: IO ()+optimizationTests :: IO Bool optimizationTests = do counts2 <- simpleTestRunner $ TestLabel "Basic Optimization Tests" $ TestList [ True ~=? True,@@ -51,41 +55,59 @@ -- Verify results of counts2 -- We can't use HUnit because it's possible that some tests have been -- optimized away, so we'll just do it manually.- unless - (cases counts2 == 8)- (putStrLn $ "Failure: Basic Optimization (" ++ optimizationLevel ++ "): expected 8 test cases; only " ++ (show $ cases counts2) ++ " found. Some may have been optimized out.")- unless - (tried counts2 == 8)- (putStrLn $ "Failure: Basic Optimization (" ++ optimizationLevel ++ "): expected to try 8 test cases; only " ++ (show $ tried counts2) ++ " tried. Some may have been optimized out.")- unless - (errors counts2 == 0)- (putStrLn $ "Failure: Basic Optimization (" ++ optimizationLevel ++ "): expected 0 errors; " ++ (show $ errors counts2) ++ " found.")- unless- (failures counts2 == 6)- (putStrLn $ "Failure: Basic Optimization (" ++ optimizationLevel ++ "): expected 6 failed cases; only " ++ (show $ failures counts2) ++ " failed. Some may have been optimized out.")- return ()+ foldr (&&) True <$> sequence [+ caseCount counts2 optimizationLevel, + tryCount counts2 optimizationLevel, + errorCount counts2 optimizationLevel, + failureCount counts2 optimizationLevel+ ]+ where+ caseCount cs ol = if (cases cs == 8) + then return True+ else do+ putStrLn $ "Failure: Basic Optimization (" ++ + ol ++ "): expected 8 test cases; only " ++ + (show $ cases cs) ++ + " found. Some may have been optimized out."+ return False+ tryCount cs ol = if (tried cs == 8) + then return True+ else do+ putStrLn $ "Failure: Basic Optimization (" ++ + ol ++ "): expected to try 8 test cases; only " ++ + (show $ tried cs) ++ + " tried. Some may have been optimized out."+ return False+ errorCount cs ol = if (errors cs == 0) + then return True+ else do+ putStrLn $ "Failure: Basic Optimization (" ++ + ol ++ "): expected 0 errors; " ++ + (show $ errors cs) ++ " found."+ return False+ failureCount cs ol = if (failures cs == 6) + then return True+ else do+ putStrLn $ "Failure: Basic Optimization (" ++ + ol ++ "): expected 6 failed cases; only " ++ + (show $ failures cs) ++ + " failed. Some may have been optimized out."+ return False -- Added in 1.4.2.3 -- When certain errors occur in a list of tests, the subsequent tests in the -- list weren't being run. This test verifies that this does not happen.-undefinedSwallowsTests :: IO ()-undefinedSwallowsTests = do- -- Added in 1.2.4.3 because the second test case will never be run- -- (in prior versions)- counts2 <- simpleTestRunner . TestList $ [- TestCase $ ('f' : undefined) @?= "bar",- TestCase $ "foo" @?= "bar"- ]- _ <- runTestTT $ TestLabel ("Undefined Swallows Tests (" ++ optimizationLevel ++ ")") $ TestList [- TestCase $ assertEqual "cases" (cases counts2) 2, - TestCase $ assertEqual "tried" (tried counts2) 2, - TestCase $ assertEqual "errors" (errors counts2) 1, - TestCase $ assertEqual "failures" (failures counts2) 1+undefinedSwallowsTests :: Test+undefinedSwallowsTests = TestLabel ("Undefined Swallows Tests (" ++ optimizationLevel ++ ")") $ TestList [+ TestCase $ do+ rs <- simpleTestRunner . TestList $ [+ -- Added in 1.2.4.3 because the second test case will never be run+ -- (in prior versions)+ TestCase $ ('f' : undefined) @?= "bar",+ TestCase $ "foo" @?= "bar"+ ]+ assertEqual + "(cases,tried,errors,failures)" + (cases rs, tried rs, errors rs, failures rs)+ (2, 2, 1, 1) ]- return ()---- A simple sequencer of the 2 tests-main :: IO ()-main = do- optimizationTests- undefinedSwallowsTests
+ tests/HUnitTests.hs view
@@ -0,0 +1,26 @@+-- HUnitTests.hs+--+-- This file is an entry point for running all of the tests.++module Main (main) where++import System.Exit++import Test.HUnit+import HUnitTestBase+import HUnitTestExtended+import HUnitTestOptimize+import TerminalTest++main :: IO ()+main = do+ counts2 <- runTestTT (test [+ baseTests, + extendedTests,+ undefinedSwallowsTests,+ terminalTests+ ])+ oPassed <- optimizationTests+ if (errors counts2 + failures counts2 == 0 && oPassed) + then exitSuccess+ else exitFailure
+ tests/TerminalTest.hs view
@@ -0,0 +1,23 @@+-- TerminalTest.hs++module TerminalTest (terminalTests) where++import Test.HUnit.Terminal+import Test.HUnit++try :: String -> String -> String -> Test+try lab inp exp' = lab ~: terminalAppearance inp ~?= exp'++terminalTests :: Test+terminalTests = test [+ try "empty" "" "",+ try "end in \\n" "abc\ndef\n" "abc\ndef\n",+ try "not end in \\n" "abc\ndef" "abc\ndef",+ try "return 1" "abc\ndefgh\rxyz" "abc\nxyzgh",+ try "return 2" "\nabcdefgh\rijklm\rxy\n" "\nxyklmfgh\n",+ try "return 3" "\r\rabc\r\rdef\r\r\r\nghi\r\r\n" "def\nghi\n",+ try "back 1" "abc\bdef\b\bgh\b" "abdgh",+ try "back 2" "abc\b\b\bdef\b\bxy\b\b\n" "dxy\n"+ -- \b at beginning of line+ -- nonprinting char+ ]
− tests/TerminalTest.lhs
@@ -1,24 +0,0 @@-TerminalTest.lhs--> import Test.HUnit.Terminal-> import Test.HUnit--> main :: IO Counts-> main = runTestTT tests--> try :: String -> String -> String -> Test-> try lab inp exp' = lab ~: terminalAppearance inp ~?= exp'--> tests :: Test-> tests = test [-> try "empty" "" "",-> try "end in \\n" "abc\ndef\n" "abc\ndef\n",-> try "not end in \\n" "abc\ndef" "abc\ndef",-> try "return 1" "abc\ndefgh\rxyz" "abc\nxyzgh",-> try "return 2" "\nabcdefgh\rijklm\rxy\n" "\nxyklmfgh\n",-> try "return 3" "\r\rabc\r\rdef\r\r\r\nghi\r\r\n" "def\nghi\n",-> try "back 1" "abc\bdef\b\bgh\b" "abdgh",-> try "back 2" "abc\b\b\bdef\b\bxy\b\b\n" "dxy\n"-> -- \b at beginning of line-> -- nonprinting char-> ]