1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE RecordWildCards #-}
7import qualified Control.Concurrent as C
8import Control.Exception (Exception, SomeException, handle, throwIO)
9import Control.Monad (replicateM, unless, when)
10import qualified Data.Map as Map
11import qualified Data.Set as Set
12import Data.Typeable (Typeable)
15import System.Directory (createDirectory, removeFile)
16import System.Exit (ExitCode (ExitSuccess))
17import System.FilePath ((<.>), (</>))
18import System.IO (IOMode (WriteMode, AppendMode),
20import System.Process (runProcess, waitForProcess)
22runTestSuites :: BuildSettings -> BuildPlan -> IO ()
23runTestSuites settings' bp = do
24 settings <- fixBuildSettings settings'
25 let selected = Map.filterWithKey notSkipped $ bpPackages bp
26 putStrLn "Running test suites"
27 let testdir = "runtests"
29 createDirectory testdir
30 allPass <- parFoldM (testWorkerThreads settings) (runTestSuite settings testdir) (&&) True $ Map.toList selected
31 unless allPass $ error $ "There were failures, please see the logs in " ++ testdir
33 notSkipped p _ = p `Set.notMember` bpSkippedTests bp
35parFoldM :: Int -- ^ number of threads
41parFoldM threadCount0 f g a0 bs0 = do
44 signal <- C.newEmptyMVar
45 tids <- replicateM threadCount0 $ C.forkIO $ worker ma mbs signal
46 wait threadCount0 signal tids
49 worker ma mbs signal =
51 (C.putMVar signal . Just)
52 (loop >> C.putMVar signal Nothing)
55 mb <- C.modifyMVar mbs $ \bs -> return $
58 b:bs' -> (bs', Just b)
63 C.modifyMVar_ ma $ \a -> return $! g a c
65 wait threadCount signal tids
66 | threadCount == 0 = return ()
68 me <- C.takeMVar signal
70 Nothing -> wait (threadCount - 1) signal tids
72 mapM_ C.killThread tids
73 throwIO (e :: SomeException)
75data TestException = TestException
76 deriving (Show, Typeable)
77instance Exception TestException
79runTestSuite :: BuildSettings
81 -> (PackageName, SelectedPackageInfo)
83runTestSuite settings testdir (packageName, SelectedPackageInfo {..}) = do
84 -- Set up a new environment that includes the sandboxed bin folder in PATH.
85 env' <- getModifiedEnv settings
87 = Just $ (if addGPP then (("GHC_PACKAGE_PATH", packageDir settings ++ ":"):) else id)
88 $ ("HASKELL_PACKAGE_SANDBOX", packageDir settings)
91 let runGen addGPP cmd args wdir handle' = do
92 ph <- runProcess cmd args (Just wdir) (menv addGPP) Nothing (Just handle') (Just handle')
93 ec <- waitForProcess ph
94 unless (ec == ExitSuccess) $ throwIO TestException
96 let run = runGen False
97 runGhcPackagePath = runGen True
99 passed <- handle (\TestException -> return False) $ do
100 getHandle WriteMode $ run "cabal" ["unpack", package] testdir
101 getHandle AppendMode $ run "cabal" (addCabalArgs settings BSTest ["configure", "--enable-tests"]) dir
102 when spiHasTests $ do
103 getHandle AppendMode $ run "cabal" ["build"] dir
104 getHandle AppendMode $ runGhcPackagePath "cabal" ["test"] dir
105 when (buildDocs settings) $
106 getHandle AppendMode $ run "cabal" ["haddock"] dir
108 let expectedFailure = packageName `Set.member` expectedFailuresBuild settings
112 when expectedFailure $ putStrLn $ package ++ " passed, but I didn't think it would."
113 else unless expectedFailure $ putStrLn $ concat
114 [ "Test suite failed: "
117 , unMaintainer spiMaintainer
118 , case spiGithubUser of
124 return $! passed || expectedFailure
126 logfile = testdir </> package <.> "log"
127 dir = testdir </> package
128 getHandle mode = withBinaryFile logfile mode
129 package = packageVersionString (packageName, spiVersion)
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