@@ -18,7 +18,7 @@ import System.FilePath (takeDirectory)
1818import System.FilePath.Find (findWithHandler , (==?) , always )
1919import qualified System.FilePath.Find as Find (extension )
2020import System.IO (Handle , hGetContents , hPutStr )
21- import System.Process (StdStream (CreatePipe ), shell , createProcess , CreateProcess (.. ), waitForProcess , ProcessHandle )
21+ import System.Process (StdStream (CreatePipe ), shell , proc , createProcess , CreateProcess (.. ), waitForProcess , ProcessHandle )
2222import Test.Framework (defaultMainWithArgs )
2323import Test.Framework.Providers.HUnit (hUnitTestToTests )
2424import Test.HUnit
@@ -62,6 +62,7 @@ data Args = Args {
6262 ,with :: String
6363 ,timeout :: Int
6464 ,threads :: Int
65+ ,shell_cmd :: Maybe FilePath
6566 ,debug :: Bool
6667 ,debug_parse :: Bool
6768 ,testpaths :: [FilePath ]
@@ -83,6 +84,7 @@ argdefs = Args {
8384 ,with = def &= typ " EXE" &= help " Replace the first word of test commands with EXE (unindented commands only)"
8485 ,timeout = def &= name " o" &= typ " SECS" &= help " Number of seconds a test may run (default: no limit)"
8586 ,threads = def &= name " j" &= typ " N" &= help " Number of threads for running tests (default: 1)"
87+ ,shell_cmd = def &= explicit &= name " shell" &= typ " EXE" &= help " The shell program to use (must accept -c CMD; default: /bin/sh on POSIX, cmd.exe on Windows)"
8688 ,debug = def &= help " Show debug info while running"
8789 ,debug_parse = def &= help " Show test file parsing results and stop"
8890 ,testpaths = def &= args &= typ " TESTFILES|TESTDIRS"
@@ -165,7 +167,7 @@ shellTestToHUnitTest args ShellTest{testname=n,command=c,stdin=i,stdoutExpected=
165167 trim' = if all_ args then id else trim
166168 when (debug args) $ do
167169 printf " actual command was: %s\n " (show cmd)
168- (o_actual, e_actual, x_actual) <- runCommandWithInput dir cmd i
170+ (o_actual, e_actual, x_actual) <- runCommandWithInput (shell_cmd args) dir cmd i
169171 when (debug args) $ do
170172 printf " actual stdout was : %s\n " (show $ trim' o_actual)
171173 printf " actual stderr was : %s\n " (show $ trim' e_actual)
@@ -193,10 +195,10 @@ shellTestToHUnitTest args ShellTest{testname=n,command=c,stdin=i,stdoutExpected=
193195-- | Run a shell command line, passing it standard input if provided,
194196-- and return the standard output, standard error output and exit code.
195197-- Note on unix, at least with ghc 6.12, command (and filepath) are assumed to be utf8-encoded.
196- runCommandWithInput :: Maybe FilePath -> String -> Maybe String -> IO (String , String , Int )
197- runCommandWithInput wd cmd input = do
198+ runCommandWithInput :: Maybe FilePath -> Maybe FilePath -> String -> Maybe String -> IO (String , String , Int )
199+ runCommandWithInput sh wd cmd input = do
198200 -- this has to be done carefully
199- (ih,oh,eh,ph) <- runInteractiveCommandInDir wd cmd
201+ (ih,oh,eh,ph) <- runInteractiveCommandInDir sh wd cmd
200202 when (isJust input) $ forkIO (hPutStr ih $ fromJust input) >> return ()
201203 o <- newEmptyMVar
202204 e <- newEmptyMVar
@@ -207,16 +209,18 @@ runCommandWithInput wd cmd input = do
207209 e_actual <- takeMVar e
208210 return (o_actual, e_actual, x_actual)
209211
210- runInteractiveCommandInDir :: Maybe FilePath -> String -> IO (Handle , Handle , Handle , ProcessHandle )
211- runInteractiveCommandInDir wd cmd = do
212+ runInteractiveCommandInDir :: Maybe FilePath -> Maybe FilePath -> String -> IO (Handle , Handle , Handle , ProcessHandle )
213+ runInteractiveCommandInDir sh wd cmd = do
212214 (mb_in, mb_out, mb_err, p) <-
213215 createProcess $
214- (shell cmd) { cwd = wd
215- , std_in = CreatePipe
216- , std_out = CreatePipe
217- , std_err = CreatePipe }
216+ run { cwd = wd
217+ , std_in = CreatePipe
218+ , std_out = CreatePipe
219+ , std_err = CreatePipe }
218220 -- these should all be Just since we used CreatePipe
219221 return (fromJust mb_in, fromJust mb_out, fromJust mb_err, p)
222+ where
223+ run = maybe (shell cmd) (\ shcmd -> proc shcmd [" -c" , cmd]) sh
220224
221225hGetContentsStrictlyAnd :: Handle -> (String -> IO b ) -> IO b
222226hGetContentsStrictlyAnd h f = hGetContents h >>= \ s -> length s `seq` f s
0 commit comments