Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add line wrap disablement to ConsoleReporter #433

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions core/Test/Tasty/Ingredients/ConsoleReporter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ buildTestOutput opts tree =
!alignment = computeAlignment opts tree

MinDurationToReport{minDurationMicros} = lookupOption opts
AnsiTricks{getAnsiTricks} = lookupOption opts

runSingleTest
:: (IsTest t, ?colors :: Bool)
Expand All @@ -153,7 +152,7 @@ buildTestOutput opts tree =
(replicate postNamePadding ' ')

printTestName = do
putStr testNamePadded
withoutLineWrap $ putStr testNamePadded
hFlush stdout

printTestProgress progress
Expand All @@ -173,8 +172,9 @@ buildTestOutput opts tree =
-- A new progress message may be shorter than the previous one
-- so we must clean whole line and print anew.
clearLine
putStr testNamePadded
infoOk msg
withoutLineWrap $ do
putStr testNamePadded
infoOk msg
hFlush stdout

printTestResult result = do
Expand All @@ -189,10 +189,11 @@ buildTestOutput opts tree =
_ -> fail
time = resultTime result

when getAnsiTricks $ do
putChar '\r'
clearLine
putStr testNamePadded
withoutLineWrap $ do
when getAnsiTricks $ do
putChar '\r'
clearLine
putStr testNamePadded

printFn (resultShortDescription result)
when (floor (time * 1e6) >= minDurationMicros) $
Expand All @@ -211,7 +212,7 @@ buildTestOutput opts tree =
runGroup _opts name grp = Ap $ do
level <- ask
let
printHeading = printf "%s%s\n" (indent level) name
printHeading = withoutLineWrap $ printf "%s%s\n" (indent level) name
printBody = runReader (getApp (mconcat grp)) (level + 1)
return $ PrintHeading name printHeading printBody

Expand All @@ -223,6 +224,18 @@ buildTestOutput opts tree =
, foldGroup = runGroup
}
opts tree
where
AnsiTricks{getAnsiTricks} = lookupOption opts
-- We must ensure these lines don't wrap, otherwise the wrong
-- line will be cleared later or the test tree printing will
-- itself wrap.
withoutLineWrap :: IO () -> IO ()
#if MIN_VERSION_ansi_terminal(1,1,2)
withoutLineWrap m | getAnsiTricks =
bracket_ disableLineWrap enableLineWrap m
#endif
withoutLineWrap m = m


-- | Make sure the progress text does not contain any newlines or line feeds,
-- lest our ANSI magic breaks. Since the progress text is expected to be short,
Expand Down
Loading