Skip to content

Test and executable runner options #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 90 additions & 73 deletions bootstrap/src/Fpm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ data Arguments =
{ runRelease :: Bool
, runCompiler :: FilePath
, runFlags :: [String]
, runRunner :: Maybe String
, runTarget :: Maybe String
, runArgs :: Maybe [String]
}
| Test
{ testRelease :: Bool
, testCompiler :: FilePath
, testFlags :: [String]
, testRunner :: Maybe String
, testTarget :: Maybe String
, testArgs :: Maybe [String]
}
Expand Down Expand Up @@ -166,7 +168,7 @@ start args = case args of
app :: Arguments -> AppSettings -> IO ()
app args settings = case args of
Build{} -> build settings
Run { runTarget = whichOne, runArgs = runArgs } -> do
Run { runTarget = whichOne, runArgs = runArgs, runRunner = runner } -> do
build settings
let buildPrefix = appSettingsBuildPrefix settings
let
Expand All @@ -180,78 +182,81 @@ app args settings = case args of
canonicalExecutables <- mapM makeAbsolute executables
case canonicalExecutables of
[] -> putStrLn "No Executables Found"
_ -> case whichOne of
Nothing -> do
exitCodes <- mapM
system
(map
(++ case runArgs of
Nothing -> ""
Just theArgs -> " " ++ (intercalate " " theArgs)
)
canonicalExecutables
)
forM_
exitCodes
(\exitCode -> when
(case exitCode of
ExitSuccess -> False
_ -> True
)
(exitWith exitCode)
)
Just name -> do
case find (name `isSuffixOf`) canonicalExecutables of
Nothing -> putStrLn "Executable Not Found"
Just specified -> do
exitCode <- case runArgs of
Nothing -> system specified
Just theArgs ->
system (specified ++ " " ++ (intercalate " " theArgs))
exitWith exitCode
Test { testTarget = whichOne, testArgs = testArgs } -> do
build settings
let buildPrefix = appSettingsBuildPrefix settings
let
executableNames = map
(\Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
sourceDir </> name
)
(appSettingsTests settings)
let executables =
map (buildPrefix </>) $ map (flip (<.>) exe) executableNames
canonicalExecutables <- mapM makeAbsolute executables
case canonicalExecutables of
[] -> putStrLn "No Tests Found"
_ -> case whichOne of
Nothing -> do
exitCodes <- mapM
system
(map
(++ case testArgs of
Nothing -> ""
Just theArgs -> " " ++ (intercalate " " theArgs)
)
canonicalExecutables
)
forM_
exitCodes
(\exitCode -> when
(case exitCode of
ExitSuccess -> False
_ -> True
)
(exitWith exitCode)
)
Just name -> do
case find (name `isSuffixOf`) canonicalExecutables of
Nothing -> putStrLn "Test Not Found"
Just specified -> do
exitCode <- case testArgs of
Nothing -> system specified
Just theArgs ->
system (specified ++ " " ++ (intercalate " " theArgs))
exitWith exitCode
_ ->
let commandPrefix = case runner of
Nothing -> ""
Just r -> r ++ " "
commandSufix = case runArgs of
Nothing -> ""
Just a -> " " ++ (intercalate " " a)
in case whichOne of
Nothing -> do
exitCodes <- mapM
system
(map (\exe -> commandPrefix ++ exe ++ commandSufix)
canonicalExecutables
)
forM_
exitCodes
(\exitCode -> when
(case exitCode of
ExitSuccess -> False
_ -> True
)
(exitWith exitCode)
)
Just name -> do
case find (name `isSuffixOf`) canonicalExecutables of
Nothing -> putStrLn "Executable Not Found"
Just specified -> do
exitCode <- system
(commandPrefix ++ specified ++ commandSufix)
exitWith exitCode
Test { testTarget = whichOne, testArgs = testArgs, testRunner = runner } ->
do
build settings
let buildPrefix = appSettingsBuildPrefix settings
let
executableNames = map
(\Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
sourceDir </> name
)
(appSettingsTests settings)
let executables =
map (buildPrefix </>) $ map (flip (<.>) exe) executableNames
canonicalExecutables <- mapM makeAbsolute executables
case canonicalExecutables of
[] -> putStrLn "No Tests Found"
_ ->
let commandPrefix = case runner of
Nothing -> ""
Just r -> r ++ " "
commandSufix = case testArgs of
Nothing -> ""
Just a -> " " ++ (intercalate " " a)
in case whichOne of
Nothing -> do
exitCodes <- mapM
system
(map (\exe -> commandPrefix ++ exe ++ commandSufix)
canonicalExecutables
)
forM_
exitCodes
(\exitCode -> when
(case exitCode of
ExitSuccess -> False
_ -> True
)
(exitWith exitCode)
)
Just name -> do
case find (name `isSuffixOf`) canonicalExecutables of
Nothing -> putStrLn "Test Not Found"
Just specified -> do
exitCode <- system
(commandPrefix ++ specified ++ commandSufix)
exitWith exitCode
_ -> putStrLn "Shouldn't be able to get here"

build :: AppSettings -> IO ()
Expand Down Expand Up @@ -420,6 +425,12 @@ runArguments =
"specify an addional argument to pass to the compiler (can appear multiple times)"
)
)
<*> optional
(strOption
(long "runner" <> metavar "RUNNER" <> help
"specify a command to be used to run the executable(s)"
)
)
<*> optional
(strOption
(long "target" <> metavar "TARGET" <> help
Expand Down Expand Up @@ -457,6 +468,12 @@ testArguments =
"specify an addional argument to pass to the compiler (can appear multiple times)"
)
)
<*> optional
(strOption
(long "runner" <> metavar "RUNNER" <> help
"specify a command to be used to run the test(s)"
)
)
<*> optional
(strOption
(long "target" <> metavar "TARGET" <> help "Name of the test to run"
Expand Down
5 changes: 5 additions & 0 deletions bootstrap/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ testHelloWorld =
{ runRelease = False
, runCompiler = "gfortran"
, runFlags = []
, runRunner = Nothing
, runTarget = Nothing
, runArgs = Nothing
}
Expand All @@ -32,6 +33,7 @@ testHelloComplex =
{ testRelease = False
, testCompiler = "gfortran"
, testFlags = []
, testRunner = Nothing
, testTarget = Nothing
, testArgs = Nothing
}
Expand All @@ -42,6 +44,7 @@ testHelloFpm =
{ runRelease = False
, runCompiler = "gfortran"
, runFlags = []
, runRunner = Nothing
, runTarget = Nothing
, runArgs = Nothing
}
Expand All @@ -52,6 +55,7 @@ testCircular =
{ testRelease = False
, testCompiler = "gfortran"
, testFlags = []
, testRunner = Nothing
, testTarget = Nothing
, testArgs = Nothing
}
Expand All @@ -70,6 +74,7 @@ testMakefileComplex =
{ runRelease = False
, runCompiler = "gfortran"
, runFlags = []
, runRunner = Nothing
, runTarget = Nothing
, runArgs = Nothing
}
Expand Down