hspec-core 2.8.0 → 2.8.1
raw patch · 6 files changed
+78/−31 lines, 6 files
Files
- hspec-core.cabal +1/−1
- src/Test/Hspec/Core/Compat.hs +32/−21
- src/Test/Hspec/Core/FailureReport.hs +1/−1
- src/Test/Hspec/Core/Runner.hs +22/−7
- test/Test/Hspec/Core/RunnerSpec.hs +21/−0
- version.yaml +1/−1
hspec-core.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: hspec-core-version: 2.8.0+version: 2.8.1 license: MIT license-file: LICENSE copyright: (c) 2011-2021 Simon Hengel,
src/Test/Hspec/Core/Compat.hs view
@@ -1,20 +1,7 @@ {-# LANGUAGE CPP #-} module Test.Hspec.Core.Compat (- getDefaultConcurrentJobs-, showType-, showFullType-, readMaybe-, lookupEnv-, module Imports--#if !MIN_VERSION_base(4,6,0)-, modifyIORef'-, atomicWriteIORef-#endif-, interruptible--, guarded-, sortOn+ module Imports+, module Test.Hspec.Core.Compat ) where import Control.Applicative as Imports@@ -28,12 +15,25 @@ , sequence_ ) import Data.Foldable as Imports++#if MIN_VERSION_base(4,11,0)+import Data.Functor as Imports+#endif+ import Data.Traversable as Imports import Data.Monoid as Imports-import Data.List as Imports (stripPrefix, isPrefixOf, isInfixOf, intercalate, inits, tails, sortBy)+import Data.List as Imports (+ stripPrefix+ , isPrefixOf+ , isInfixOf+ , intercalate+ , inits+ , tails+ , sortBy #if MIN_VERSION_base(4,8,0)-import Data.List (sortOn)+ , sortOn #endif+ ) import Prelude as Imports hiding ( all@@ -62,9 +62,16 @@ ) import Data.Typeable (Typeable, typeOf, typeRepTyCon)-import Text.Read import Data.IORef as Imports++#if MIN_VERSION_base(4,6,0)+import Text.Read as Imports (readMaybe)+import System.Environment as Imports (lookupEnv)+#else+import Text.Read import System.Environment+import qualified Text.ParserCombinators.ReadP as P+#endif #if !MIN_VERSION_base(4,8,0) import Data.Ord (comparing)@@ -74,14 +81,12 @@ import Control.Concurrent #if MIN_VERSION_base(4,9,0)-import Control.Exception (interruptible)+import Control.Exception as Imports (interruptible) #else import GHC.IO #endif #if !MIN_VERSION_base(4,6,0)-import qualified Text.ParserCombinators.ReadP as P- -- |Strict version of 'modifyIORef' modifyIORef' :: IORef a -> (a -> a) -> IO () modifyIORef' ref f = do@@ -152,4 +157,10 @@ sortOn :: Ord b => (a -> b) -> [a] -> [a] sortOn f = map snd . sortBy (comparing fst) . map (\x -> let y = f x in y `seq` (y, x))+#endif++#if !MIN_VERSION_base(4,11,0)+infixl 1 <&>+(<&>) :: Functor f => f a -> (a -> b) -> f b+(<&>) = flip (<$>) #endif
src/Test/Hspec/Core/FailureReport.hs view
@@ -9,7 +9,7 @@ import Test.Hspec.Core.Compat #ifndef __GHCJS__-import System.SetEnv+import System.SetEnv (setEnv) import Test.Hspec.Core.Util (safeTry) #endif import System.IO
src/Test/Hspec/Core/Runner.hs view
@@ -30,6 +30,7 @@ #ifdef TEST , rerunAll , specToEvalForest+, colorOutputSupported #endif ) where @@ -210,7 +211,7 @@ Nothing -> getDefaultConcurrentJobs Just n -> return n - useColor <- doesUseColor stdout config+ useColor <- colorOutputSupported (configColorMode config) (hIsTerminalDevice stdout) results <- withHiddenCursor useColor stdout $ do let@@ -283,12 +284,29 @@ | useColor = E.bracket_ (hHideCursor h) (hShowCursor h) | otherwise = id -doesUseColor :: Handle -> Config -> IO Bool-doesUseColor h c = case configColorMode c of- ColorAuto -> (&&) <$> hIsTerminalDevice h <*> (not <$> isDumb)+colorOutputSupported :: ColorMode -> IO Bool -> IO Bool+colorOutputSupported mode isTerminalDevice = case mode of+ ColorAuto -> (not <$> noColor ||^ isDumb) &&^ isTerminalDevice ColorNever -> return False ColorAlways -> return True +noColor :: IO Bool+noColor = lookupEnv "NO_COLOR" <&> (/= Nothing)++isDumb :: IO Bool+isDumb = lookupEnv "TERM" <&> (== Just "dumb")++(||^) :: IO Bool -> IO Bool -> IO Bool+(||^) a b = ifM a (pure True) b++(&&^) :: IO Bool -> IO Bool -> IO Bool+(&&^) a b = ifM a b (pure False)++ifM :: IO Bool -> IO a -> IO a -> IO a+ifM action true false = do+ bool <- action+ if bool then true else false+ rerunAll :: Config -> Maybe FailureReport -> Summary -> Bool rerunAll _ Nothing _ = False rerunAll config (Just oldFailureReport) summary =@@ -296,9 +314,6 @@ && configRerun config && isSuccess summary && (not . null) (failureReportPaths oldFailureReport)--isDumb :: IO Bool-isDumb = maybe False (== "dumb") <$> lookupEnv "TERM" -- | Summary of a test run. data Summary = Summary {
test/Test/Hspec/Core/RunnerSpec.hs view
@@ -575,6 +575,27 @@ high <- readIORef highRef high `shouldBe` j + describe "colorOutputSupported" $ do+ it "returns False" $ do+ withEnvironment [] $ do+ H.colorOutputSupported H.ColorAuto (return False) `shouldReturn` False++ context "with a terminal device" $ do+ let isTerminalDevice = return True+ it "returns True" $ do+ withEnvironment [] $ do+ H.colorOutputSupported H.ColorAuto isTerminalDevice `shouldReturn` True++ context "when TERM=dumb" $ do+ it "returns False" $ do+ withEnvironment [("TERM", "dumb")] $ do+ H.colorOutputSupported H.ColorAuto isTerminalDevice `shouldReturn` False++ context "when NO_COLOR is set" $ do+ it "returns False" $ do+ withEnvironment [("NO_COLOR", "yes")] $ do+ H.colorOutputSupported H.ColorAuto isTerminalDevice `shouldReturn` False+ describe "rerunAll" $ do let report = FailureReport 0 0 0 0 [([], "foo")]
version.yaml view
@@ -1,1 +1,1 @@-&version 2.8.0+&version 2.8.1