packages feed

tasty-hspec 0.1.0.1 → 0.2

raw patch · 2 files changed

+96/−49 lines, 2 filesdep +QuickCheckdep +randomdep +tasty-quickcheckdep ~basedep ~hspecdep ~tastyPVP ok

version bump matches the API change (PVP)

Dependencies added: QuickCheck, random, tasty-quickcheck, tasty-smallcheck

Dependency ranges changed: base, hspec, tasty

API changes (from Hackage documentation)

- Test.Tasty.Hspec: data TestTree :: *
- Test.Tasty.Hspec: instance IsTest MySpec
- Test.Tasty.Hspec: instance Typeable MySpec
- Test.Tasty.Hspec: testCase :: TestName -> Spec -> TestTree
- Test.Tasty.Hspec: type TestName = String
+ Test.Tasty.Hspec: QuickCheckMaxRatio :: Int -> QuickCheckMaxRatio
+ Test.Tasty.Hspec: QuickCheckMaxSize :: Int -> QuickCheckMaxSize
+ Test.Tasty.Hspec: QuickCheckReplay :: Maybe (QCGen, Int) -> QuickCheckReplay
+ Test.Tasty.Hspec: QuickCheckTests :: Int -> QuickCheckTests
+ Test.Tasty.Hspec: SmallCheckDepth :: Int -> SmallCheckDepth
+ Test.Tasty.Hspec: instance IsTest Item
+ Test.Tasty.Hspec: instance Typeable Item
+ Test.Tasty.Hspec: newtype QuickCheckMaxRatio :: *
+ Test.Tasty.Hspec: newtype QuickCheckMaxSize :: *
+ Test.Tasty.Hspec: newtype QuickCheckReplay :: *
+ Test.Tasty.Hspec: newtype QuickCheckTests :: *
+ Test.Tasty.Hspec: newtype SmallCheckDepth :: *
+ Test.Tasty.Hspec: testSpec :: TestName -> Spec -> IO TestTree

Files

