main-tester-0.1.0.0: Capture stdout/stderr/exit code, and replace stdin of your main function.

Safe HaskellSafe
LanguageHaskell2010

Test.Main

Contents

Synopsis

Utilities for testing your main function

captureProcessResult :: IO () -> IO ProcessResult Source #

Capture stdout, stderr, and exit code of the given IO action.

>>> let main = putStr "hello"
>>> captureProcessResult main
ProcessResult {prStdout = "hello", prStderr = "", prExitCode = ExitSuccess}

If the IO action exit with error message, the exit code of result is ExitFailure.

>>> import System.IO
>>> import System.Exit
>>> let main = hPutStr stderr "OMG!" >> exitWith (ExitFailure 1)
>>> captureProcessResult main
ProcessResult {prStdout = "", prStderr = "OMG!", prExitCode = ExitFailure 1}

withStdin :: ByteString -> IO a -> IO a Source #

Pass the ByteString to stdin of the given IO action.

>>> import Data.ByteString.Char8 ()
>>> :set -XOverloadedStrings
>>> let main = putStrLn . reverse =<< getLine
>>> withStdin "abcde" main
edcba

Re-export from System.Environment

withArgs :: [String] -> IO a -> IO a #

withArgs args act - while executing action act, have getArgs return args.

Re-export from System.Exit

data ExitCode :: * #

Defines the exit codes that a program can return.

Constructors

ExitSuccess

indicates successful termination;