Skip to content

Commit

Permalink
Avoid potential multi-line progress lines
Browse files Browse the repository at this point in the history
Without these changes, I get mutliple dots from QuickCheck on the terminal with

  --quickcheck-tests=1000000

Either of them suffices for a fix, but they both make sense.
  • Loading branch information
UnkindPartition committed Sep 15, 2021
1 parent 2d02dec commit 50a9871
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion core/Test/Tasty/Ingredients/ConsoleReporter.hs
Expand Up @@ -142,7 +142,7 @@ buildTestOutput opts tree =

| otherwise = do
let
msg = case (progressText progress, 100 * progressPercent progress) of
msg = case (cleanupProgressText $ progressText progress, 100 * progressPercent progress) of
("", pct) -> printf "%.0f%%" pct
(txt, 0.0) -> printf "%s" txt
(txt, pct) -> printf "%s: %.0f%%" txt pct
Expand Down Expand Up @@ -196,6 +196,12 @@ buildTestOutput opts tree =
}
opts tree

-- | 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,
-- we simply drop anything after a newline.
cleanupProgressText :: String -> String
cleanupProgressText = takeWhile $ \c -> c /= '\n' && c /= '\r'

-- | Fold function for the 'TestOutput' tree into a 'Monoid'.
--
-- @since 0.12
Expand Down
4 changes: 3 additions & 1 deletion quickcheck/Test/Tasty/QuickCheck.hs
Expand Up @@ -232,8 +232,10 @@ quickCheck :: (Progress -> IO ())
-> QC.Property
-> IO QC.Result
quickCheck yieldProgress args prop = do
-- Here we rely on the fact that QuickCheck currently prints its progress to
-- stderr and the overall status (which we don't need) to stdout
tm <- QC.newTerminal
(\progressText -> yieldProgress emptyProgress { progressText })
(const $ pure ())
(\progressText -> yieldProgress emptyProgress { progressText })
QC.withState args $ \ s ->
QC.test s { QC.terminal = tm } prop
Expand Down

0 comments on commit 50a9871

Please sign in to comment.