| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Test.Main
Contents
Synopsis
- captureProcessResult :: IO () -> IO ProcessResult
- data ProcessResult = ProcessResult {
- prStdout :: !ByteString
- prStderr :: !ByteString
- prExitCode :: !ExitCode
- withStdin :: ByteString -> IO a -> IO a
- withArgs :: [String] -> IO a -> IO a
- data ExitCode = ExitSuccess
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 mainProcessResult {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 mainProcessResult {prStdout = "", prStderr = "OMG!", prExitCode = ExitFailure 1}
data ProcessResult #
Used for the result of captureProcessResult.
Constructors
| ProcessResult | |
Fields
| |
Instances
| Eq ProcessResult # | |
Defined in Test.Main.Internal Methods (==) :: ProcessResult -> ProcessResult -> Bool # (/=) :: ProcessResult -> ProcessResult -> Bool # | |
| Show ProcessResult # | |
Defined in Test.Main.Internal Methods showsPrec :: Int -> ProcessResult -> ShowS # show :: ProcessResult -> String # showList :: [ProcessResult] -> ShowS # | |
| Generic ProcessResult # | |
Defined in Test.Main.Internal Associated Types type Rep ProcessResult :: * -> * # | |
| type Rep ProcessResult # | |
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" mainedcba
Re-export from System.Environment
Re-export from System.Exit
Defines the exit codes that a program can return.
Constructors
| ExitSuccess | indicates successful termination; |
Instances
| Eq ExitCode | |
| Ord ExitCode | |
Defined in GHC.IO.Exception | |
| Read ExitCode | |
| Show ExitCode | |
| Generic ExitCode | |
| Exception ExitCode | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception Methods toException :: ExitCode -> SomeException # fromException :: SomeException -> Maybe ExitCode # displayException :: ExitCode -> String # | |
| type Rep ExitCode | |
Defined in GHC.IO.Exception | |