@@ -30,6 +30,7 @@ main = do
3030 [] -> usage
3131 [" --version" ] -> putStrLn version
3232 " build" : as -> decodeGit cmdBuild env as
33+ " test" : as -> cmdTest env as
3334 " clean" : as -> cmdClean env as
3435 " fetch" : as -> decodeGit cmdFetch env as
3536 " help" : as -> cmdHelp env as
@@ -257,6 +258,10 @@ cmdBuild env [apkg] = do
257258 cmdBuild env []
258259cmdBuild _ _ = usage
259260
261+ cmdTest :: Env -> [String ] -> IO ()
262+ cmdTest env [] = build env { targets = TgtTst : targets env }
263+ cmdTest _ _ = usage
264+
260265getGlobal :: Cabal -> Section
261266getGlobal (Cabal sects) =
262267 fromMaybe (error " no global section" ) $ listToMaybe [ s | s@ (Section " global" _ _) <- sects ]
@@ -296,19 +301,22 @@ build env = do
296301 sectLib s@ (Section " library" _ _) | TgtLib `elem` targets env && isBuildable s = buildLib env glob s
297302 sectLib s@ (Section " foreign-library" _ _) | TgtFor `elem` targets env && isBuildable s = buildForeignLib env glob s
298303 sectLib _ = return Nothing
299- sectExe ll s@ (Section " executable" _ _) | TgtExe `elem` targets env && isBuildable s = buildExe env glob s ll
304+ sectExe ll s@ (Section " executable" _ _) | TgtExe `elem` targets env && isBuildable s = void $ buildExe env glob s ll
300305 sectExe _ _ = return ()
306+ sectTst ll s@ (Section " test-suite" _ _) | TgtTst `elem` targets env && isBuildable s = buildExe env glob s ll >>= cmd env
307+ sectTst _ _ = return ()
301308 sects' = addMissing sects
302309 message env 3 $ " Unnormalized Cabal file:\n " ++ show cbl
303310 message env 2 $ " Normalized Cabal file:\n " ++ show ncbl
304311 -- Build libs first, then exes
305- localLibs <- mapM sectLib sects'
306- mapM_ (sectExe $ catMaybes localLibs) sects'
312+ localLibs <- catMaybes <$> mapM sectLib sects'
313+ mapM_ (sectExe localLibs) sects'
314+ mapM_ (sectTst localLibs) sects'
307315
308316isBuildable :: Section -> Bool
309317isBuildable (Section _ _ flds) = getFieldBool True flds " buildable"
310318
311- buildExe :: Env -> Section -> Section -> [Name ] -> IO ()
319+ buildExe :: Env -> Section -> Section -> [Name ] -> IO FilePath
312320buildExe env glob@ (Section _ _ sglob) sect@ (Section _ name flds) localLibs = do
313321 message env 0 $ " Building executable " ++ name
314322 createPathFile env glob sect
@@ -469,6 +477,7 @@ cmdHelp :: Env -> [String] -> IO ()
469477cmdHelp _ _ = putStrLn " \
470478 \Available commands:\n \
471479 \ mcabal [FLAGS] build [--git=URL [--dir=DIR]] [PKG] build in current directory, or the package PKG\n \
480+ \ mcabal [FLAGS] test build and run tests in current directory\n \
472481 \ mcabal [FLAGS] clean clean in the current directory\n \
473482 \ mcabal [FLAGS] fetch [--git=URL [--dir=DIR]] PKG fetch files for package PKG\n \
474483 \ mcabal [FLAGS] help show this message\n \
0 commit comments