hspec-core 2.6.1 → 2.7.0
raw patch · 5 files changed
+90/−10 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Test.Hspec.Core.Runner: [configFailOnFocused] :: Config -> Bool
+ Test.Hspec.Core.Runner: [configFocusedOnly] :: Config -> Bool
- Test.Hspec.Core.Runner: Config :: Bool -> Bool -> Bool -> Bool -> Maybe FilePath -> Bool -> Bool -> Maybe (Path -> Bool) -> Maybe (Path -> Bool) -> Maybe Integer -> Maybe Int -> Maybe Int -> Maybe Int -> Int -> ColorMode -> Bool -> Maybe Formatter -> Bool -> Either Handle FilePath -> Maybe Int -> Config
+ Test.Hspec.Core.Runner: Config :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe FilePath -> Bool -> Bool -> Maybe (Path -> Bool) -> Maybe (Path -> Bool) -> Maybe Integer -> Maybe Int -> Maybe Int -> Maybe Int -> Int -> ColorMode -> Bool -> Maybe Formatter -> Bool -> Either Handle FilePath -> Maybe Int -> Config
Files
- hspec-core.cabal +2/−2
- src/Test/Hspec/Core/Config/Options.hs +23/−6
- src/Test/Hspec/Core/Runner.hs +27/−2
- test/Test/Hspec/Core/Config/OptionsSpec.hs +1/−0
- test/Test/Hspec/Core/RunnerSpec.hs +37/−0
hspec-core.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 7cca186c021b61bad5f4aa3748a723fbe2ec81a918644d575eaa8d7fbba6f3a0+-- hash: 39dc148675f73276544e876331589928821112ae13bb688991d3c5c5ee686cee name: hspec-core-version: 2.6.1+version: 2.7.0 license: MIT license-file: LICENSE copyright: (c) 2011-2019 Simon Hengel,
src/Test/Hspec/Core/Config/Options.hs view
@@ -33,6 +33,8 @@ data Config = Config { configIgnoreConfigFile :: Bool , configDryRun :: Bool+, configFocusedOnly :: Bool+, configFailOnFocused :: Bool , configPrintCpuTime :: Bool , configFastFail :: Bool , configFailureReport :: Maybe FilePath@@ -61,6 +63,8 @@ defaultConfig = Config { configIgnoreConfigFile = False , configDryRun = False+, configFocusedOnly = False+, configFailOnFocused = False , configPrintCpuTime = False , configFastFail = False , configFailureReport = Nothing@@ -190,10 +194,13 @@ ] runnerOptions :: Monad m => [OptDescr (Result m -> Result m)]-runnerOptions = [- Option [] ["dry-run"] (NoArg setDryRun) "pretend that everything passed; don't verify anything"- , Option [] ["fail-fast"] (NoArg setFastFail) "abort on first failure"- , Option "r" ["rerun"] (NoArg setRerun) "rerun all examples that failed in the previous test run (only works in combination with --failure-report or in GHCi)"+runnerOptions = concat [+ 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-fast" setFastFail "abort on first failure"+ ] ++ [+ Option "r" ["rerun"] (NoArg setRerun) "rerun all examples that failed in the previous test run (only works in combination with --failure-report or in GHCi)" , mkOption [] "failure-report" (Arg "FILE" return setFailureReport) "read/write a failure report for use with --rerun" , Option [] ["rerun-all-on-success"] (NoArg setRerunAllOnSuccess) "run the whole test suite after a previously failing rerun succeeds for the first time (only works in combination with --rerun)" , mkOption "j" "jobs" (Arg "N" readMaxJobs setMaxJobs) "run at most N parallelizable tests simultaneously (default: number of available processors)"@@ -211,8 +218,18 @@ setMaxJobs :: Int -> Config -> Config setMaxJobs n c = c {configConcurrentJobs = Just n} - setDryRun = set $ \config -> config {configDryRun = True}- setFastFail = set $ \config -> config {configFastFail = True}+ setDryRun :: Bool -> Config -> Config+ setDryRun value config = config {configDryRun = value}++ setFocusedOnly :: Bool -> Config -> Config+ setFocusedOnly value config = config {configFocusedOnly = value}++ setFailOnFocused :: Bool -> Config -> Config+ setFailOnFocused value config = config {configFailOnFocused = value}++ setFastFail :: Bool -> Config -> Config+ setFastFail value config = config {configFastFail = value}+ setRerun = set $ \config -> config {configRerun = True} setRerunAllOnSuccess = set $ \config -> config {configRerunAllOnSuccess = True}
src/Test/Hspec/Core/Runner.hs view
@@ -180,6 +180,29 @@ then runSpec spec c_ else return summary +failFocused :: Item a -> Item a+failFocused item = item {itemExample = example}+ where+ failure = Failure Nothing (Reason "item is focused; failing due to --fail-on-focused")+ example+ | itemIsFocused item = \ params hook p -> do+ Result info status <- itemExample item params hook p+ return $ Result info $ case status of+ Success -> failure+ Pending _ _ -> failure+ Failure{} -> status+ | otherwise = itemExample item++failFocusedItems :: Config -> Spec -> Spec+failFocusedItems config spec+ | configFailOnFocused config = mapSpecItem_ failFocused spec+ | otherwise = spec++focusSpec :: Config -> Spec -> Spec+focusSpec config spec+ | configFocusedOnly config = spec+ | otherwise = focus spec+ runSpec_ :: Config -> Spec -> IO Summary runSpec_ config spec = do withHandle config $ \h -> do@@ -193,9 +216,11 @@ useColor <- doesUseColor h config - let params = Params (configQuickCheckArgs config) (configSmallCheckDepth config)+ let+ focusedSpec = focusSpec config (failFocusedItems config spec)+ params = Params (configQuickCheckArgs config) (configSmallCheckDepth config) - filteredSpec <- filterSpecs config . mapMaybe (toEvalTree params) . applyDryRun config <$> runSpecM (focus spec)+ filteredSpec <- filterSpecs config . mapMaybe (toEvalTree params) . applyDryRun config <$> runSpecM focusedSpec (total, failures) <- withHiddenCursor useColor h $ do let
test/Test/Hspec/Core/Config/OptionsSpec.hs view
@@ -91,6 +91,7 @@ fromLeft (parseOptions [("~/.hspec", ["--fail"])] Nothing []) `shouldBe` (ExitFailure 1, unlines [ "my-spec: option `--fail' is ambiguous; could be one of:"+ , " --fail-on-focused fail on focused 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
@@ -254,6 +254,43 @@ H.it "bar" True readIORef ref `shouldReturn` False + context "with --focused-only" $ do+ let run = captureLines . withArgs ["--focused-only"] . H.hspec+ context "when there aren't any focused spec items" $ do+ it "does not run anything" $ do+ r <- run $ do+ H.it "foo" True+ H.it "bar" True+ normalizeSummary r `shouldBe` [+ ""+ , ""+ , "Finished in 0.0000 seconds"+ , "0 examples, 0 failures"+ ]++ context "with --fail-on-focused" $ do+ let run = captureLines . ignoreExitCode . withArgs ["--fail-on-focused", "--seed", "23"] . H.hspec . removeLocations+ it "fails on focused spec items" $ do+ r <- run $ do+ H.it "foo" True+ H.fit "bar" True+ normalizeSummary r `shouldBe` [+ ""+ , "bar FAILED [1]"+ , ""+ , "Failures:"+ , ""+ , " 1) bar"+ , " item is focused; failing due to --fail-on-focused"+ , ""+ , " To rerun use: --match \"/bar/\""+ , ""+ , "Randomized with seed 23"+ , ""+ , "Finished in 0.0000 seconds"+ , "1 example, 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