Skip to content

Commit

Permalink
Teach the HUnit Steps provider to log progress
Browse files Browse the repository at this point in the history
A cheap improvement to also show the steps as the tests are running.
This does mean that we need to bump the `tasty` lower bound to 1.5.
  • Loading branch information
michaelpj committed Sep 11, 2023
1 parent 0f6bbe5 commit e3eff61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion hunit/Test/Tasty/HUnit/Steps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ newtype TestCaseSteps = TestCaseSteps ((String -> IO ()) -> Assertion)
deriving Typeable

instance IsTest TestCaseSteps where
run _ (TestCaseSteps assertionFn) _ = do
run _ (TestCaseSteps assertionFn) yieldProgress = do
ref <- newIORef []

let
stepFn :: String -> IO ()
stepFn msg = do
tme <- getTime
-- The number of steps is not fixed, so we can't
-- provide the progress percentage.
-- We also don't provide the timings here, only
-- at the end.
yieldProgress (Progress msg 0)
atomicModifyIORef ref (\l -> ((tme,msg):l, ()))

hunitResult <- (Right <$> assertionFn stepFn) `catch`
Expand Down
2 changes: 1 addition & 1 deletion hunit/tasty-hunit.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ library
Test.Tasty.HUnit.Steps
other-extensions: TypeFamilies, DeriveDataTypeable
build-depends: base >= 4.8 && < 5,
tasty >= 1.2.2 && < 1.6,
tasty >= 1.5 && < 1.6,
call-stack < 0.5
-- hs-source-dirs:
default-language: Haskell2010
Expand Down

0 comments on commit e3eff61

Please sign in to comment.