2{-# LANGUAGE DeriveDataTypeable #-}
7import Control.Monad (foldM, unless, when)
8import qualified Data.Map as Map
9import qualified Data.Set as Set
13import System.Directory (createDirectory, removeFile, canonicalizePath)
14import System.Environment (getEnvironment)
15import System.Exit (ExitCode (ExitSuccess))
16import System.FilePath ((<.>), (</>))
17import System.IO (IOMode (WriteMode, AppendMode),
19import System.Process (runProcess, waitForProcess)
20import Control.Exception (handle, Exception, throwIO)
21import Data.Typeable (Typeable)
23runTestSuites :: BuildSettings -> InstallInfo -> IO ()
24runTestSuites settings ii = do
25 let testdir = "runtests"
27 createDirectory testdir
28 allPass <- foldM (runTestSuite settings testdir hasTestSuites) True $ Map.toList $ iiPackages ii
29 unless allPass $ error $ "There were failures, please see the logs in " ++ testdir
31 PackageDB pdb = iiPackageDB ii
33 hasTestSuites name = maybe defaultHasTestSuites piHasTests $ Map.lookup name pdb
35-- | Separate for the PATH environment variable
43fixEnv :: FilePath -> (String, String) -> (String, String)
44fixEnv bin (p@"PATH", x) = (p, bin ++ pathSep : x)
47data TestException = TestException
48 deriving (Show, Typeable)
49instance Exception TestException
51runTestSuite :: BuildSettings
53 -> (PackageName -> Bool) -- ^ do we have any test suites?
55 -> (PackageName, (Version, Maintainer))
57runTestSuite settings testdir hasTestSuites prevPassed (packageName, (version, Maintainer maintainer)) = do
58 -- Set up a new environment that includes the sandboxed bin folder in PATH.
59 env' <- getEnvironment
61 = Just $ (if addGPP then (("GHC_PACKAGE_PATH", packageDir settings ++ ":"):) else id)
62 $ ("HASKELL_PACKAGE_SANDBOX", packageDir settings)
63 : map (fixEnv $ binDir settings) env'
65 let runGen addGPP cmd args wdir handle = do
66 ph <- runProcess cmd args (Just wdir) (menv addGPP) Nothing (Just handle) (Just handle)
67 ec <- waitForProcess ph
68 unless (ec == ExitSuccess) $ throwIO TestException
70 let run = runGen False
71 runGhcPackagePath = runGen True
73 passed <- handle (\TestException -> return False) $ do
74 getHandle WriteMode $ run "cabal" ["unpack", package] testdir
75 getHandle AppendMode $ run "cabal" (addCabalArgs settings ["configure", "--enable-tests"]) dir
76 when (hasTestSuites packageName) $ do
77 getHandle AppendMode $ run "cabal" ["build"] dir
78 getHandle AppendMode $ runGhcPackagePath "cabal" ["test"] dir
79 getHandle AppendMode $ run "cabal" ["haddock"] dir
81 let expectedFailure = packageName `Set.member` expectedFailures settings
85 when expectedFailure $ putStrLn $ package ++ " passed, but I didn't think it would."
86 else unless expectedFailure $ putStrLn $ "Test suite failed: " ++ package ++ "(" ++ maintainer ++ ")"
88 return $! prevPassed && (passed || expectedFailure)
90 logfile = testdir </> package <.> "log"
91 dir = testdir </> package
92 getHandle mode = withBinaryFile logfile mode
93 package = packageVersionString (packageName, version)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list