@@ -563,14 +563,17 @@ withRepo repo_dir m = do
563
563
requireSuccess :: Result -> TestM Result
564
564
requireSuccess r@ Result { resultCommand = cmd
565
565
, resultExitCode = exitCode
566
- , resultOutput = output } = withFrozenCallStack $ do
566
+ , resultStdout
567
+ , resultStderr } = withFrozenCallStack $ do
567
568
env <- getTestEnv
568
569
when (exitCode /= ExitSuccess && not (testShouldFail env)) $
569
570
assertFailure $ " Command " ++ cmd ++ " failed.\n " ++
570
- " Output:\n " ++ output ++ " \n "
571
+ " Stdout:\n " ++ resultStdout ++ " \n " ++
572
+ " Stderr:\n " ++ resultStderr ++ " \n "
571
573
when (exitCode == ExitSuccess && testShouldFail env) $
572
574
assertFailure $ " Command " ++ cmd ++ " succeeded.\n " ++
573
- " Output:\n " ++ output ++ " \n "
575
+ " Stdout:\n " ++ resultStdout ++ " \n " ++
576
+ " Stderr:\n " ++ resultStderr ++ " \n "
574
577
return r
575
578
576
579
initWorkDir :: TestM ()
@@ -595,21 +598,30 @@ recordHeader args = do
595
598
initWorkDir
596
599
liftIO $ putStr str_header
597
600
liftIO $ C. appendFile (testWorkDir env </> " test.log" ) header
598
- liftIO $ C. appendFile (testActualFile env) header
601
+ liftIO $ C. appendFile (testActualFile Out env) header
599
602
600
603
recordLog :: Result -> TestM ()
601
- recordLog res = do
604
+ recordLog Result {resultOut, resultStdout, resultStderr, resultCommand} = do
602
605
env <- getTestEnv
603
606
let mode = testRecordMode env
604
607
initWorkDir
605
608
liftIO $ C. appendFile (testWorkDir env </> " test.log" )
606
- (C. pack $ " + " ++ resultCommand res ++ " \n "
607
- ++ resultOutput res ++ " \n\n " )
608
- liftIO . C. appendFile (testActualFile env) . C. pack . testRecordNormalizer env $
609
- case mode of
610
- RecordAll -> unlines (lines (resultOutput res))
611
- RecordMarked -> getMarkedOutput (resultOutput res)
609
+ (C. pack $ " + " ++ resultCommand ++ " \n "
610
+ ++ " OUT\n " <> resultOut ++ " \n "
611
+ ++ " STDOUT\n " <> resultStdout ++ " \n "
612
+ ++ " STDERR\n " <> resultStderr ++ " \n "
613
+ ++ " \n " )
614
+ let report f txt
615
+ = liftIO
616
+ . C. appendFile f
617
+ . C. pack
618
+ . testRecordNormalizer env $ case mode of
619
+ RecordAll -> unlines (lines txt)
620
+ RecordMarked -> getMarkedOutput txt
612
621
DoNotRecord -> " "
622
+ report (testActualFile Out env) resultOut
623
+ report (testActualFile Stdout env) resultStdout
624
+ report (testActualFile Stderr env) resultStderr
613
625
614
626
getMarkedOutput :: String -> String -- trailing newline
615
627
getMarkedOutput out = unlines (go (lines out) False )
@@ -669,7 +681,7 @@ shouldNotExist path =
669
681
assertRegex :: MonadIO m => String -> String -> Result -> m ()
670
682
assertRegex msg regex r =
671
683
withFrozenCallStack $
672
- let out = resultOutput r
684
+ let out = resultStdout r
673
685
in assertBool (msg ++ " ,\n actual output:\n " ++ out)
674
686
(out =~ regex)
675
687
@@ -695,14 +707,14 @@ assertOutputContains needle result =
695
707
withFrozenCallStack $
696
708
unless (needle `isInfixOf` (concatOutput output)) $
697
709
assertFailure $ " expected: " ++ needle
698
- where output = resultOutput result
710
+ where output = resultStdout result
699
711
700
712
assertOutputDoesNotContain :: MonadIO m => WithCallStack (String -> Result -> m () )
701
713
assertOutputDoesNotContain needle result =
702
714
withFrozenCallStack $
703
715
when (needle `isInfixOf` (concatOutput output)) $
704
716
assertFailure $ " unexpected: " ++ needle
705
- where output = resultOutput result
717
+ where output = resultStdout result
706
718
707
719
assertFindInFile :: MonadIO m => WithCallStack (String -> FilePath -> m () )
708
720
assertFindInFile needle path =
@@ -897,7 +909,7 @@ withSourceCopy m = do
897
909
let cwd = testCurrentDir env
898
910
dest = testSourceCopyDir env
899
911
r <- git' " ls-files" [" --cached" , " --modified" ]
900
- forM_ (lines (resultOutput r)) $ \ f -> do
912
+ forM_ (lines (resultStdout r)) $ \ f -> do
901
913
unless (isTestFile f) $ do
902
914
liftIO $ createDirectoryIfMissing True (takeDirectory (dest </> f))
903
915
liftIO $ copyFile (cwd </> f) (dest </> f)
@@ -923,7 +935,7 @@ getIPID :: String -> TestM String
923
935
getIPID pn = do
924
936
r <- ghcPkg' " field" [" --global" , pn, " id" ]
925
937
-- Don't choke on warnings from ghc-pkg
926
- case mapMaybe (stripPrefix " id: " ) (lines (resultOutput r)) of
938
+ case mapMaybe (stripPrefix " id: " ) (lines (resultStdout r)) of
927
939
-- ~/.cabal/store may contain multiple versions of single package
928
940
-- we pick first one. It should work
929
941
(x: _) -> return (takeWhile (not . Char. isSpace) x)
0 commit comments