Skip to content

Commit

Permalink
Improve --hide-successes to not print headings for empty test subtree…
Browse files Browse the repository at this point in the history
…s (i.e. when -p filtered tests out)
  • Loading branch information
sergv committed Dec 6, 2023
1 parent 1147251 commit 4c4d899
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions core/Test/Tasty/Ingredients/ConsoleReporter.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- vim:fdm=marker
{-# LANGUAGE BangPatterns, ImplicitParams, MultiParamTypeClasses, DeriveDataTypeable, FlexibleContexts, CApiFFI, NamedFieldPuns #-}
{-# LANGUAGE BangPatterns, ImplicitParams, MultiParamTypeClasses, DeriveDataTypeable, FlexibleContexts, CApiFFI, NamedFieldPuns, TupleSections #-}
-- | Console reporter ingredient.
--
-- @since 0.11.3
Expand Down Expand Up @@ -303,22 +303,28 @@ consoleOutput toutput smap =

consoleOutputHidingSuccesses :: (?colors :: Bool) => TestOutput -> StatusMap -> IO ()
consoleOutputHidingSuccesses toutput smap =
void . getApp $ foldTestOutput foldTest foldHeading toutput smap
void . getApp $ fst $ foldTestOutput foldTest foldHeading toutput smap
where
foldTest :: p -> IO () -> IO Result -> (Result -> IO ()) -> (Ap IO Any, Any)
foldTest _name printName getResult printResult =
Ap $ do
(, Any True) $ Ap $ do
printName :: IO ()
r <- getResult
if resultSuccessful r
then do clearThisLine; return $ Any False
else do printResult r :: IO (); return $ Any True

foldHeading _name printHeading printBody =
Ap $ do
printHeading :: IO ()
Any failed <- getApp printBody
unless failed clearAboveLine
return $ Any failed
foldHeading :: p -> IO () -> (Ap IO Any, Any) -> (Ap IO Any, Any)
foldHeading _name printHeading (printBody, Any nonEmpty) =
(, Any nonEmpty) $ Ap $
if nonEmpty
then do
printHeading :: IO ()
Any failed <- getApp printBody
unless failed clearAboveLine
return $ Any failed
else
return mempty

clearAboveLine = do cursorUpLine 1; clearThisLine
clearThisLine = do clearLine; setCursorColumn 0
Expand Down

0 comments on commit 4c4d899

Please sign in to comment.