hspec-core 2.10.3 → 2.10.4
raw patch · 4 files changed
+38/−8 lines, 4 files
Files
- hspec-core.cabal +1/−1
- src/Test/Hspec/Core/Formatters/Internal.hs +6/−5
- test/Test/Hspec/Core/Formatters/InternalSpec.hs +30/−1
- version.yaml +1/−1
hspec-core.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: hspec-core-version: 2.10.3+version: 2.10.4 license: MIT license-file: LICENSE copyright: (c) 2011-2022 Simon Hengel,
src/Test/Hspec/Core/Formatters/Internal.hs view
@@ -243,13 +243,14 @@ writeChunk :: String -> FormatM () writeChunk str = do h <- getHandle+ let+ plainOutput = IO.hPutStr h str+ colorOutput color = bracket_ (hSetSGR h [color]) (hSetSGR h [Reset]) plainOutput mColor <- gets stateColor liftIO $ case mColor of- Just color | not (all isSpace str) -> bracket_- (hSetSGR h [color])- (hSetSGR h [Reset])- (IO.hPutStr h str)- _ -> IO.hPutStr h str+ Just (SetColor Foreground _ _) | all isSpace str -> plainOutput+ Just color -> colorOutput color+ Nothing -> plainOutput -- | Set output color to red, run given action, and finally restore the default -- color.
test/Test/Hspec/Core/Formatters/InternalSpec.hs view
@@ -13,7 +13,7 @@ formatConfigUseColor = True , formatConfigReportProgress = False , formatConfigOutputUnicode = False-, formatConfigUseDiff = False+, formatConfigUseDiff = True , formatConfigPrettyPrint = False , formatConfigPrettyPrintFunction = Nothing , formatConfigPrintTimes = False@@ -28,8 +28,37 @@ spec :: Spec spec = do+ forM_ [+ ("extraChunk", extraChunk, Red)+ , ("missingChunk", missingChunk, Green)+ ] $ \ (name, chunk, color) -> do++ let colorize layer text = setSGRCode [SetColor layer Dull color] <> text <> setSGRCode [Reset]++ describe name $ do+ it "colorizes chunks" $ do+ capture_ $ runFormatM formatConfig $ do+ chunk "foo"+ `shouldReturn` colorize Foreground "foo"++ context "with an all-spaces chunk" $ do+ it "colorizes background" $ do+ capture_ $ runFormatM formatConfig $ do+ chunk " "+ `shouldReturn` colorize Background " "++ context "with an all-newlines chunk" $ do+ it "colorizes background" $ do+ capture_ $ runFormatM formatConfig $ do+ chunk "\n\n\n"+ `shouldReturn` colorize Background "\n\n\n"+ describe "write" $ do it "does not span colored output over multiple lines" $ do++ -- This helps with output on Jenkins and Buildkite:+ -- https://github.com/hspec/hspec/issues/346+ capture_ $ runFormatM formatConfig $ do withSuccessColor $ write "foo\nbar\nbaz\n" `shouldReturn` unlines [green "foo", green "bar", green "baz"]
version.yaml view
@@ -1,1 +1,1 @@-&version 2.10.3+&version 2.10.4