packages feed

hspec-core 2.5.5 → 2.5.6

raw patch · 3 files changed

+89/−53 lines, 3 filesdep ~HUnitdep ~QuickCheck

Dependency ranges changed: HUnit, QuickCheck

Files

hspec-core.cabal view
@@ -1,13 +1,13 @@-cabal-version: >= 1.10+cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.29.5.+-- This file has been generated from package.yaml by hpack version 0.30.0. -- -- see: https://github.com/sol/hpack ----- hash: 18722f32fa5f70fec923fb16bae44075fdcc96cfab7622d6d9146d22fb7faed5+-- hash: d15ffeb43ef1d93930099b550ae67aff43faf175f1b1c6479204335df8ab4304  name:             hspec-core-version:          2.5.5+version:          2.5.6 license:          MIT license-file:     LICENSE copyright:        (c) 2011-2018 Simon Hengel,@@ -33,8 +33,8 @@       vendor   ghc-options: -Wall   build-depends:-      HUnit >=1.5.0.0-    , QuickCheck >=2.10+      HUnit ==1.6.*+    , QuickCheck ==2.12.*     , ansi-terminal >=0.5     , array     , base >=4.5.0.0 && <5@@ -91,8 +91,8 @@   ghc-options: -Wall   cpp-options: -DTEST   build-depends:-      HUnit >=1.5.0.0-    , QuickCheck >=2.10+      HUnit ==1.6.*+    , QuickCheck ==2.12.*     , ansi-terminal >=0.5     , array     , base >=4.5.0.0 && <5@@ -112,6 +112,8 @@     , temporary     , tf-random     , transformers >=0.2.2.0+  build-tool-depends:+      hspec-meta:hspec-meta-discover   other-modules:       Test.Hspec.Core.Clock       Test.Hspec.Core.Compat
src/Test/Hspec/Core/QuickCheckUtil.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE RecordWildCards #-} module Test.Hspec.Core.QuickCheckUtil where @@ -10,6 +9,7 @@ import           Data.Maybe import           Data.Int import           System.Random+ import           Test.QuickCheck import           Test.QuickCheck.Text (isOneLine) import qualified Test.QuickCheck.Property as QCP@@ -17,14 +17,11 @@ import           Test.QuickCheck.Gen import           Test.QuickCheck.IO () import           Test.QuickCheck.Random+import qualified Test.QuickCheck.Test as QC (showTestCount)+import           Test.QuickCheck.State (State(..))  import           Test.Hspec.Core.Util -import           Test.QuickCheck.Test (formatLabel)--formatLabels :: Int -> [(String, Double)] -> String-formatLabels n = unlines . map (formatLabel n True)- aroundProperty :: ((a -> IO ()) -> IO ()) -> (a -> Property) -> Property aroundProperty action p = MkProperty . MkGen $ \r n -> aroundProp action $ \a -> (unGen . unProperty $ p a) r n @@ -88,33 +85,48 @@         | isOneLine reason = reason ++ " " ++ numbers ++ colonNewline         | otherwise = numbers ++ colonNewline ++ ensureTrailingNewline reason       numbers = formatNumbers numTests numShrinks-#if MIN_VERSION_QuickCheck(2,11,0)       colonNewline = ":\n"-#else-      colonNewline = ": \n"-#endif    GaveUp {..} ->     case stripSuffix outputWithoutVerbose output of-      Just info -> otherFailure info ("Gave up after " ++ pluralize numTests "test" ++ "!")+      Just info -> otherFailure info ("Gave up after " ++ numbers ++ "!")       Nothing -> couldNotParse output     where-      outputWithoutVerbose = "*** Gave up! Passed only " ++ pluralize numTests "test" ++ ".\n"+      numbers = showTestCount numTests numDiscarded+      outputWithoutVerbose = "*** Gave up! Passed only " ++ numbers ++ " tests.\n"    NoExpectedFailure {..} -> case splitBy "*** Failed! " output of     Just (info, err) -> otherFailure info err     Nothing -> couldNotParse output -  InsufficientCoverage {..} -> case splitBy ("*** " ++ pre) output of-    Just (info, err) -> otherFailure info (pre ++ err)-    Nothing -> couldNotParse output-    where-      pre = "Insufficient coverage after "-   where     result = QuickCheckResult (numTests r) . strip     otherFailure info err = result info (QuickCheckOtherFailure $ strip err)     couldNotParse = result "" . QuickCheckOtherFailure++showTestCount :: Int -> Int -> String+showTestCount success discarded = QC.showTestCount state+  where+    state = MkState {+      terminal                  = undefined+    , maxSuccessTests           = undefined+    , maxDiscardedRatio         = undefined+    , coverageConfidence        = undefined+    , computeSize               = undefined+    , numTotMaxShrinks          = 0+    , numSuccessTests           = success+    , numDiscardedTests         = discarded+    , numRecentlyDiscardedTests = 0+    , labels                    = mempty+    , classes                   = mempty+    , tables                    = mempty+    , requiredCoverage          = mempty+    , expected                  = True+    , randomSeed                = mkGen 0+    , numSuccessShrinks         = 0+    , numTryShrinks             = 0+    , numTotTryShrinks          = 0+    }  ensureTrailingNewline :: String -> String ensureTrailingNewline = unlines . lines
test/Test/Hspec/Core/QuickCheckUtilSpec.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE StandaloneDeriving #-} {-# OPTIONS_GHC -fno-warn-orphans #-}@@ -60,7 +59,7 @@           p n = (n == 1234) ==> True            qc = quickCheckWithResult args {maxSuccess = 2, maxDiscardRatio = 1}-          result = QuickCheckResult 0 "" (QuickCheckOtherFailure "Gave up after 0 tests!")+          result = QuickCheckResult 0 "" (QuickCheckOtherFailure "Gave up after 0 tests; 2 discarded!")        it "parses result" $ do         parseQuickCheckResult <$> qc p `shouldReturn` result@@ -97,27 +96,58 @@         parseQuickCheckResult <$> quickCheckWithResult args {maxSuccess = 2} (verbose p) `shouldReturn`           QuickCheckResult 2 info (QuickCheckOtherFailure "Passed 2 tests (expected failure).") -    context "with InsufficientCoverage" $ do-      let-        p :: Int -> Property-        p n = cover (n == 23) 10 "is 23" True+    context "with cover" $ do+      context "without checkCoverage" $ do+        let+          p :: Int -> Property+          p n = cover 10 (n == 23) "is 23" True -      it "parses result" $ do-        parseQuickCheckResult <$> qc p `shouldReturn`-          QuickCheckResult 100 "" (QuickCheckOtherFailure "Insufficient coverage after 100 tests (only 0% is 23, not 10%).")+        it "parses result" $ do+          parseQuickCheckResult <$> qc p `shouldReturn`+            QuickCheckResult 100 "+++ OK, passed 100 tests.\n\nOnly 0% is 23, but expected 10%" QuickCheckSuccess -      it "includes verbose output" $ do+        it "includes verbose output" $ do+          let+            info = intercalate "\n" [+                "Passed:"+              , "0"+              , ""+              , "Passed:"+              , "-39"+              , ""+              , "+++ OK, passed 2 tests."+              , ""+              , "Only 0% is 23, but expected 10%"+              ]+          parseQuickCheckResult <$> quickCheckWithResult args {maxSuccess = 2} (verbose p) `shouldReturn`+            QuickCheckResult 2 info QuickCheckSuccess++      context "with checkCoverage" $ do         let-          info = intercalate "\n" [-              "Passed:"-            , "0"-            , ""-            , "Passed:"-            , "-39"-            ]-        parseQuickCheckResult <$> quickCheckWithResult args {maxSuccess = 2} (verbose p) `shouldReturn`-          QuickCheckResult 2 info (QuickCheckOtherFailure "Insufficient coverage after 2 tests (only 0% is 23, not 10%).")+          p :: Int -> Property+          p n = checkCoverage $ cover 10 (n == 23) "is 23" True +          failure :: QuickCheckFailure+          failure = QCFailure {+              quickCheckFailureNumShrinks = 0+            , quickCheckFailureException = Nothing+            , quickCheckFailureReason = "Insufficient coverage"+            , quickCheckFailureCounterexample = [+                " 1.0% is 23"+              , ""+              , "Only 1.0% is 23, but expected 10.0%"+              ]+            }++        it "parses result" $ do+          parseQuickCheckResult <$> qc p `shouldReturn`+            QuickCheckResult 800 "" (QuickCheckFailure failure)++        it "includes verbose output" $ do+          let info = intercalate "\n\n" (replicate 799 "Passed:")+          parseQuickCheckResult <$> qc (verbose . p) `shouldReturn`+            QuickCheckResult 800 info (QuickCheckFailure failure)+     context "with Failure" $ do       context "with single-line failure reason" $ do         let@@ -138,11 +168,7 @@                 , "Failed:"                 , "1"                 , ""-#if MIN_VERSION_QuickCheck(2,11,0)                 , "Passed:"-#else-                , "*** Failed! Passed:"-#endif                 , "0"                 ] @@ -167,11 +193,7 @@                 , "Failed:"                 , "1"                 , ""-#if MIN_VERSION_QuickCheck(2,11,0)                 , "Passed:"-#else-                , "*** Failed! Passed:"-#endif                 , "0"                 ]           parseQuickCheckResult <$> qc (verbose p) `shouldReturn` result {quickCheckResultInfo = info}