1- {-# LANGUAGE OverloadedStrings #-}
2-
31module Test.Smoke.Executable where
42
5- import Control.Monad (unless )
6- import Control.Monad.IO.Class (liftIO )
7- import Control.Monad.Trans.Except (ExceptT , throwE )
3+ import Control.Monad.Trans.Except (ExceptT )
84import Data.Text (Text )
95import qualified Data.Text.IO as Text.IO
106import qualified Data.Vector as Vector
11- import Data.Vector (Vector )
12- import qualified System.Directory as Directory
137import System.Exit (ExitCode )
148import System.IO (hClose )
159import System.IO.Temp (withSystemTempFile )
1610import System.Process (CreateProcess (.. ), proc )
1711import System.Process.Text (readCreateProcessWithExitCode )
1812import Test.Smoke.Paths
13+ import Test.Smoke.Shell
1914import Test.Smoke.Types
2015
21- defaultShell :: ExceptT SmokeExecutableError IO Shell
22- defaultShell = do
23- sh <- findExecutable $ parseFile " sh"
24- return $ Shell sh mempty
25-
26- defaultShellExecute :: Vector String
27- defaultShellExecute = Vector. fromList [" sh" , " -c" ]
28-
29- shellFromCommandLine :: CommandLine -> ExceptT SmokeExecutableError IO Shell
30- shellFromCommandLine (CommandLine shellName shellArgs) = do
31- shellCommand <- findExecutable shellName
32- return $ Shell shellCommand shellArgs
33-
3416runExecutable ::
3517 Executable
3618 -> Args
@@ -45,7 +27,7 @@ runExecutable (ExecutableProgram executablePath executableArgs) args (StdIn stdI
4527 {cwd = toFilePath . unWorkingDirectory <$> workingDirectory})
4628 stdIn
4729runExecutable (ExecutableScript (Shell shellPath shellArgs) (Script script)) args stdIn workingDirectory =
48- withSystemTempFile " smoke.sh " $ \ scriptPath scriptHandle -> do
30+ withSystemTempFile defaultShellScriptName $ \ scriptPath scriptHandle -> do
4931 Text.IO. hPutStr scriptHandle script
5032 hClose scriptHandle
5133 let executableArgs = shellArgs <> Args (Vector. singleton scriptPath)
@@ -56,7 +38,7 @@ runExecutable (ExecutableScript (Shell shellPath shellArgs) (Script script)) arg
5638 workingDirectory
5739
5840convertCommandToExecutable ::
59- Maybe Shell -> Command -> ExceptT SmokeExecutableError IO Executable
41+ Maybe Shell -> Command -> ExceptT PathError IO Executable
6042convertCommandToExecutable _ (CommandArgs (CommandLine executableName commandArgs)) = do
6143 executablePath <- findExecutable executableName
6244 return $ ExecutableProgram executablePath commandArgs
@@ -69,19 +51,7 @@ convertCommandToExecutable _ (CommandScript (Just commandLine) script) = do
6951 shell <- shellFromCommandLine commandLine
7052 return $ ExecutableScript shell script
7153
72- findExecutable ::
73- RelativePath File -> ExceptT SmokeExecutableError IO (ResolvedPath File )
74- findExecutable path = do
75- exists <- liftIO $ Directory. doesFileExist (toFilePath path)
76- if exists
77- then do
78- permissions <- liftIO $ Directory. getPermissions (toFilePath path)
79- unless (Directory. executable permissions) $
80- throwE $ FileIsNotExecutable path
81- liftIO $ resolve path
82- else do
83- executable <- liftIO $ Directory. findExecutable (toFilePath path)
84- maybe
85- (throwE $ CouldNotFindExecutable path)
86- (liftIO . resolve . parseFile)
87- executable
54+ shellFromCommandLine :: CommandLine -> ExceptT PathError IO Shell
55+ shellFromCommandLine (CommandLine shellName shellArgs) = do
56+ shellCommand <- findExecutable shellName
57+ return $ Shell shellCommand shellArgs
0 commit comments