diff options
author | Brad Richardson <everythingfunctional@protonmail.com> | 2020-11-16 11:56:33 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-16 11:56:33 -0600 |
commit | 213d34325da7a1fc01bae0dd420faf3a06381883 (patch) | |
tree | 4af6e4a2262ed8d39aa936237b34831fbdafa98d | |
parent | ca1a0e4f50db32770b6e9aa60db9ce0b660b5bf8 (diff) | |
parent | ffd95a4179276d49fd4d2a277c2eba905dc43b7a (diff) | |
download | fpm-213d34325da7a1fc01bae0dd420faf3a06381883.tar.gz fpm-213d34325da7a1fc01bae0dd420faf3a06381883.zip |
Merge pull request #221 from everythingfunctional/test_runner_option
Test and executable runner options
-rw-r--r-- | bootstrap/src/Fpm.hs | 163 | ||||
-rw-r--r-- | bootstrap/test/Spec.hs | 5 |
2 files changed, 95 insertions, 73 deletions
diff --git a/bootstrap/src/Fpm.hs b/bootstrap/src/Fpm.hs index 256f8e1..943393e 100644 --- a/bootstrap/src/Fpm.hs +++ b/bootstrap/src/Fpm.hs @@ -94,6 +94,7 @@ data Arguments = { runRelease :: Bool , runCompiler :: FilePath , runFlags :: [String] + , runRunner :: Maybe String , runTarget :: Maybe String , runArgs :: Maybe [String] } @@ -101,6 +102,7 @@ data Arguments = { testRelease :: Bool , testCompiler :: FilePath , testFlags :: [String] + , testRunner :: Maybe String , testTarget :: Maybe String , testArgs :: Maybe [String] } @@ -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 @@ -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 () @@ -422,6 +427,12 @@ runArguments = ) <*> 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 "Name of the executable to run" ) @@ -459,6 +470,12 @@ testArguments = ) <*> 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" ) ) diff --git a/bootstrap/test/Spec.hs b/bootstrap/test/Spec.hs index dfa73df..215024d 100644 --- a/bootstrap/test/Spec.hs +++ b/bootstrap/test/Spec.hs @@ -22,6 +22,7 @@ testHelloWorld = { runRelease = False , runCompiler = "gfortran" , runFlags = [] + , runRunner = Nothing , runTarget = Nothing , runArgs = Nothing } @@ -32,6 +33,7 @@ testHelloComplex = { testRelease = False , testCompiler = "gfortran" , testFlags = [] + , testRunner = Nothing , testTarget = Nothing , testArgs = Nothing } @@ -42,6 +44,7 @@ testHelloFpm = { runRelease = False , runCompiler = "gfortran" , runFlags = [] + , runRunner = Nothing , runTarget = Nothing , runArgs = Nothing } @@ -52,6 +55,7 @@ testCircular = { testRelease = False , testCompiler = "gfortran" , testFlags = [] + , testRunner = Nothing , testTarget = Nothing , testArgs = Nothing } @@ -70,6 +74,7 @@ testMakefileComplex = { runRelease = False , runCompiler = "gfortran" , runFlags = [] + , runRunner = Nothing , runTarget = Nothing , runArgs = Nothing } |