Skip to content

Commit 213d343

Browse files
Merge pull request #221 from everythingfunctional/test_runner_option
Test and executable runner options
2 parents ca1a0e4 + ffd95a4 commit 213d343

File tree

2 files changed

+95
-73
lines changed

2 files changed

+95
-73
lines changed

bootstrap/src/Fpm.hs

Lines changed: 90 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,15 @@ data Arguments =
9494
{ runRelease :: Bool
9595
, runCompiler :: FilePath
9696
, runFlags :: [String]
97+
, runRunner :: Maybe String
9798
, runTarget :: Maybe String
9899
, runArgs :: Maybe [String]
99100
}
100101
| Test
101102
{ testRelease :: Bool
102103
, testCompiler :: FilePath
103104
, testFlags :: [String]
105+
, testRunner :: Maybe String
104106
, testTarget :: Maybe String
105107
, testArgs :: Maybe [String]
106108
}
@@ -166,7 +168,7 @@ start args = case args of
166168
app :: Arguments -> AppSettings -> IO ()
167169
app args settings = case args of
168170
Build{} -> build settings
169-
Run { runTarget = whichOne, runArgs = runArgs } -> do
171+
Run { runTarget = whichOne, runArgs = runArgs, runRunner = runner } -> do
170172
build settings
171173
let buildPrefix = appSettingsBuildPrefix settings
172174
let
@@ -180,78 +182,81 @@ app args settings = case args of
180182
canonicalExecutables <- mapM makeAbsolute executables
181183
case canonicalExecutables of
182184
[] -> putStrLn "No Executables Found"
183-
_ -> case whichOne of
184-
Nothing -> do
185-
exitCodes <- mapM
186-
system
187-
(map
188-
(++ case runArgs of
189-
Nothing -> ""
190-
Just theArgs -> " " ++ (intercalate " " theArgs)
191-
)
192-
canonicalExecutables
193-
)
194-
forM_
195-
exitCodes
196-
(\exitCode -> when
197-
(case exitCode of
198-
ExitSuccess -> False
199-
_ -> True
200-
)
201-
(exitWith exitCode)
202-
)
203-
Just name -> do
204-
case find (name `isSuffixOf`) canonicalExecutables of
205-
Nothing -> putStrLn "Executable Not Found"
206-
Just specified -> do
207-
exitCode <- case runArgs of
208-
Nothing -> system specified
209-
Just theArgs ->
210-
system (specified ++ " " ++ (intercalate " " theArgs))
211-
exitWith exitCode
212-
Test { testTarget = whichOne, testArgs = testArgs } -> do
213-
build settings
214-
let buildPrefix = appSettingsBuildPrefix settings
215-
let
216-
executableNames = map
217-
(\Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
218-
sourceDir </> name
219-
)
220-
(appSettingsTests settings)
221-
let executables =
222-
map (buildPrefix </>) $ map (flip (<.>) exe) executableNames
223-
canonicalExecutables <- mapM makeAbsolute executables
224-
case canonicalExecutables of
225-
[] -> putStrLn "No Tests Found"
226-
_ -> case whichOne of
227-
Nothing -> do
228-
exitCodes <- mapM
229-
system
230-
(map
231-
(++ case testArgs of
232-
Nothing -> ""
233-
Just theArgs -> " " ++ (intercalate " " theArgs)
234-
)
235-
canonicalExecutables
236-
)
237-
forM_
238-
exitCodes
239-
(\exitCode -> when
240-
(case exitCode of
241-
ExitSuccess -> False
242-
_ -> True
243-
)
244-
(exitWith exitCode)
245-
)
246-
Just name -> do
247-
case find (name `isSuffixOf`) canonicalExecutables of
248-
Nothing -> putStrLn "Test Not Found"
249-
Just specified -> do
250-
exitCode <- case testArgs of
251-
Nothing -> system specified
252-
Just theArgs ->
253-
system (specified ++ " " ++ (intercalate " " theArgs))
254-
exitWith exitCode
185+
_ ->
186+
let commandPrefix = case runner of
187+
Nothing -> ""
188+
Just r -> r ++ " "
189+
commandSufix = case runArgs of
190+
Nothing -> ""
191+
Just a -> " " ++ (intercalate " " a)
192+
in case whichOne of
193+
Nothing -> do
194+
exitCodes <- mapM
195+
system
196+
(map (\exe -> commandPrefix ++ exe ++ commandSufix)
197+
canonicalExecutables
198+
)
199+
forM_
200+
exitCodes
201+
(\exitCode -> when
202+
(case exitCode of
203+
ExitSuccess -> False
204+
_ -> True
205+
)
206+
(exitWith exitCode)
207+
)
208+
Just name -> do
209+
case find (name `isSuffixOf`) canonicalExecutables of
210+
Nothing -> putStrLn "Executable Not Found"
211+
Just specified -> do
212+
exitCode <- system
213+
(commandPrefix ++ specified ++ commandSufix)
214+
exitWith exitCode
215+
Test { testTarget = whichOne, testArgs = testArgs, testRunner = runner } ->
216+
do
217+
build settings
218+
let buildPrefix = appSettingsBuildPrefix settings
219+
let
220+
executableNames = map
221+
(\Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
222+
sourceDir </> name
223+
)
224+
(appSettingsTests settings)
225+
let executables =
226+
map (buildPrefix </>) $ map (flip (<.>) exe) executableNames
227+
canonicalExecutables <- mapM makeAbsolute executables
228+
case canonicalExecutables of
229+
[] -> putStrLn "No Tests Found"
230+
_ ->
231+
let commandPrefix = case runner of
232+
Nothing -> ""
233+
Just r -> r ++ " "
234+
commandSufix = case testArgs of
235+
Nothing -> ""
236+
Just a -> " " ++ (intercalate " " a)
237+
in case whichOne of
238+
Nothing -> do
239+
exitCodes <- mapM
240+
system
241+
(map (\exe -> commandPrefix ++ exe ++ commandSufix)
242+
canonicalExecutables
243+
)
244+
forM_
245+
exitCodes
246+
(\exitCode -> when
247+
(case exitCode of
248+
ExitSuccess -> False
249+
_ -> True
250+
)
251+
(exitWith exitCode)
252+
)
253+
Just name -> do
254+
case find (name `isSuffixOf`) canonicalExecutables of
255+
Nothing -> putStrLn "Test Not Found"
256+
Just specified -> do
257+
exitCode <- system
258+
(commandPrefix ++ specified ++ commandSufix)
259+
exitWith exitCode
255260
_ -> putStrLn "Shouldn't be able to get here"
256261

