Skip to content

Commit

Permalink
Merge pull request #150 from everythingfunctional/FixExitCodes
Browse files Browse the repository at this point in the history
Propogate exit codes from tests and executables
  • Loading branch information
everythingfunctional authored Jul 26, 2020
2 parents 3769bd1 + ffbb910 commit fcb7f67
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions bootstrap/src/Fpm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Build ( buildLibrary
, buildWithScript
)
import Control.Monad.Extra ( concatMapM
, forM_
, when
)
import Data.List ( isSuffixOf
Expand Down Expand Up @@ -55,6 +56,9 @@ import System.Directory ( createDirectory
, makeAbsolute
, withCurrentDirectory
)
import System.Exit ( ExitCode(..)
, exitWith
)
import System.Process ( runCommand
, system
)
Expand Down Expand Up @@ -144,15 +148,25 @@ app args settings = case command' args of
case canonicalExecutables of
[] -> putStrLn "No Executables Found"
_ -> case whichOne of
"" -> mapM_
system
(map (++ " " ++ commandArguments args) canonicalExecutables)
"" -> do
exitCodes <- mapM
system
(map (++ " " ++ commandArguments args) canonicalExecutables)
forM_
exitCodes
(\exitCode -> when
(case exitCode of
ExitSuccess -> False
_ -> True
)
(exitWith exitCode)
)
name -> do
case find (name `isSuffixOf`) canonicalExecutables of
Nothing -> putStrLn "Executable Not Found"
Just specified -> do
system (specified ++ " " ++ (commandArguments args))
return ()
exitCode <- system (specified ++ " " ++ (commandArguments args))
exitWith exitCode
Test whichOne -> do
build settings
let buildPrefix = appSettingsBuildPrefix settings
Expand All @@ -168,15 +182,25 @@ app args settings = case command' args of
case canonicalExecutables of
[] -> putStrLn "No Tests Found"
_ -> case whichOne of
"" -> mapM_
system
(map (++ " " ++ commandArguments args) canonicalExecutables)
"" -> do
exitCodes <- mapM
system
(map (++ " " ++ commandArguments args) canonicalExecutables)
forM_
exitCodes
(\exitCode -> when
(case exitCode of
ExitSuccess -> False
_ -> True
)
(exitWith exitCode)
)
name -> do
case find (name `isSuffixOf`) canonicalExecutables of
Nothing -> putStrLn "Test Not Found"
Just specified -> do
system (specified ++ " " ++ (commandArguments args))
return ()
exitCode <- system (specified ++ " " ++ (commandArguments args))
exitWith exitCode

build :: AppSettings -> IO ()
build settings = do
Expand Down Expand Up @@ -285,8 +309,11 @@ arguments =
<> command "test" (info testArguments (progDesc "Run the tests"))
<> command "build"
(info buildArguments (progDesc "Build the executable"))
<> command "new"
(info newArguments (progDesc "Create a new project in a new directory"))
<> command
"new"
(info newArguments
(progDesc "Create a new project in a new directory")
)
)
<*> switch (long "release" <> help "Build in release mode")
<*> strOption
Expand Down

0 comments on commit fcb7f67

Please sign in to comment.