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 :: FilePath -> InstallInfo -> IO ()
24runTestSuites root ii = do
25 let testdir = "runtests"
27 createDirectory testdir
28 allPass <- foldM (runTestSuite root 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 :: FilePath
53 -> (PackageName -> Bool) -- ^ do we have any test suites?
55 -> (PackageName, (Version, Maintainer))
57runTestSuite root 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
60 let menv = Just $ map (fixEnv $ binDir root) env'
62 let run cmd args wdir handle = do
63 ph <- runProcess cmd args (Just wdir) menv Nothing (Just handle) (Just handle)
64 ec <- waitForProcess ph
65 unless (ec == ExitSuccess) $ throwIO TestException
67 passed <- handle (\TestException -> return False) $ do
68 getHandle WriteMode $ run "cabal" ["unpack", package] testdir
69 getHandle AppendMode $ run "cabal" (addCabalArgs root ["configure", "--enable-tests"]) dir
70 when (hasTestSuites packageName) $ do
71 getHandle AppendMode $ run "cabal" ["build"] dir
72 getHandle AppendMode $ run "cabal" ["test"] dir
73 getHandle AppendMode $ run "cabal" ["haddock"] dir
75 let expectedFailure = packageName `Set.member` expectedFailures
79 when expectedFailure $ putStrLn $ package ++ " passed, but I didn't think it would."
80 else unless expectedFailure $ putStrLn $ "Test suite failed: " ++ package ++ "(" ++ maintainer ++ ")"
82 return $! prevPassed && (passed || expectedFailure)
84 logfile = testdir </> package <.> "log"
85 dir = testdir </> package
86 getHandle mode = withBinaryFile logfile mode
87 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