Commit 70618983 authored by ttuegel's avatar ttuegel
Browse files

Test command runs all executable testsuites

Ticket #215 (Overhaul support for packages' tests). The 'test' command runs all
executable tests listed in the package description when the package is
configured with tests enabled. The exit codes and standard output/error are
collected and reported.
parent f77f9334
......@@ -102,6 +102,7 @@ Library
Distribution.Simple.Register,
Distribution.Simple.Setup,
Distribution.Simple.SrcDist,
Distribution.Simple.Test,
Distribution.Simple.UHC,
Distribution.Simple.UserHooks,
Distribution.Simple.Utils,
......
......@@ -104,6 +104,7 @@ import Distribution.Simple.Configure
import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..) )
import Distribution.Simple.BuildPaths ( srcPref)
import Distribution.Simple.Test (test)
import Distribution.Simple.Install (install)
import Distribution.Simple.Haddock (haddock, hscolour)
import Distribution.Simple.Utils
......@@ -321,11 +322,11 @@ sdistAction hooks flags args = do
where verbosity = fromFlag (sDistVerbosity flags)
testAction :: UserHooks -> TestFlags -> Args -> IO ()
testAction hooks flags args = do
let distPref = fromFlag $ testDistPref flags
localbuildinfo <- getBuildConfig hooks distPref
let pkg_descr = localPkgDescr localbuildinfo
runTests hooks args False pkg_descr localbuildinfo
testAction hooks flags args
= do let distPref = fromFlag $ testDistPref flags
hookedAction preTest testHook postTest
(getBuildConfig hooks distPref)
hooks flags args
registerAction :: UserHooks -> RegisterFlags -> Args -> IO ()
registerAction hooks flags args
......@@ -417,6 +418,7 @@ simpleUserHooks =
postConf = finalChecks,
buildHook = defaultBuildHook,
copyHook = \desc lbi _ f -> install desc lbi f, -- has correct 'copy' behavior with params
testHook = defaultTestHook,
instHook = defaultInstallHook,
sDistHook = \p l h f -> sdist p l f srcPref (allSuffixHandlers h),
cleanHook = \p _ _ f -> clean p f,
......@@ -538,6 +540,11 @@ getHookedBuildInfo verbosity = do
info verbosity $ "Reading parameters from " ++ infoFile
readHookedBuildInfo verbosity infoFile
defaultTestHook :: PackageDescription -> LocalBuildInfo
-> UserHooks -> TestFlags -> IO ()
defaultTestHook pkg_descr localbuildinfo _ flags =
test pkg_descr localbuildinfo flags
defaultInstallHook :: PackageDescription -> LocalBuildInfo
-> UserHooks -> InstallFlags -> IO ()
defaultInstallHook pkg_descr localbuildinfo _ flags = do
......
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Simple.Test
-- Copyright : Thomas Tuegel 2010
--
-- Maintainer : cabal-devel@haskell.org
-- Portability : portable
--
-- This is the entry point into testing a built package. Performs the
-- \"@.\/setup test@\" action. It runs testsuites designated in the package
-- description and reports on the results.
{- 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 Isaac Jones 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. -}
module Distribution.Simple.Test ( test ) where
import Distribution.PackageDescription
( PackageDescription(..), Testsuite(..), TestType(..)
, hasTests, matches )
import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..) )
import Distribution.Simple.BuildPaths ( exeExtension )
import Distribution.Simple.Setup ( TestFlags(..), fromFlag )
import Distribution.Simple.Utils
import Distribution.Text
import Distribution.Verbosity ( Verbosity, silent )
import Distribution.Version ( anyVersion, thisVersion, Version(..) )
import Control.Monad ( unless )
import System.FilePath ( (</>), (<.>) )
import System.Exit ( ExitCode(..) )
-- |Perform the \"@.\/setup test@\" action.
test :: PackageDescription -- ^information from the .cabal file
-> LocalBuildInfo -- ^information from the configure step
-> TestFlags -- ^flags sent to test
-> IO ()
test pkg_descr lbi flags = do
let verbosity = fromFlag $ testVerbosity flags
exeTestType = (ExeTest $ thisVersion $ Version [1] [])
doTest t =
if testType t `matches` exeTestType
then doExeTest t
else do
_ <- die $ "No support for running test type: " ++
show (disp $ testType t)
return False
doExeTest t = do
(out, _, exit) <- rawSystemStdInOut silent exe []
Nothing False
case exit of
ExitSuccess -> do
notice verbosity $ "Testsuite " ++ testName t ++
" successful."
doOutput info out
return True
ExitFailure code -> do
notice verbosity $ "Testsuite " ++ testName t ++
" failure with exit code " ++
show code ++ "!"
doOutput notice out
return False
where exe = buildDir lbi </> testName t </>
testName t <.> exeExtension
doOutput :: (Verbosity -> String -> IO ())
-> String -> IO ()
doOutput f o = if null o then return () else
f verbosity $ "Testsuite " ++ testName t ++
" output:\n" ++ o
unless (hasTests pkg_descr) $ notice verbosity
"Package has no tests or was configured with tests disabled."
results <- mapM doTest $ testsuites pkg_descr
let successful = length $ filter id results
total = length $ testsuites pkg_descr
notice verbosity $ show successful ++ " of " ++ show total ++
" testsuites successful."
\ No newline at end of file
......@@ -66,7 +66,7 @@ import Distribution.Simple.PreProcess (PPSuffixHandler)
import Distribution.Simple.Setup
(ConfigFlags, BuildFlags, CleanFlags, CopyFlags,
InstallFlags, SDistFlags, RegisterFlags, HscolourFlags,
HaddockFlags)
HaddockFlags, TestFlags)
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo)
type Args = [String]
......@@ -79,8 +79,6 @@ type Args = [String]
-- break in future releases.
data UserHooks = UserHooks {
-- | Used for @.\/setup test@
runTests :: Args -> Bool -> PackageDescription -> LocalBuildInfo -> IO (),
-- | Read the description file
readDesc :: IO (Maybe GenericPackageDescription),
-- | Custom preprocessors in addition to and overriding 'knownSuffixHandlers'.
......@@ -161,14 +159,20 @@ data UserHooks = UserHooks {
-- |Over-ride this hook to get different behavior during haddock.
haddockHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> HaddockFlags -> IO (),
-- |Hook to run after haddock command. Second arg indicates verbosity level.
postHaddock :: Args -> HaddockFlags -> PackageDescription -> LocalBuildInfo -> IO ()
postHaddock :: Args -> HaddockFlags -> PackageDescription -> LocalBuildInfo -> IO (),
-- |Hook to run before test command.
preTest :: Args -> TestFlags -> IO HookedBuildInfo,
-- |Over-ride this hook to get different behavior during test.
testHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> TestFlags -> IO (),
-- |Hook to run after test command.
postTest :: Args -> TestFlags -> PackageDescription -> LocalBuildInfo -> IO ()
}
-- |Empty 'UserHooks' which do nothing.
emptyUserHooks :: UserHooks
emptyUserHooks
= UserHooks {
runTests = ru,
readDesc = return Nothing,
hookedPreProcessors = [],
hookedPrograms = [],
......@@ -201,7 +205,10 @@ emptyUserHooks
postHscolour = ru,
preHaddock = rn,
haddockHook = ru,
postHaddock = ru
postHaddock = ru,
preTest = rn,
testHook = ru,
postTest = ru
}
where rn args _ = noExtraFlags args >> return emptyHookedBuildInfo
ru _ _ _ _ = return ()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment