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 multiple 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 authored and Bodigrim committed Jul 29, 2023
1 parent 8dc9412 commit 3f5bcb9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion core/Test/Tasty/Ingredients/ConsoleReporter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,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 @@ -206,6 +206,13 @@ 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 = map (\c -> if isSpace c then ' ' else c)
. takeWhile (\c -> c /= '\n' && c /= '\r' && c /= '\t')

-- | Fold function for the 'TestOutput' tree into a 'Monoid'.
--
-- @since 0.12
Expand Down
2 changes: 2 additions & 0 deletions quickcheck/Test/Tasty/QuickCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ 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
(const $ pure ())
(\progressText -> yieldProgress emptyProgress { progressText = parseProgress progressText })
Expand Down
2 changes: 1 addition & 1 deletion quickcheck/tasty-quickcheck.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test-suite test
test.hs
build-depends:
base >= 4.7 && < 5
, tasty
, tasty >= 1.5
, tasty-quickcheck
, tasty-hunit
, pcre-light
Expand Down

0 comments on commit 3f5bcb9

Please sign in to comment.