Skip to content

Commit

Permalink
Add line wrap disablement to ConsoleReporter
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundnoble committed Nov 15, 2024
1 parent 7efa34a commit bec56cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 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 @@ -192,7 +192,8 @@ buildTestOutput opts tree =
when getAnsiTricks $ do
putChar '\r'
clearLine
putStr testNamePadded
withoutLineWrap $
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,15 @@ 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 ()
withoutLineWrap m =
bracket disableLineWrap (\_ -> enableLineWrap) (\_ -> 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
2 changes: 1 addition & 1 deletion core/tasty.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ library
transformers >= 0.5 && < 0.7,
tagged >= 0.5 && < 0.9,
optparse-applicative >= 0.14 && < 0.19,
ansi-terminal >= 0.9 && < 1.2
ansi-terminal >= 1.1.2 && < 1.2

-- No reason to depend on unbounded-delays on 64-bit architecture
if(!arch(x86_64) && !arch(aarch64) && !arch(ppc64) && !arch(s390x) && !arch(riscv64))
Expand Down

0 comments on commit bec56cf

Please sign in to comment.