packages feed

hspec-dirstream 0.2.0.0 → 0.3.0.0

raw patch · 3 files changed

+33/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Test.Hspec.Dirstream: testFilesErr :: (Show b, Eq b) => FilePath -> (FilePath -> Bool) -> (String -> Either String b) -> SpecWith ()
+ Test.Hspec.Dirstream: testFilesPredicate :: (Show a, Eq a) => FilePath -> (FilePath -> Bool) -> (String -> a) -> (a -> Bool) -> SpecWith ()

Files

hspec-dirstream.cabal view
@@ -1,5 +1,5 @@ name:                hspec-dirstream-version:             0.2.0.0+version:             0.3.0.0 synopsis:            Helper functions to simplify adding integration tests. description:         This package uses [hspec](http://hackage.haskell.org/package/hspec) and [dirstream](http://hackage.haskell.org/package/dirstream) to provide easy-to-use functions for integration tests. homepage:            https://hub.darcs.net/vmchale/hspec-dirstream
src/Test/Hspec/Dirstream.hs view
@@ -8,6 +8,8 @@     ( -- Functions to generate a `Spec`       testFiles     , testFilesIO+    , testFilesErr+    , testFilesPredicate     -- * Helper functions for dealing with file extensions     , F.extension     , Test.Hspec.Dirstream.hasExtension@@ -61,14 +63,42 @@           -> SpecWith () testFiles dir p f = runSafeT $ runEffect $ paths dir p >-> mapS (testFile f) +-- | A version of the above where the return value can be any 'IO'. testFilesIO :: FilePath -> (F.FilePath -> Bool) -> (String -> IO String) -> SpecWith () testFilesIO dir p f = runSafeT $ runEffect $ paths dir p >-> mapS (testFileIO f) +-- | This function checks that each file returns a value satisfying the+-- predicate.+testFilesPredicate :: (Show a, Eq a)+                   => FilePath -- ^ Directory containing test data+                   -> (F.FilePath -> Bool) -- ^ Filter on file extensions+                   -> (String -> a) -- ^ Function to process the string+                   -> (a -> Bool) -- ^ Predicate to check the result+                   -> SpecWith ()+testFilesPredicate dir p f pr = runSafeT $ runEffect $ paths dir p >-> mapS (testFilePredicate f pr)+ testFileIO :: (String -> IO String) -> String -> SpecWith () testFileIO fun f = it f $ do     sample <- readFile f     expected <- readFile (replaceExtension f ".out")     fun sample >>= (`shouldBe` expected)++-- | This function simply tests that each file returns a 'Left' value and that+-- the error message contained therein matches the contents of the appropriate+-- file.+testFilesErr :: (Show b, Eq b) => FilePath -> (F.FilePath -> Bool) -> (String -> Either String b) -> SpecWith ()+testFilesErr dir p f = runSafeT $ runEffect $ paths dir p >-> mapS (testFileErr f)++testFilePredicate :: (Eq a, Show a) => (String -> a) -> (a -> Bool) -> String -> SpecWith ()+testFilePredicate fun p f = it f $ do+    sample <- readFile f+    fun sample `shouldSatisfy` p++testFileErr :: (Eq b, Show b) => (String -> Either String b) -> String -> SpecWith ()+testFileErr fun f = it f $ do+    sample <- readFile f+    expected <- readFile (replaceExtension f ".out")+    fun sample `shouldBe` Left expected  testFile :: (Eq a, Show a) => (String -> Either a String) -> String -> SpecWith () testFile fun f = it f $ do
test/Spec.hs view
@@ -13,3 +13,5 @@             testFiles "test/data" (hasExtension "hs") ((pure :: a -> Either String a) . tail)     describe "testFilesIO" $             testFilesIO "test/data" (hasExtension "hs") (pure . tail)+    describe "testFilesPredicate" $+            testFilesPredicate "test/data" (hasExtension "hs") tail ((>= 0) . length)