@@ -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,28 @@ 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 (testActualFileStdout env) header
599
602
600
603
recordLog :: Result -> TestM ()
601
- recordLog res = do
604
+ recordLog Result {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
+ ++ " STDOUT\n " <> resultStdout ++ " \n "
611
+ ++ " STDERR\n " <> resultStderr ++ " \n "
612
+ ++ " \n " )
613
+ let report f txt
614
+ = liftIO
615
+ . C. appendFile f
616
+ . C. pack
617
+ . testRecordNormalizer env $ case mode of
618
+ RecordAll -> unlines (lines txt)
619
+ RecordMarked -> getMarkedOutput txt
612
620
DoNotRecord -> " "
621
+ report (testActualFileStdout env) resultStdout
622
+ report (testActualFileStderr env) resultStderr
613
623
614
624
getMarkedOutput :: String -> String -- trailing newline
615
625
getMarkedOutput out = unlines (go (lines out) False )
@@ -669,7 +679,7 @@ shouldNotExist path =
669
679
assertRegex :: MonadIO m => String -> String -> Result -> m ()
670
680
assertRegex msg regex r =
671
681
withFrozenCallStack $
672
- let out = resultOutput r
682
+ let out = resultStdout r
673
683
in assertBool (msg ++ " ,\n actual output:\n " ++ out)
674
684
(out =~ regex)
675
685
@@ -695,14 +705,14 @@ assertOutputContains needle result =
695
705
withFrozenCallStack $
696
706
unless (needle `isInfixOf` (concatOutput output)) $
697
707
assertFailure $ " expected: " ++ needle
698
- where output = resultOutput result
708
+ where output = resultStdout result
699
709
700
710
assertOutputDoesNotContain :: MonadIO m => WithCallStack (String -> Result -> m () )
701
711
assertOutputDoesNotContain needle result =
702
712
withFrozenCallStack $
703
713
when (needle `isInfixOf` (concatOutput output)) $
704
714
assertFailure $ " unexpected: " ++ needle
705
- where output = resultOutput result
715
+ where output = resultStdout result
706
716
707
717
assertFindInFile :: MonadIO m => WithCallStack (String -> FilePath -> m () )
708
718
assertFindInFile needle path =
@@ -897,7 +907,7 @@ withSourceCopy m = do
897
907
let cwd = testCurrentDir env
898
908
dest = testSourceCopyDir env
899
909
r <- git' " ls-files" [" --cached" , " --modified" ]
900
- forM_ (lines (resultOutput r)) $ \ f -> do
910
+ forM_ (lines (resultStdout r)) $ \ f -> do
901
911
unless (isTestFile f) $ do
902
912
liftIO $ createDirectoryIfMissing True (takeDirectory (dest </> f))
903
913
liftIO $ copyFile (cwd </> f) (dest </> f)
@@ -923,7 +933,7 @@ getIPID :: String -> TestM String
923
933
getIPID pn = do
924
934
r <- ghcPkg' " field" [" --global" , pn, " id" ]
925
935
-- Don't choke on warnings from ghc-pkg
926
- case mapMaybe (stripPrefix " id: " ) (lines (resultOutput r)) of
936
+ case mapMaybe (stripPrefix " id: " ) (lines (resultStdout r)) of
927
937
-- ~/.cabal/store may contain multiple versions of single package
928
938
-- we pick first one. It should work
929
939
(x: _) -> return (takeWhile (not . Char. isSpace) x)
0 commit comments