on master help sign in
Merge pull request #3265 from crough/test-exitcode
ed6c0ffJan de Muijnck-Hughes
main/Main.hs+15−3
@@ -1,5 +1,11 @@
1module Main where
1module Main where
2
2
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+
3import Idris.AbsSyntax
9import Idris.AbsSyntax
4import Idris.CmdOptions
10import Idris.CmdOptions
5import Idris.Error
11import Idris.Error
@@ -9,8 +15,8 @@ import Idris.Package
9
15
10import Util.System (setupBundledCC)
16import Util.System (setupBundledCC)
11
17
12−import Control.Monad (when)
18+import Util.System ( setupBundledCC )
13−import System.Exit (exitSuccess)
19+import System.Exit ( ExitCode(..), exitWith)
14
20
15processShowOptions :: [Opt] -> Idris ()
21processShowOptions :: [Opt] -> Idris ()
16processShowOptions opts = runIO $ do
22processShowOptions opts = runIO $ do
@@ -49,7 +55,13 @@ processPackageOptions opts = do
49 check opts getPkgMkDoc $ \fs -> runIO $ do
55 check opts getPkgMkDoc $ \fs -> runIO $ do
50 mapM_ (documentPkg opts) fs
56 mapM_ (documentPkg opts) fs
51 check opts getPkgTest $ \fs -> runIO $ do
57 check opts getPkgTest $ \fs -> runIO $ do
58+
52− mapM_ (testPkg opts) fs
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+
53 check opts getPkg $ \fs -> runIO $ do
65 check opts getPkg $ \fs -> runIO $ do
54 mapM_ (buildPkg opts (WarnOnly `elem` opts)) fs
66 mapM_ (buildPkg opts (WarnOnly `elem` opts)) fs
55 check opts getPkgREPL $ \fs -> case fs of
67 check opts getPkgREPL $ \fs -> case fs of
src/Idris/Package.hs+36−33
@@ -145,6 +145,7 @@ replPkg copts fp = do
145 case mergeOptions copts (idris_opts pkgdesc) of
145 case mergeOptions copts (idris_opts pkgdesc) of
146 Left emsg -> ifail emsg
146 Left emsg -> ifail emsg
147 Right opts -> do
147 Right opts -> do
148+
148 putIState orig
149 putIState orig
149 dir <- runIO getCurrentDirectory
150 dir <- runIO getCurrentDirectory
150 runIO $ setCurrentDirectory $ dir </> sourcedir pkgdesc
151 runIO $ setCurrentDirectory $ dir </> sourcedir pkgdesc
@@ -237,42 +238,44 @@ documentPkg copts (install,fp) = do
237-- | Build a package with a sythesized main function that runs the tests
238-- | Build a package with a sythesized main function that runs the tests
238testPkg :: [Opt] -- ^ Command line options.
239testPkg :: [Opt] -- ^ Command line options.
239 -> FilePath -- ^ Path to ipkg file.
240 -> FilePath -- ^ Path to ipkg file.
240− -> IO ()
241+ -> IO ExitCode
241testPkg copts fp = do
242testPkg copts fp = do
242 pkgdesc <- parseDesc fp
243 pkgdesc <- parseDesc fp
243 ok <- mapM (testLib True (pkgname pkgdesc)) (libdeps pkgdesc)
244 ok <- mapM (testLib True (pkgname pkgdesc)) (libdeps pkgdesc)
244− when (and ok) $ do
245+ if and ok
246+ then do
245− m_ist <- inPkgDir pkgdesc $ do
247+ (m_ist, exitCode) <- inPkgDir pkgdesc $ do
246− make (makefile pkgdesc)
248+ make (makefile pkgdesc)
247− -- Get a temporary file to save the tests' source in
249+ -- Get a temporary file to save the tests' source in
248− (tmpn, tmph) <- tempfile ".idr"
250+ (tmpn, tmph) <- tempfile ".idr"
249− hPutStrLn tmph $
251+ hPutStrLn tmph $
250− "module Test_______\n" ++
252+ "module Test_______\n" ++
251− concat ["import " ++ show m ++ "\n" | m <- modules pkgdesc]
253+ concat ["import " ++ show m ++ "\n" | m <- modules pkgdesc]
252− ++ "namespace Main\n"
254+ ++ "namespace Main\n"
253− ++ " main : IO ()\n"
255+ ++ " main : IO ()\n"
254− ++ " main = do "
256+ ++ " main = do "
255− ++ concat [ show t ++ "\n "
257+ ++ concat [ show t ++ "\n "
256− | t <- idris_tests pkgdesc]
258+ | t <- idris_tests pkgdesc]
257− hClose tmph
259+ hClose tmph
258− (tmpn', tmph') <- tempfile ""
260+ (tmpn', tmph') <- tempfile ""
259− hClose tmph'
261+ hClose tmph'
260− let popts = (Filename tmpn : NoREPL : Verbose : Output tmpn' : idris_opts pkgdesc)
262+ let popts = (Filename tmpn : NoREPL : Verbose : Output tmpn' : idris_opts pkgdesc)
261− case mergeOptions copts popts of
263+ case mergeOptions copts popts of
262− Left emsg -> do
264+ Left emsg -> do
263− putStrLn emsg
265+ putStrLn emsg
264− exitWith (ExitFailure 1)
266+ exitWith (ExitFailure 1)
265− Right opts -> do
267+ Right opts -> do
266− m_ist <- idris opts
268+ m_ist <- idris opts
267− rawSystem tmpn' []
269+ exitCode <- rawSystem tmpn' []
268− return m_ist
270+ return (m_ist, exitCode)
269− case m_ist of
271+ case m_ist of
270− Nothing -> exitWith (ExitFailure 1)
272+ Nothing -> exitWith (ExitFailure 1)
271− Just ist -> do
273+ Just ist -> do
272− -- Quit with error code if problem building
274+ -- Quit with error code if problem building
273− case errSpan ist of
275+ case errSpan ist of
274− Just _ -> exitWith (ExitFailure 1)
276+ Just _ -> exitWith (ExitFailure 1)
275− _ -> return ()
277+ _ -> return exitCode
278+ else return (ExitFailure 1)
276
279
277-- ----------------------------------------------------------- [ Installation ]
280-- ----------------------------------------------------------- [ Installation ]
278
281