hspec-core 2.1.10 → 2.2.0
raw patch · 7 files changed
+56/−44 lines, 7 filesdep ~HUnitdep ~basedep ~hspec-expectationsPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: HUnit, base, hspec-expectations, hspec-meta
API changes (from Hackage documentation)
- Test.Hspec.Core.Spec: Fail :: String -> Result
+ Test.Hspec.Core.Spec: Fail :: (Maybe Location) -> String -> Result
Files
- hspec-core.cabal +4/−4
- src/Test/Hspec/Core/Example.hs +39/−8
- src/Test/Hspec/Core/Runner/Eval.hs +3/−3
- src/Test/Hspec/Core/Tree.hs +0/−19
- test/Test/Hspec/Core/ExampleSpec.hs +6/−6
- test/Test/Hspec/Core/FormattersSpec.hs +3/−3
- test/Test/Hspec/Core/RunnerSpec.hs +1/−1
hspec-core.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: hspec-core-version: 2.1.10+version: 2.2.0 license: MIT license-file: LICENSE copyright: (c) 2011-2015 Simon Hengel,@@ -40,7 +40,7 @@ , HUnit >= 1.2.5 , QuickCheck >= 2.5.1 , quickcheck-io- , hspec-expectations == 0.7.1.*+ , hspec-expectations == 0.7.2.* , async >= 2 exposed-modules: Test.Hspec.Core.Spec@@ -82,9 +82,9 @@ , HUnit >= 1.2.5 , QuickCheck >= 2.5.1 , quickcheck-io- , hspec-expectations == 0.7.1.*+ , hspec-expectations == 0.7.2.* , async >= 2- , hspec-meta >= 2.1.5+ , hspec-meta >= 2.2.0 , silently >= 1.2.4 , process other-modules:
src/Test/Hspec/Core/Example.hs view
@@ -7,11 +7,13 @@ , Progress , ProgressCallback , Result (..)+, Location (..)+, LocationAccuracy (..) ) where import Data.Maybe (fromMaybe) import Data.List (isPrefixOf)-import Test.HUnit.Lang (HUnitFailure(..))+import qualified Test.HUnit.Lang as HUnit import qualified Control.Exception as E import Data.Typeable (Typeable) import qualified Test.QuickCheck as QC@@ -50,23 +52,52 @@ type ActionWith a = a -> IO () -- | The result of running an example-data Result = Success | Pending (Maybe String) | Fail String+data Result = Success | Pending (Maybe String) | Fail (Maybe Location) String deriving (Eq, Show, Read, Typeable) instance E.Exception Result +-- | @Location@ is used to represent source locations.+data Location = Location {+ locationFile :: FilePath+, locationLine :: Int+, locationColumn :: Int+, locationAccuracy :: LocationAccuracy+} deriving (Eq, Show, Read)++-- | A marker for source locations+data LocationAccuracy =+ -- | The source location is accurate+ ExactLocation |+ -- | The source location was determined on a best-effort basis and my be+ -- wrong or inaccurate+ BestEffort+ deriving (Eq, Show, Read)+ instance Example Bool where type Arg Bool = ()- evaluateExample b _ _ _ = if b then return Success else return (Fail "")+ evaluateExample b _ _ _ = if b then return Success else return (Fail Nothing "") instance Example Expectation where type Arg Expectation = () evaluateExample e = evaluateExample (\() -> e) +hunitFailureToResult :: HUnit.HUnitFailure -> Result+hunitFailureToResult e = case e of+#if MIN_VERSION_HUnit(1,3,0)+ HUnit.HUnitFailure loc err -> Fail location err+ where+ location = case loc of+ Nothing -> Nothing+ Just (HUnit.Location f l c) -> Just $ Location f l c ExactLocation+#else+ HUnit.HUnitFailure err -> Fail Nothing err+#endif+ instance Example (a -> Expectation) where type Arg (a -> Expectation) = a evaluateExample e _ action _ = (action e >> return Success) `E.catches` [- E.Handler (\(HUnitFailure err) -> return (Fail err))+ E.Handler (return . hunitFailureToResult) , E.Handler (return :: Result -> IO Result) ] @@ -85,11 +116,11 @@ return $ case r of QC.Success {} -> Success- QC.Failure {QC.output = m} -> fromMaybe (Fail $ sanitizeFailureMessage r) (parsePending m)- QC.GaveUp {QC.numTests = n} -> Fail ("Gave up after " ++ pluralize n "test" )- QC.NoExpectedFailure {} -> Fail ("No expected failure")+ QC.Failure {QC.output = m} -> fromMaybe (Fail Nothing $ sanitizeFailureMessage r) (parsePending m)+ QC.GaveUp {QC.numTests = n} -> Fail Nothing ("Gave up after " ++ pluralize n "test" )+ QC.NoExpectedFailure {} -> Fail Nothing ("No expected failure") #if MIN_VERSION_QuickCheck(2,8,0)- QC.InsufficientCoverage {} -> Fail ("Insufficient coverage")+ QC.InsufficientCoverage {} -> Fail Nothing ("Insufficient coverage") #endif where qcProgressCallback = QCP.PostTest QCP.NotCounterexample $
src/Test/Hspec/Core/Runner/Eval.hs view
@@ -98,9 +98,9 @@ where forceResult :: Result -> Result forceResult r = case r of- Success -> r+ Success -> r Pending m -> m `deepseq` r- Fail m -> m `deepseq` r+ Fail _ m -> m `deepseq` r data Message = Done | Run (FormatM ()) @@ -147,7 +147,7 @@ Right (Pending reason) -> do increasePendingCount examplePending formatter path reason- Right (Fail err) -> failed loc path (Right err)+ Right (Fail loc_ err) -> failed (loc_ <|> loc) path (Right err) Left err -> failed loc path (Left err) failed loc path err = do
src/Test/Hspec/Core/Tree.hs view
@@ -12,8 +12,6 @@ SpecTree , Tree (..) , Item (..)-, Location (..)-, LocationAccuracy (..) , specGroup , specItem ) where@@ -78,23 +76,6 @@ -- | Example for behavior , itemExample :: Params -> (ActionWith a -> IO ()) -> ProgressCallback -> IO Result }---- | @Location@ is used to represent source locations.-data Location = Location {- locationFile :: FilePath-, locationLine :: Int-, locationColumn :: Int-, locationAccuracy :: LocationAccuracy-} deriving (Eq, Show)---- | A marker for source locations-data LocationAccuracy =- -- | The source location is accurate- ExactLocation |- -- | The source location was determined on a best-effort basis and my be- -- wrong or inaccurate- BestEffort- deriving (Eq, Show) -- | The @specGroup@ function combines a list of specs into a larger spec. specGroup :: String -> [SpecTree a] -> SpecTree a
test/Test/Hspec/Core/ExampleSpec.hs view
@@ -26,7 +26,7 @@ evaluateExample True `shouldReturn` H.Success it "returns Fail on False" $ do- evaluateExample False `shouldReturn` H.Fail ""+ evaluateExample False `shouldReturn` H.Fail Nothing "" it "propagates exceptions" $ do evaluateExample (error "foobar" :: Bool) `shouldThrow` errorCall "foobar"@@ -36,7 +36,7 @@ evaluateExample (23 `shouldBe` (23 :: Int)) `shouldReturn` H.Success it "returns Fail if an expectation does not hold" $ do- H.Fail msg <- evaluateExample (23 `shouldBe` (42 :: Int))+ H.Fail _ msg <- evaluateExample (23 `shouldBe` (42 :: Int)) msg `shouldEndWith` "expected: 42\n but got: 23" it "propagates exceptions" $ do@@ -66,11 +66,11 @@ evaluateExample (property $ \n -> n == (n :: Int)) `shouldReturn` H.Success it "returns Fail if property does not hold" $ do- H.Fail _ <- evaluateExample $ property $ \n -> n /= (n :: Int)+ H.Fail _ _ <- evaluateExample $ property $ \n -> n /= (n :: Int) return () it "shows what falsified it" $ do- H.Fail r <- evaluateExample $ property $ \ (x :: Int) (y :: Int) -> (x == 0 && y == 1) ==> False+ H.Fail _ r <- evaluateExample $ property $ \ (x :: Int) (y :: Int) -> (x == 0 && y == 1) ==> False r `shouldBe` intercalate "\n" [ "Falsifiable (after 1 test): " , "0"@@ -89,7 +89,7 @@ readIORef ref `shouldReturn` 2000 it "pretty-prints exceptions" $ do- H.Fail r <- evaluateExample $ property (\ (x :: Int) -> (x == 0) ==> (error "foobar" :: Bool))+ H.Fail _ r <- evaluateExample $ property (\ (x :: Int) -> (x == 0) ==> (error "foobar" :: Bool)) r `shouldBe` intercalate "\n" [ #if MIN_VERSION_QuickCheck(2,7,0) "uncaught exception: ErrorCall (foobar) (after 1 test)"@@ -101,7 +101,7 @@ context "when used with shouldBe" $ do it "shows what falsified it" $ do- H.Fail r <- evaluateExample $ property $ \ (x :: Int) (y :: Int) -> (x == 0 && y == 1) ==> 23 `shouldBe` (42 :: Int)+ H.Fail _ r <- evaluateExample $ property $ \ (x :: Int) (y :: Int) -> (x == 0 && y == 1) ==> 23 `shouldBe` (42 :: Int) r `shouldStartWith` "Falsifiable (after 1 test): \n" r `shouldEndWith` intercalate "\n" [ "expected: 42"
test/Test/Hspec/Core/FormattersSpec.hs view
@@ -19,11 +19,11 @@ testSpec = do H.describe "Example" $ do H.it "success" (H.Success)- H.it "fail 1" (H.Fail "fail message")+ H.it "fail 1" (H.Fail Nothing "fail message") H.it "pending" (H.pendingWith "pending message")- H.it "fail 2" (H.Fail "")+ H.it "fail 2" (H.Fail Nothing "") H.it "exceptions" (undefined :: H.Result)- H.it "fail 3" (H.Fail "")+ H.it "fail 3" (H.Fail Nothing "") spec :: Spec spec = do
test/Test/Hspec/Core/RunnerSpec.hs view
@@ -423,7 +423,7 @@ it "does not let escape error thunks from failure messages" $ do r <- silence . H.hspecResult $ do- H.it "some example" (H.Fail $ "foobar" ++ undefined)+ H.it "some example" (H.Fail Nothing $ "foobar" ++ undefined) r `shouldBe` H.Summary 1 1 it "runs specs in parallel" $ do