-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Capture stdout/stderr/exit code, and replace stdin of your main function.
--   
--   See README.md for detail.
@package main-tester
@version 0.1.0.0

module Test.Main.Internal

-- | Used for the result of <a>captureProcessResult</a>.
data ProcessResult
ProcessResult :: !ByteString -> !ByteString -> !ExitCode -> ProcessResult
[prStdout] :: ProcessResult -> !ByteString
[prStderr] :: ProcessResult -> !ByteString
[prExitCode] :: ProcessResult -> !ExitCode

-- | Use to avoid errors in related to new line code in tests. Currently I
--   use this function only for this module's test.
normalizeNewLines :: ProcessResult -> ProcessResult
instance GHC.Generics.Generic Test.Main.Internal.ProcessResult
instance GHC.Show.Show Test.Main.Internal.ProcessResult
instance GHC.Classes.Eq Test.Main.Internal.ProcessResult

module Test.Main

-- | Capture stdout, stderr, and exit code of the given IO action.
--   
--   <pre>
--   &gt;&gt;&gt; let main = putStr "hello"
--   
--   &gt;&gt;&gt; captureProcessResult main
--   ProcessResult {prStdout = "hello", prStderr = "", prExitCode = ExitSuccess}
--   </pre>
--   
--   If the IO action exit with error message, the exit code of result is
--   <tt>ExitFailure</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; import System.IO
--   
--   &gt;&gt;&gt; import System.Exit
--   
--   &gt;&gt;&gt; let main = hPutStr stderr "OMG!" &gt;&gt; exitWith (ExitFailure 1)
--   
--   &gt;&gt;&gt; captureProcessResult main
--   ProcessResult {prStdout = "", prStderr = "OMG!", prExitCode = ExitFailure 1}
--   </pre>
captureProcessResult :: IO () -> IO ProcessResult

-- | Used for the result of <a>captureProcessResult</a>.
data ProcessResult
ProcessResult :: !ByteString -> !ByteString -> !ExitCode -> ProcessResult
[prStdout] :: ProcessResult -> !ByteString
[prStderr] :: ProcessResult -> !ByteString
[prExitCode] :: ProcessResult -> !ExitCode

-- | Pass the ByteString to stdin of the given IO action.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.ByteString.Char8 ()
--   
--   &gt;&gt;&gt; :set -XOverloadedStrings
--   
--   &gt;&gt;&gt; let main = putStrLn . reverse =&lt;&lt; getLine
--   
--   &gt;&gt;&gt; withStdin "abcde" main
--   edcba
--   </pre>
withStdin :: ByteString -> IO a -> IO a

-- | <a>withArgs</a> <tt>args act</tt> - while executing action
--   <tt>act</tt>, have <a>getArgs</a> return <tt>args</tt>.
withArgs :: () => [String] -> IO a -> IO a

-- | Defines the exit codes that a program can return.
data ExitCode

-- | indicates successful termination;
ExitSuccess :: ExitCode
