hspec 0.6.0 → 0.6.1
raw patch · 3 files changed
+88/−3 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Test.Hspec.Formatters: failed_examples :: Bool -> Formatter
+ Test.Hspec.Formatters: progress :: Bool -> Formatter
+ Test.Hspec.Formatters: silent :: Bool -> Formatter
Files
- Specs.hs +17/−1
- Test/Hspec/Formatters.hs +70/−1
- hspec.cabal +1/−1
Specs.hs view
@@ -4,7 +4,7 @@ import Test.Hspec import Test.Hspec.Runner (hHspecWithFormat, toExitCode) import Test.Hspec.Core (Spec(..),Result(..),quantify,failedCount)-import Test.Hspec.Formatters (specdoc)+import Test.Hspec.Formatters import Test.Hspec.QuickCheck import Test.Hspec.HUnit () import System.IO@@ -92,6 +92,9 @@ it "quickcheck" (property $ \ i -> i == (i+1::Integer))] (reportContents, exampleSpecs) <- capture $ hHspecWithFormat (specdoc False) stdout testSpecs+ (silentReportContents, _) <- capture $ hHspecWithFormat (silent False) stdout testSpecs+ (progressReportContents, _) <- capture $ hHspecWithFormat (progress False) stdout testSpecs+ (failed_examplesReportContents, _) <- capture $ hHspecWithFormat (failed_examples False) stdout testSpecs let report = lines reportContents @@ -184,6 +187,19 @@ it "accepts a message to display in the report" (any (== " # pending message") report)+ ],+ describe "the \"hHspecWithFormat\" function" [+ it "can use the \"silent\" formatter to show no output"+ (null silentReportContents),++ it "can use the \"progress\" formatter to show '..F...FF.F' style output"+ (HUnit.assertEqual "" ".F.FFF" (head $ lines progressReportContents)),++ it "can use the \"specdoc\" formatter to show all examples (default)"+ (HUnit.assertEqual "" "Example" (lines reportContents !! 1)),++ it "can use the \"failed_examples\" formatter to show only failed examples"+ (HUnit.assertEqual "" " x fail 1 FAILED [1]" (head $ lines failed_examplesReportContents)) ], describe "quantify (an internal function)" [ it "returns an amount and a word given an amount and word"
Test/Hspec/Formatters.hs view
@@ -2,7 +2,7 @@ -- They follow a structure similar to RSpec formatters. -- module Test.Hspec.Formatters (- specdoc+ silent, specdoc, progress, failed_examples ) where import Test.Hspec.Core@@ -12,6 +12,17 @@ import Control.Monad (when) import System.Console.ANSI +silent :: Bool -> Formatter+silent _ = Formatter {+ exampleGroupStarted = \ _ _ -> return (),+ examplePassed = \ _ _ _ -> return (),+ exampleFailed = \ _ _ _ -> return (),+ examplePending = \ _ _ _ -> return (),+ errorsFormatter = \ _ _ -> return (),+ footerFormatter = \ _ _ _ -> return ()+ }++ specdoc :: Bool -> Formatter specdoc useColor = Formatter { exampleGroupStarted = \ h spec -> do@@ -30,6 +41,64 @@ when useColor (pendingColor h) let (Pending s) = result spec hPutStrLn h $ " - " ++ requirement spec ++ "\n # " ++ s,++ errorsFormatter = \ h errors -> do+ when useColor (failColor h)+ mapM_ (hPutStrLn h) ("" : intersperse "" errors)+ when (not $ null errors) (hPutStrLn h ""),++ footerFormatter = \ h specs time -> do+ when useColor (if failedCount specs == 0 then passColor h else failColor h)+ hPutStrLn h $ printf "Finished in %1.4f seconds" time+ hPutStrLn h ""+ hPutStr h $ quantify (length specs) "example" ++ ", "+ hPutStrLn h $ quantify (failedCount specs) "failure"+ when useColor (normalColor h)+ }+++progress :: Bool -> Formatter+progress useColor = Formatter {+ exampleGroupStarted = \ _ _ -> return (),++ examplePassed = \ h _ _ -> do+ when useColor (passColor h)+ hPutStr h ".",++ exampleFailed = \ h _ _ -> do+ when useColor (failColor h)+ hPutStr h "F",++ examplePending = \ h _ _ -> do+ when useColor (pendingColor h)+ hPutStr h $ ".",++ errorsFormatter = \ h errors -> do+ when useColor (failColor h)+ mapM_ (hPutStrLn h) ("" : intersperse "" errors)+ when (not $ null errors) (hPutStrLn h ""),++ footerFormatter = \ h specs time -> do+ when useColor (if failedCount specs == 0 then passColor h else failColor h)+ hPutStrLn h $ printf "Finished in %1.4f seconds" time+ hPutStrLn h ""+ hPutStr h $ quantify (length specs) "example" ++ ", "+ hPutStrLn h $ quantify (failedCount specs) "failure"+ when useColor (normalColor h)+ }+++failed_examples :: Bool -> Formatter+failed_examples useColor = Formatter {+ exampleGroupStarted = \ _ _ -> return (),++ examplePassed = \ _ _ _ -> return (),++ exampleFailed = \ h spec errors -> do+ when useColor (failColor h)+ hPutStrLn h $ " x " ++ requirement spec ++ " FAILED [" ++ (show $ (length errors) + 1) ++ "]",++ examplePending = \ _ _ _ -> return (), errorsFormatter = \ h errors -> do when useColor (failColor h)
hspec.cabal view
@@ -1,5 +1,5 @@ name: hspec-version: 0.6.0+version: 0.6.1 cabal-version: -any build-type: Custom license: BSD3