Test/Tasty/Hspec.hs view
@@ -1,55 +1,98 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} -module Test.Tasty.Hspec-    ( testCase--    -- * Re-exports+module Test.Tasty.Hspec (+    -- * Test+      testSpec+    -- * Options+    -- | === Re-exported from <https://hackage.haskell.org/package/tasty-smallcheck tasty-smallcheck>+    , SmallCheckDepth(..)+    -- | === Re-exported from <https://hackage.haskell.org/package/tasty-quickcheck tasty-quickcheck>+    , QuickCheckMaxRatio(..)+    , QuickCheckMaxSize(..)+    , QuickCheckReplay(..)+    , QuickCheckTests(..)+    -- * Hspec re-export     , module Test.Hspec-    , Test.Tasty.TestName-    , Test.Tasty.TestTree     ) where +import           Control.Applicative    ((<$>))+import           Control.Monad          (join)+import           Data.Proxy+import           Data.Typeable          (Typeable)+import qualified Test.Hspec             as H+import qualified Test.Hspec.Core        as H+import qualified Test.Hspec.Runner      as H+import qualified Test.QuickCheck        as QC+import qualified Test.QuickCheck.Random as QC+import qualified Test.Tasty             as T+import qualified Test.Tasty.SmallCheck  as TSC+import qualified Test.Tasty.Options     as T+import qualified Test.Tasty.Providers   as T+import qualified Test.Tasty.QuickCheck  as TQC+import           System.Random++-- For re-export. import Test.Hspec+import Test.Tasty.SmallCheck (SmallCheckDepth(..))+import Test.Tasty.QuickCheck (QuickCheckMaxRatio(..), QuickCheckMaxSize(..)+                             , QuickCheckReplay(..), QuickCheckTests(..)) -import Data.Typeable        (Typeable)-import Test.Tasty           (TestName, TestTree)-import Test.Tasty.Providers (IsTest(..), singleTest, testPassed, testFailed)-import Test.Hspec.Runner    (Summary(..), hspecResult)+-- | Create a <https://hackage.haskell.org/package/tasty tasty> 'T.TestTree' from an+-- <https://hackage.haskell.org/package/hspec Hspec> 'H.Spec'.+testSpec :: T.TestName -> H.Spec -> IO T.TestTree+testSpec name spec = H.runSpecM spec >>= fmap (T.testGroup name . join) . mapM specTreeToTestTrees --- | Turn an hspec @Spec@ into a tasty @TestTree@.------ > module AnimalsSpec (tests) where--- >--- > import Test.Tasty.Hspec--- >--- > tests :: TestTree--- > tests = testGroup "animals"--- >     [ testCase "mammals" mammalsSpec--- >     , testCase "birds"   birdsSpec--- >     ]--- >--- > mammalsSpec :: Spec--- > mammalsSpec = do--- >     describe "cow" $ do--- >         it "moos" $--- >             speak cow `shouldBe` "moo"--- >--- >         it "eats grass" $--- >             hungryFor cow `shouldBe` "grass"--- >--- > birdsSpec :: Spec--- > birdsSpec = do--- >     describe "ostrich" $ do--- >         it "sticks its head in sand" $--- >             fmap (`shouldBe` InSand) getHeadState-testCase :: TestName -> Spec -> TestTree-testCase name = singleTest name . MySpec+specTreeToTestTrees :: H.SpecTree -> IO [T.TestTree]+specTreeToTestTrees (H.SpecGroup name specs) = return . T.testGroup name . join <$> mapM specTreeToTestTrees specs+specTreeToTestTrees (H.BuildSpecs action)    = action >>= fmap join . mapM specTreeToTestTrees+specTreeToTestTrees (H.SpecItem name item)   = return [T.singleTest name (Item item)] -newtype MySpec = MySpec Spec deriving Typeable+hspecResultToTastyResult :: H.Result -> T.Result+hspecResultToTastyResult H.Success        = T.testPassed ""+hspecResultToTastyResult (H.Pending mstr) = T.testFailed ("test pending" ++ maybe "" (": " ++) mstr)+hspecResultToTastyResult (H.Fail str)     = T.testFailed str -instance IsTest MySpec where-    run _ (MySpec spec) _ = do-        (Summary _ failures) <- hspecResult spec-        return $ if (failures == 0) then testPassed "" else testFailed ""-        --return $ Result (failures == 0) ""-    testOptions = return []+newtype Item = Item H.Item+    deriving Typeable++instance T.IsTest Item where+    run opts (Item (H.Item _ example)) progress =+        hspecResultToTastyResult <$> example params id hprogress+      where+        params :: H.Params+        params = H.Params+            { H.paramsQuickCheckArgs = qc_args+            , H.paramsSmallCheckDepth = sc_depth+            }+          where+            qc_args :: QC.Args+            qc_args =+                let TQC.QuickCheckTests    num_tests = T.lookupOption opts+                    TQC.QuickCheckReplay   replay    = T.lookupOption opts+                    TQC.QuickCheckMaxSize  max_size  = T.lookupOption opts+                    TQC.QuickCheckMaxRatio max_ratio = T.lookupOption opts+                in QC.stdArgs+                    { QC.chatty          = False+                    , QC.maxDiscardRatio = max_ratio+                    , QC.maxSize         = max_size+                    , QC.maxSuccess      = num_tests+                    , QC.replay          = replay+                    }++            sc_depth :: Int+            sc_depth = let TSC.SmallCheckDepth depth = T.lookupOption opts in depth++        hprogress :: H.Progress -> IO ()+        hprogress (x,y) = progress $ T.Progress+            { T.progressText    = ""+            , T.progressPercent = fromIntegral x / fromIntegral y+            }++    testOptions = return+        [ T.Option (Proxy :: Proxy TQC.QuickCheckTests)+        , T.Option (Proxy :: Proxy TQC.QuickCheckReplay)+        , T.Option (Proxy :: Proxy TQC.QuickCheckMaxSize)+        , T.Option (Proxy :: Proxy TQC.QuickCheckMaxRatio)+        , T.Option (Proxy :: Proxy TSC.SmallCheckDepth)+        ]
tasty-hspec.cabal view
@@ -1,5 +1,5 @@ name:                tasty-hspec-version:             0.1.0.1+version:             0.2 synopsis:            Hspec support for the Tasty test framework. description:         Hspec support for the Tasty test framework. @@ -15,7 +15,11 @@ library   exposed-modules:     Test.Tasty.Hspec   other-extensions:    DeriveDataTypeable-  build-depends:       base ==4.*-                     , hspec-                     , tasty >= 0.8+  build-depends:       base             ==4.*+                     , hspec            >=1.11.0 && <1.12.0+                     , QuickCheck       >=2.7    && <3+                     , tasty            >= 0.8   && <1.0+                     , tasty-smallcheck >=0.1    && <0.9+                     , tasty-quickcheck >=0.3    && <0.9+                     , random   default-language:    Haskell2010