{-# LANGUAGE DeriveDataTypeable #-}
{-
Demonstrate a stdout/stderr handling bug.

stdout working normally:
 
$ runhaskell test.hs | cat
output
$
 
after uncommenting either commented line below, stdout can't be captured:
 
$ runhaskell test.hs | cat
$ 
 
-}

import System.Console.CmdArgs hiding (args)
import qualified System.Console.CmdArgs as CmdArgs (args)
import Test.Framework (defaultMainWithArgs)

data Args = Args {
     debug      :: Bool
    ,implicit   :: String
    ,executable :: String
    ,testfiles  :: [String]
    ,otheropts  :: [String]
    } deriving (Show, Data, Typeable)

argsmode :: Mode Args
argsmode = mode $ Args{
            debug      = def &= explicit & flag "debug" & text "debug verbosity"
           ,implicit   = "exit" &= typ "none|exit|all" & empty "none" & text "provide implicit tests"
           ,executable = def &= argPos 0 & typ "EXECUTABLE" & text "executable under test"
           ,testfiles  = def &= CmdArgs.args & typ "TESTFILES" & text "test files"
           ,otheropts  = def &= unknownFlags & explicit & typ "FLAGS" & text "other flags are passed to test runner"
           }

main :: IO ()
main = do
  -- args <- cmdArgs "" [argsmode]
  putStrLn "output"
  -- defaultMainWithArgs [] []
