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 #

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}

data ProcessResult #

Used for the result of captureProcessResult.

Instances
Eq ProcessResult # 
Instance details

Defined in Test.Main.Internal

Show ProcessResult # 
Instance details

Defined in Test.Main.Internal

Generic ProcessResult # 
Instance details

Defined in Test.Main.Internal

Associated Types

type Rep ProcessResult :: * -> * #

type Rep ProcessResult # 
Instance details

Defined in Test.Main.Internal

type Rep ProcessResult = D1 (MetaData "ProcessResult" "Test.Main.Internal" "main-tester-0.1.0.0-BAaTOLrpEGrDatoSTuO3Hc" False) (C1 (MetaCons "ProcessResult" PrefixI True) (S1 (MetaSel (Just "prStdout") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ByteString) :*: (S1 (MetaSel (Just "prStderr") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ByteString) :*: S1 (MetaSel (Just "prExitCode") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ExitCode))))

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

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;

Instances
Eq ExitCode 
Instance details

Defined in GHC.IO.Exception

Ord ExitCode 
Instance details

Defined in GHC.IO.Exception

Read ExitCode 
Instance details

Defined in GHC.IO.Exception

Show ExitCode 
Instance details

Defined in GHC.IO.Exception

Generic ExitCode 
Instance details

Defined in GHC.IO.Exception

Associated Types

type Rep ExitCode :: * -> * #

Methods

from :: ExitCode -> Rep ExitCode x #

to :: Rep ExitCode x -> ExitCode #

Exception ExitCode

Since: base-4.1.0.0

Instance details

Defined in GHC.IO.Exception

type Rep ExitCode 
Instance details

Defined in GHC.IO.Exception

type Rep ExitCode = D1 (MetaData "ExitCode" "GHC.IO.Exception" "base" False) (C1 (MetaCons "ExitSuccess" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "ExitFailure" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int)))