Skip to content

Commit

Permalink
Remove "Ok, modules loaded: .." message
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Oct 16, 2024
1 parent 91280f4 commit d74d468
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 46 deletions.
20 changes: 18 additions & 2 deletions src/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Session (
, Session(..)
, echo
, withSession

, ReloadingSucceeded(..)
, reload

, Summary(..)
Expand Down Expand Up @@ -54,8 +56,22 @@ withSession config args action = do
where
(ghciArgs, hspecArgs) = splitArgs args

reload :: MonadIO m => Session -> m String
reload session = liftIO $ evalVerbose session.interpreter ":reload"
data ReloadingSucceeded = ReloadingSucceeded | ReloadingFailed
deriving (Eq, Show)

reload :: MonadIO m => Session -> m (ReloadingSucceeded, String)
reload session = liftIO $ foo <$> evalVerbose session.interpreter ":reload"


foo :: String -> (ReloadingSucceeded, String)
foo (lines -> input) = (bar, unlines $ discardReloadMessage input)
where
bar = if any isOk input then ReloadingSucceeded else ReloadingFailed

isOk = isPrefixOf "Ok, modules loaded: "
isFailed = isPrefixOf "Failed, modules loaded: "

discardReloadMessage = filter (not . isOk) . filter (not . isFailed)

data Summary = Summary {
summaryExamples :: Int
Expand Down
14 changes: 4 additions & 10 deletions src/Trigger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ triggerAll session hooks = do
resetSummary session
trigger session hooks

reloadedSuccessfully :: String -> Bool
reloadedSuccessfully = any success . lines
where
success :: String -> Bool
success = isPrefixOf "Ok, modules loaded: "

removeProgress :: String -> String
removeProgress xs = case break (== '\r') xs of
(_, "") -> xs
Expand All @@ -71,13 +65,13 @@ trigger session hooks = runWriterT (runExceptT go) >>= \ case
go :: Trigger ()
go = do
runHook hooks.beforeReload
output <- Session.reload session
(s, output) <- Session.reload session
tell output
case reloadedSuccessfully output of
False -> do
case s of
Session.ReloadingFailed -> do
echo $ withColor Red "RELOADING FAILED" <> "\n"
abort
True -> do
Session.ReloadingSucceeded -> do
echo $ withColor Green "RELOADING SUCCEEDED" <> "\n"

runHook hooks.afterReload
Expand Down
2 changes: 1 addition & 1 deletion test/Helper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ failingSpec = unlines [
data Status = Ok | Failed
deriving (Eq, Show)

modulesLoaded :: Status -> [String] -> String
modulesLoaded :: Status -> [String] -> String -- FIXME: remove
modulesLoaded status xs = show status ++ ", modules loaded: " <> mods <> "."
where
mods = case xs of
Expand Down
4 changes: 2 additions & 2 deletions test/SessionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ spec = do

describe "reload" $ do
it "reloads" $ do
withSession [] $ \session -> do
Session.reload session `shouldReturn` (modulesLoaded Ok [] ++ "\n")
withSession [] $ \ session -> do
Session.reload session `shouldReturn` (ReloadingSucceeded, "")

describe "hasSpec" $ around withSomeSpec $ do
context "when module contains spec" $ do
Expand Down
59 changes: 28 additions & 31 deletions test/TriggerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ withSession specPath args = do
: "-fdiagnostics-color=never"
: file
: args
++ ["--no-color", "--seed=0"]
++ ["--expert", "--no-color", "--seed=0"]
where
(dir, file) = splitFileName specPath

Expand Down Expand Up @@ -93,8 +93,7 @@ spec = do
withSession name [] $ \ session -> do
writeFile name failingSpec
(trigger session >> triggerAll session) `shouldReturn` (Failure, [
modulesLoaded Ok ["Spec"]
, withColor Green "RELOADING SUCCEEDED"
withColor Green "RELOADING SUCCEEDED"
, ""
, "foo [✔]"
, "bar [✘]"
Expand All @@ -104,12 +103,6 @@ spec = do
, " Spec.hs:8:3: "
, " 1) bar"
, ""
#if MIN_VERSION_hspec(2,11,7)
, " To rerun use: --match \"/bar/\" --seed 0"
#else
, " To rerun use: --match \"/bar/\""
#endif
, ""
, "Randomized with seed 0"
, ""
, "Finished in ..."
Expand All @@ -121,8 +114,7 @@ spec = do
it "reloads and runs specs" $ \ name -> do
withSession name [] $ \ session -> do
trigger session `shouldReturn` (Success, [
modulesLoaded Ok ["Spec"]
, withColor Green "RELOADING SUCCEEDED"
withColor Green "RELOADING SUCCEEDED"
, ""
, "foo [✔]"
, "bar [✔]"
Expand All @@ -137,8 +129,7 @@ spec = do
withHooks $ \ hooks -> do
withSession name [] $ \ session -> do
triggerWithHooks session hooks `shouldReturn` (Success, [
modulesLoaded Ok ["Spec"]
, withColor Green "RELOADING SUCCEEDED"
withColor Green "RELOADING SUCCEEDED"
, ""
, "foo [✔]"
, "bar [✔]"
Expand All @@ -163,8 +154,7 @@ spec = do
withHooks $ \ hooks -> do
withSession name [] $ \ session -> do
triggerWithHooks session hooks { afterReload = failingHook } `shouldReturn` (HookFailed, [
modulesLoaded Ok ["Spec"]
, withColor Green "RELOADING SUCCEEDED"
withColor Green "RELOADING SUCCEEDED"
, "hook failed"
])
`shouldReturn` [BeforeReloadSucceeded]
Expand All @@ -186,7 +176,6 @@ spec = do
#if __GLASGOW_HASKELL__ >= 910
, ""
#endif
, modulesLoaded Failed []
, withColor Red "RELOADING FAILED"
])

Expand All @@ -195,15 +184,32 @@ spec = do
withSession name [] $ \ session -> do
writeFile name failingSpec
(Failure, xs) <- trigger session
xs `shouldContain` [modulesLoaded Ok ["Spec"]]
xs `shouldContain` ["2 examples, 1 failure"]
xs `shouldBe` [
"[1 of 1] Compiling Spec [Source file changed]"
, withColor Green "RELOADING SUCCEEDED"
, ""
, "foo [✔]"
, "bar [✘]"
, ""
, "Failures:"
, ""
, " Spec.hs:8:3: "
, " 1) bar"
, ""
, "Randomized with seed 0"
, ""
, "Finished in ..."
, "2 examples, 1 failure"
, "Summary {summaryExamples = 2, summaryFailures = 1}"
]
-- xs `shouldContain` [modulesLoaded Ok ["Spec"]]
-- xs `shouldContain` ["2 examples, 1 failure"]

it "only reruns failing specs" $ \ name -> do
withSession name [] $ \ session -> do
writeFile name failingSpec
(trigger session >> trigger session) `shouldReturn` (Failure, [
modulesLoaded Ok ["Spec"]
, withColor Green "RELOADING SUCCEEDED"
withColor Green "RELOADING SUCCEEDED"
, ""
, "bar [✘]"
, ""
Expand All @@ -212,12 +218,6 @@ spec = do
, " Spec.hs:8:3: "
, " 1) bar"
, ""
#if MIN_VERSION_hspec(2,11,7)
, " To rerun use: --match \"/bar/\" --seed 0"
#else
, " To rerun use: --match \"/bar/\""
#endif
, ""
, "Randomized with seed 0"
, ""
, "Finished in ..."
Expand All @@ -233,7 +233,6 @@ spec = do
writeFile name passingSpec
trigger session `shouldReturn` (Success, [
"[1 of 1] Compiling Spec [Source file changed]"
, modulesLoaded Ok ["Spec"]
, withColor Green "RELOADING SUCCEEDED"
, ""
, "bar [✔]"
Expand All @@ -255,17 +254,15 @@ spec = do
withSession name [] $ \ session -> do
writeFile name "module Spec where"
(trigger session >> trigger session) `shouldReturn` (Success, [
modulesLoaded Ok ["Spec"]
, withColor Green "RELOADING SUCCEEDED"
withColor Green "RELOADING SUCCEEDED"
])

context "with an hspec-meta spec" $ do
it "reloads and runs spec" $ \ name -> do
requiresHspecMeta $ withSession name ["-package hspec-meta"] $ \ session -> do
writeFile name passingMetaSpec
(trigger session >> trigger session) `shouldReturn` (Success, [
modulesLoaded Ok ["Spec"]
, withColor Green "RELOADING SUCCEEDED"
withColor Green "RELOADING SUCCEEDED"
, ""
, "foo [✔]"
, "bar [✔]"
Expand Down

0 comments on commit d74d468

Please sign in to comment.