on master help sign in
Merge pull request #3265 from crough/test-exitcode

testPkg exits with the wrapped tests exit code

commited6c0ff18e0d3d20d3b15500290314669dfd9486 authorJan de Muijnck-Hughes <jfdm@users.noreply.github.com> dateFri 25 Nov 2016, 10:21 (10 years ago) parent2c0be60f6cd836
2 files changed+51−36
main/Main.hs+15−3 src/Idris/Package.hs+36−33
main/Main.hs+15−3
@@ -1,5 +1,11 @@
11module Main where
22
3+import System.Exit ( ExitCode(..), exitWith, exitSuccess )
4+
5+import Control.Monad ( unless, when, (>=>) )
6+import Data.Maybe ( fromMaybe )
7+import Data.Foldable ( foldrM )
8+
39import Idris.AbsSyntax
410import Idris.CmdOptions
511import Idris.Error
@@ -9,8 +15,8 @@ import Idris.Package
915
1016import Util.System (setupBundledCC)
1117
12−import Control.Monad (when)
13−import System.Exit (exitSuccess)
18+import Util.System ( setupBundledCC )
19+import System.Exit ( ExitCode(..), exitWith)
1420
1521processShowOptions :: [Opt] -> Idris ()
1622processShowOptions opts = runIO $ do
@@ -49,7 +55,13 @@ processPackageOptions opts = do
4955 check opts getPkgMkDoc $ \fs -> runIO $ do
5056 mapM_ (documentPkg opts) fs
5157 check opts getPkgTest $ \fs -> runIO $ do
52− mapM_ (testPkg opts) fs
58+
59+ codes <- mapM (testPkg opts) fs
60+ -- check if any of the tests exited with an exit code other
61+ -- than zero; if they did, exit with exit code 1
62+ unless (null $ filter (/= ExitSuccess) codes) $
63+ exitWith (ExitFailure 1)
64+
5365 check opts getPkg $ \fs -> runIO $ do
5466 mapM_ (buildPkg opts (WarnOnly `elem` opts)) fs
5567 check opts getPkgREPL $ \fs -> case fs of
src/Idris/Package.hs+36−33
@@ -145,6 +145,7 @@ replPkg copts fp = do
145145 case mergeOptions copts (idris_opts pkgdesc) of
146146 Left emsg -> ifail emsg
147147 Right opts -> do
148+
148149 putIState orig
149150 dir <- runIO getCurrentDirectory
150151 runIO $ setCurrentDirectory $ dir </> sourcedir pkgdesc
@@ -237,42 +238,44 @@ documentPkg copts (install,fp) = do
237238-- | Build a package with a sythesized main function that runs the tests
238239testPkg :: [Opt] -- ^ Command line options.
239240 -> FilePath -- ^ Path to ipkg file.
240− -> IO ()
241+ -> IO ExitCode
241242testPkg copts fp = do
242243 pkgdesc <- parseDesc fp
243244 ok <- mapM (testLib True (pkgname pkgdesc)) (libdeps pkgdesc)
244− when (and ok) $ do
245− m_ist <- inPkgDir pkgdesc $ do
246− make (makefile pkgdesc)
247− -- Get a temporary file to save the tests' source in
248− (tmpn, tmph) <- tempfile ".idr"
249− hPutStrLn tmph $
250− "module Test_______\n" ++
251− concat ["import " ++ show m ++ "\n" | m <- modules pkgdesc]
252− ++ "namespace Main\n"
253− ++ " main : IO ()\n"
254− ++ " main = do "
255− ++ concat [ show t ++ "\n "
256− | t <- idris_tests pkgdesc]
257− hClose tmph
258− (tmpn', tmph') <- tempfile ""
259− hClose tmph'
260− let popts = (Filename tmpn : NoREPL : Verbose : Output tmpn' : idris_opts pkgdesc)
261− case mergeOptions copts popts of
262− Left emsg -> do
263− putStrLn emsg
264− exitWith (ExitFailure 1)
265− Right opts -> do
266− m_ist <- idris opts
267− rawSystem tmpn' []
268− return m_ist
269− case m_ist of
270− Nothing -> exitWith (ExitFailure 1)
271− Just ist -> do
272− -- Quit with error code if problem building
273− case errSpan ist of
274− Just _ -> exitWith (ExitFailure 1)
275− _ -> return ()
245+ if and ok
246+ then do
247+ (m_ist, exitCode) <- inPkgDir pkgdesc $ do
248+ make (makefile pkgdesc)
249+ -- Get a temporary file to save the tests' source in
250+ (tmpn, tmph) <- tempfile ".idr"
251+ hPutStrLn tmph $
252+ "module Test_______\n" ++
253+ concat ["import " ++ show m ++ "\n" | m <- modules pkgdesc]
254+ ++ "namespace Main\n"
255+ ++ " main : IO ()\n"
256+ ++ " main = do "
257+ ++ concat [ show t ++ "\n "
258+ | t <- idris_tests pkgdesc]
259+ hClose tmph
260+ (tmpn', tmph') <- tempfile ""
261+ hClose tmph'
262+ let popts = (Filename tmpn : NoREPL : Verbose : Output tmpn' : idris_opts pkgdesc)
263+ case mergeOptions copts popts of
264+ Left emsg -> do
265+ putStrLn emsg
266+ exitWith (ExitFailure 1)
267+ Right opts -> do
268+ m_ist <- idris opts
269+ exitCode <- rawSystem tmpn' []
270+ return (m_ist, exitCode)
271+ case m_ist of
272+ Nothing -> exitWith (ExitFailure 1)
273+ Just ist -> do
274+ -- Quit with error code if problem building
275+ case errSpan ist of
276+ Just _ -> exitWith (ExitFailure 1)
277+ _ -> return exitCode
278+ else return (ExitFailure 1)
276279
277280-- ----------------------------------------------------------- [ Installation ]
278281