hspec-core 2.10.1 → 2.10.2
raw patch · 8 files changed
+88/−13 lines, 8 filesdep +timedep −clock
Dependencies added: time
Dependencies removed: clock
Files
- help.txt +2/−0
- hspec-core.cabal +3/−3
- src/Test/Hspec/Core/Clock.hs +13/−3
- src/Test/Hspec/Core/Config/Definition.hs +14/−0
- src/Test/Hspec/Core/Runner.hs +23/−6
- test/Test/Hspec/Core/Config/OptionsSpec.hs +1/−0
- test/Test/Hspec/Core/RunnerSpec.hs +31/−0
- version.yaml +1/−1
help.txt view
@@ -12,6 +12,8 @@ --[no-]focused-only do not run anything, unless there are focused spec items --[no-]fail-on-focused fail on focused spec items+ --[no-]fail-on-pending fail on pending spec items+ --[no-]strict enable --fail-on-focused and --fail-on-pending --[no-]fail-fast abort on first failure --[no-]randomize randomize execution order -r --rerun rerun all examples that failed in the previous
hspec-core.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: hspec-core-version: 2.10.1+version: 2.10.2 license: MIT license-file: LICENSE copyright: (c) 2011-2022 Simon Hengel,@@ -40,7 +40,6 @@ , array , base >=4.5.0.0 && <5 , call-stack >=0.2.0- , clock >=0.7.1 , deepseq , directory , filepath@@ -49,6 +48,7 @@ , random , setenv , tf-random+ , time , transformers >=0.2.2.0 exposed-modules: Test.Hspec.Core.Spec@@ -125,7 +125,6 @@ , base >=4.5.0.0 && <5 , base-orphans , call-stack >=0.2.0- , clock >=0.7.1 , deepseq , directory , filepath@@ -138,6 +137,7 @@ , silently >=1.2.4 , temporary , tf-random+ , time , transformers >=0.2.2.0 build-tool-depends: hspec-meta:hspec-meta-discover
src/Test/Hspec/Core/Clock.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE CPP #-} module Test.Hspec.Core.Clock ( Seconds(..) , toMilliseconds@@ -13,10 +14,15 @@ import Test.Hspec.Core.Compat import Text.Printf-import System.Clock import Control.Concurrent import qualified System.Timeout as System +#if MIN_VERSION_base(4,11,0)+import qualified GHC.Clock as GHC+#else+import Data.Time.Clock.POSIX+#endif+ newtype Seconds = Seconds Double deriving (Eq, Show, Ord, Num, Fractional, PrintfArg) @@ -27,9 +33,13 @@ toMicroseconds (Seconds s) = floor (s * 1000000) getMonotonicTime :: IO Seconds+#if MIN_VERSION_base(4,11,0)+getMonotonicTime = Seconds <$> GHC.getMonotonicTime+#else getMonotonicTime = do- t <- getTime Monotonic- return $ Seconds ((fromIntegral . toNanoSecs $ t) / 1000000000)+ t <- getPOSIXTime+ return $ Seconds (realToFrac t)+#endif measure :: IO a -> IO (Seconds, a) measure action = do
src/Test/Hspec/Core/Config/Definition.hs view
@@ -41,6 +41,7 @@ , configDryRun :: Bool , configFocusedOnly :: Bool , configFailOnFocused :: Bool+, configFailOnPending :: Bool , configPrintSlowItems :: Maybe Int , configPrintCpuTime :: Bool , configFailFast :: Bool@@ -79,6 +80,7 @@ , configDryRun = False , configFocusedOnly = False , configFailOnFocused = False+, configFailOnPending = False , configPrintSlowItems = Nothing , configPrintCpuTime = False , configFailFast = False@@ -231,7 +233,11 @@ runnerOptions = [ mkFlag "dry-run" setDryRun "pretend that everything passed; don't verify anything" , mkFlag "focused-only" setFocusedOnly "do not run anything, unless there are focused spec items"+ , mkFlag "fail-on-focused" setFailOnFocused "fail on focused spec items"+ , mkFlag "fail-on-pending" setFailOnPending "fail on pending spec items"+ , mkFlag "strict" setStrict "enable --fail-on-focused and --fail-on-pending"+ , mkFlag "fail-fast" setFailFast "abort on first failure" , mkFlag "randomize" setRandomize "randomize execution order" , mkOptionNoArg "rerun" (Just 'r') setRerun "rerun all examples that failed in the previous test run (only works in combination with --failure-report or in GHCi)"@@ -260,6 +266,14 @@ setFailOnFocused :: Bool -> Config -> Config setFailOnFocused value config = config {configFailOnFocused = value}++ setFailOnPending :: Bool -> Config -> Config+ setFailOnPending value config = config {configFailOnPending = value}++ setStrict :: Bool -> Config -> Config+ setStrict value =+ setFailOnFocused value+ . setFailOnPending value setFailFast :: Bool -> Config -> Config setFailFast value config = config {configFailFast = value}
src/Test/Hspec/Core/Runner.hs view
@@ -93,9 +93,8 @@ import System.Random import Control.Monad.ST import Data.STRef-import System.Console.ANSI (hSupportsANSI) -import System.Console.ANSI (hHideCursor, hShowCursor)+import System.Console.ANSI (hSupportsANSI, hHideCursor, hShowCursor) import qualified Test.QuickCheck as QC import Test.Hspec.Core.Util (Path)@@ -258,6 +257,14 @@ runSpecForest_ :: Config -> [SpecTree ()] -> IO SpecResult runSpecForest_ config spec = runEvalTree config (specToEvalForest config spec) +mapItem :: (Item a -> Item b) -> [SpecTree a] -> [SpecTree b]+mapItem f = map (fmap f)++failFocusedItems :: Config -> [SpecTree a] -> [SpecTree a]+failFocusedItems config+ | configFailOnFocused config = mapItem failFocused+ | otherwise = id+ failFocused :: Item a -> Item a failFocused item = item {itemExample = example} where@@ -271,11 +278,20 @@ Failure{} -> status | otherwise = itemExample item -failFocusedItems :: Config -> [SpecTree a] -> [SpecTree a]-failFocusedItems config spec- | configFailOnFocused config = map (fmap failFocused) spec- | otherwise = spec+failPendingItems :: Config -> [SpecTree a] -> [SpecTree a]+failPendingItems config+ | configFailOnPending config = mapItem failPending+ | otherwise = id +failPending :: Item a -> Item a+failPending item = item {itemExample = example}+ where+ example params hook p = do+ Result info status <- itemExample item params hook p+ return $ Result info $ case status of+ Pending loc _ -> Failure loc (Reason "item is pending; failing due to --fail-on-pending")+ _ -> status+ focusSpec :: Config -> [SpecTree a] -> [SpecTree a] focusSpec config spec | configFocusedOnly config = spec@@ -342,6 +358,7 @@ specToEvalForest :: Config -> [SpecTree ()] -> [EvalTree] specToEvalForest config = failFocusedItems config+ >>> failPendingItems config >>> focusSpec config >>> toEvalItemForest params >>> applyDryRun config
test/Test/Hspec/Core/Config/OptionsSpec.hs view
@@ -116,6 +116,7 @@ unlines [ "my-spec: option `--fail' is ambiguous; could be one of:" , " --fail-on-focused fail on focused spec items"+ , " --fail-on-pending fail on pending spec items" , " --fail-fast abort on first failure" , " --failure-report=FILE read/write a failure report for use with --rerun" , "in config file ~/.hspec"
test/Test/Hspec/Core/RunnerSpec.hs view
@@ -292,6 +292,32 @@ , "1 example, 1 failure" ] + context "with --fail-on-pending" $ do+ let run = captureLines . ignoreExitCode . withArgs ["--fail-on-pending", "--seed", "23"] . H.hspec . removeLocations+ it "fails on pending spec items" $ do+ r <- run $ do+ H.it "foo" True+ H.it "bar" $ do+ void $ E.throwIO (H.Pending Nothing Nothing)++ normalizeSummary r `shouldBe` [+ ""+ , "foo [✔]"+ , "bar [✘]"+ , ""+ , "Failures:"+ , ""+ , " 1) bar"+ , " item is pending; failing due to --fail-on-pending"+ , ""+ , " To rerun use: --match \"/bar/\""+ , ""+ , "Randomized with seed 23"+ , ""+ , "Finished in 0.0000 seconds"+ , "2 examples, 1 failure"+ ]+ context "with --fail-fast" $ do it "stops after first failure" $ do r <- captureLines . ignoreExitCode . withArgs ["--fail-fast", "--seed", "23"] . H.hspec . removeLocations $ do@@ -641,6 +667,11 @@ it "returns True" $ do H.colorOutputSupported H.ColorAuto isTerminalDevice `shouldReturn` (True, True)++ context "with BUILDKITE=true" $ do+ it "disables progress reporting" $ do+ withEnvironment [("BUILDKITE", "true")] $ do+ H.colorOutputSupported H.ColorAuto isTerminalDevice `shouldReturn` (False, True) context "when NO_COLOR is set" $ do it "returns False" $ do
version.yaml view
@@ -1,1 +1,1 @@-&version 2.10.1+&version 2.10.2