aboutsummaryrefslogblamecommitdiff
path: root/haddock-test/src/Test/Haddock/Process.hs
blob: 52bf95333afcc65587448970ca11c2a41b80cd8d (plain) (tree)
1
2
3
4
5
6
7
8
9







                                 













                                     
                   






















                                                            
{-# LANGUAGE RecordWildCards #-}


module Test.Haddock.Process where


import Control.Monad

import System.Exit
import System.IO
import System.Process


type Environment = [(String, String)]


data ProcessConfig = ProcessConfig
    { pcArgs :: [String]
    , pcWorkDir :: Maybe FilePath
    , pcEnv :: Maybe Environment
    , pcStdIn :: Maybe Handle
    , pcStdOut :: Maybe Handle
    , pcStdErr :: Maybe Handle
    }
    deriving (Show)


processConfig :: ProcessConfig
processConfig = ProcessConfig
    { pcArgs = []
    , pcWorkDir = Nothing
    , pcEnv = Nothing
    , pcStdIn = Nothing
    , pcStdOut = Nothing
    , pcStdErr = Nothing
    }


runProcess' :: FilePath -> ProcessConfig -> IO ProcessHandle
runProcess' path (ProcessConfig { .. }) = runProcess
    path pcArgs pcWorkDir pcEnv pcStdIn pcStdOut pcStdErr


waitForSuccess :: String -> ProcessHandle -> IO ()
waitForSuccess msg handle = do
    result <- waitForProcess handle
    unless (result == ExitSuccess) $ do
        hPutStrLn stderr $ msg
        exitFailure