257262
build :: AppSettings -> IO ()
@@ -420,6 +425,12 @@ runArguments =
420425
"specify an addional argument to pass to the compiler (can appear multiple times)"
421426
)
422427
)
428+
<*> optional
429+
(strOption
430+
(long "runner" <> metavar "RUNNER" <> help
431+
"specify a command to be used to run the executable(s)"
432+
)
433+
)
423434
<*> optional
424435
(strOption
425436
(long "target" <> metavar "TARGET" <> help
@@ -457,6 +468,12 @@ testArguments =
457468
"specify an addional argument to pass to the compiler (can appear multiple times)"
458469
)
459470
)
471+
<*> optional
472+
(strOption
473+
(long "runner" <> metavar "RUNNER" <> help
474+
"specify a command to be used to run the test(s)"
475+
)
476+
)
460477
<*> optional
461478
(strOption
462479
(long "target" <> metavar "TARGET" <> help "Name of the test to run"

bootstrap/test/Spec.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ testHelloWorld =
2222
{ runRelease = False
2323
, runCompiler = "gfortran"
2424
, runFlags = []
25+
, runRunner = Nothing
2526
, runTarget = Nothing
2627
, runArgs = Nothing
2728
}
@@ -32,6 +33,7 @@ testHelloComplex =
3233
{ testRelease = False
3334
, testCompiler = "gfortran"
3435
, testFlags = []
36+
, testRunner = Nothing
3537
, testTarget = Nothing
3638
, testArgs = Nothing
3739
}
@@ -42,6 +44,7 @@ testHelloFpm =
4244
{ runRelease = False
4345
, runCompiler = "gfortran"
4446
, runFlags = []
47+
, runRunner = Nothing
4548
, runTarget = Nothing
4649
, runArgs = Nothing
4750
}
@@ -52,6 +55,7 @@ testCircular =
5255
{ testRelease = False
5356
, testCompiler = "gfortran"
5457
, testFlags = []
58+
, testRunner = Nothing
5559
, testTarget = Nothing
5660
, testArgs = Nothing
5761
}
@@ -70,6 +74,7 @@ testMakefileComplex =
7074
{ runRelease = False
7175
, runCompiler = "gfortran"
7276
, runFlags = []
77+
, runRunner = Nothing
7378
, runTarget = Nothing
7479
, runArgs = Nothing
7580
}

0 commit comments

Comments
 (0)