{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveGeneric #-}
#if defined(mingw32_HOST_OS)
{-# LANGUAGE RecordWildCards #-}
#endif

module Test.Main.Internal where


import qualified Data.ByteString.Char8 as B
import           GHC.Generics (Generic)
import           System.Exit (ExitCode)



-- | Used for the result of 'Test.Main.captureProcessResult'.
data ProcessResult =
  ProcessResult
    { prStdout :: !B.ByteString
    , prStderr :: !B.ByteString
    , prExitCode :: !ExitCode
    } deriving (Eq, Show, Generic)


-- | 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
#if defined(mingw32_HOST_OS)
normalizeNewLines ProcessResult {..} =
  ProcessResult (nl prStdout) (nl prStderr) (prExitCode)
  where
    nl = B.concat . B.split '\r'
#else
normalizeNewLines = id
#endif