hspec-dirstream (empty) → 0.1.0.0
raw patch · 10 files changed
+181/−0 lines, 10 filesdep +basedep +dirstreamdep +filepathsetup-changed
Dependencies added: base, dirstream, filepath, hspec, hspec-core, hspec-dirstream, pipes, pipes-safe, system-filepath, text
Files
- LICENSE +11/−0
- README.md +5/−0
- Setup.hs +2/−0
- cabal.project.local +6/−0
- hspec-dirstream.cabal +66/−0
- src/Test/Hspec/Dirstream.hs +65/−0
- stack.yaml +10/−0
- test/Spec.hs +14/−0
- test/data/file.hs +1/−0
- test/data/file.out +1/−0
+ LICENSE view
@@ -0,0 +1,11 @@+Copyright Vanessa McHale (c) 2018++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.++3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,5 @@+# hspec-dirstream++This provides some functions intended to make writing integration tests eaiser.+You can view documentation+[here](https://hackage.haskell.org/package/hspec-dirstream)
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cabal.project.local view
@@ -0,0 +1,6 @@+constraints: hspec-dirstream +development+with-compiler: ghc-8.2.2+tests: True+documentation: True+haddock-hoogle: True+haddock-internal: True
+ hspec-dirstream.cabal view
@@ -0,0 +1,66 @@+name: hspec-dirstream+version: 0.1.0.0+synopsis: Helper functions to simplify adding integration tests.+description: This package uses+ [hspec](https://hackage.haskell.org/package/hspec) and+ [dirstream](https://hackage.haskell.org/package/dirstream)+ to provide easy-to-use functions designed for use in+ integration tests.+homepage: https://hub.darcs.net/vmchale/hspec-dirstream+license: BSD3+license-file: LICENSE+author: Vanessa McHale+maintainer: vamchale@gmail.com+copyright: Copyright: (c) 2018 Vanessa McHale+category: Testing, Development+build-type: Simple+extra-doc-files: README.md+data-files: test/data/*.hs+ , test/data/*.out+extra-source-files: stack.yaml+ , cabal.project.local+cabal-version: >=1.18++Flag development {+ Description: Enable `-Werror`+ manual: True+ default: False+}++library+ hs-source-dirs: src+ exposed-modules: Test.Hspec.Dirstream+ build-depends: base >= 4.7 && < 5+ , hspec+ , dirstream+ , pipes+ , pipes-safe+ , filepath+ , hspec-core+ , system-filepath+ , text+ default-language: Haskell2010+ if flag(development)+ ghc-options: -Werror+ if impl(ghc >= 8.0)+ ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat+ ghc-options: -Wall++test-suite hspec-dirstream-test+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: Spec.hs+ build-depends: base+ , hspec-dirstream+ , hspec+ if flag(development)+ if impl(ghc >= 8.0)+ ghc-options: -Werror+ if impl(ghc >= 8.0)+ ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat+ ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall+ default-language: Haskell2010++source-repository head+ type: darcs+ location: https://hub.darcs.net/vmchale/hspec-dirstream
+ src/Test/Hspec/Dirstream.hs view
@@ -0,0 +1,65 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE StandaloneDeriving #-}++module Test.Hspec.Dirstream+ ( testFiles+ , F.extension+ , Test.Hspec.Dirstream.hasExtension+ ) where++import Data.DirStream+import Data.Text (Text)+import qualified Filesystem.Path.CurrentOS as F+import Pipes+import qualified Pipes.Prelude as P+import Pipes.Safe+import System.FilePath+import Test.Hspec+import Test.Hspec.Core.Spec++deriving instance MonadCatch (SpecM a)+deriving instance MonadThrow (SpecM a)+deriving instance MonadMask (SpecM a)+deriving instance MonadIO (SpecM a)++hasExtension :: Text -> F.FilePath -> Bool+hasExtension = flip F.hasExtension++mapS :: (a -> SpecM () ()) -> Proxy () a y' y (SafeT (SpecM ())) r+mapS = P.mapM_ . (lift .)++paths :: MonadSafe m => String -> (F.FilePath -> Bool) -> Producer String m ()+paths dir p = every (childOf path) >-> P.filter p >-> P.map F.encodeString+ where path = F.decodeString dir++-- | Helper function to generate a spec. The spec runs on the given directory,+-- filtering by the given function. It then compares their output to the text of+-- the file with @.out@ as the new extension.+--+-- As an example, consider the directory structure+--+-- > test/data+-- > ├── file.hs+-- > └── file.out+--+-- If we have a function called @formatFile@ and we run+--+-- > testFiles "test/data" (hasExtension "hs") formatFile+--+-- This would read @test/data/file.hs@, format the file if it can, and compare+-- the output to the contents of @test/data/file.out@.+testFiles :: (Eq a, Show a)+ => FilePath -- ^ Base directory+ -> (F.FilePath -> Bool) -- ^ Filter on file extensions+ -> (String -> Either a String) -- ^ Function to process a file+ -> SpecWith ()+testFiles dir p f = runSafeT $ runEffect $ paths dir p >-> mapS (testFile f)++testFile :: (Eq a, Show a) => (String -> Either a String) -> String -> SpecWith ()+testFile fun f = it f $ do+ sample <- readFile f+ expected <- readFile (replaceExtension f ".out")+ fun sample `shouldBe` Right expected
+ stack.yaml view
@@ -0,0 +1,10 @@+---+resolver: lts-10.2+packages:+ - '.'+extra-deps:+ - dirstream-1.0.3+flags:+ hspec-dirstream:+ development: true+extra-package-dbs: []
+ test/Spec.hs view
@@ -0,0 +1,14 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE OverloadedStrings #-}++#if __GLASGOW_HASKELL__ <= 784+import Control.Applicative+#endif+import Test.Hspec+import Test.Hspec.Dirstream++main :: IO ()+main = hspec $+ describe "tail" $+ parallel $+ testFiles "test/data" (hasExtension "hs") ((pure :: a -> Either String a) . tail)
+ test/data/file.hs view
@@ -0,0 +1,1 @@+module FakeModule where
+ test/data/file.out view
@@ -0,0 +1,1 @@+odule FakeModule where