hspec-dirstream-1.0.0.2: Helper functions to simplify adding integration tests.

Safe HaskellNone
LanguageHaskell2010

Test.Hspec.Dirstream

Contents

Synopsis

Documentation

testFiles Source #

Arguments

:: (Eq a, Show a) 
=> FilePath

Base directory

-> (FilePath -> Bool)

Filter on file extensions

-> (String -> Either a String)

Function to process a file

-> SpecWith () 

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.

testFilesErr :: (Show b, Eq b) => FilePath -> PathFilter -> (String -> Either String b) -> SpecWith () Source #

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.

testFilesPure :: (Show b, Eq b) => FilePath -> PathFilter -> PathProducer -> FileProcessor a b -> SpecWith () Source #

A very general means of testing files, where the check function is pure.

Configuration helper functions

Helper functions for dealing with file extensions

extension :: FilePath -> Maybe Text #

Get a FilePath’s last extension, or Nothing if it has no extensions.

Types and type synonyms

data FileProcessor a b Source #

Constructors

FileProc 

Fields

  • reader :: FilePath -> IO a

    A function to read files

  • processor :: a -> b

    A function to process files after they have been read

  • check :: b -> Bool

    A predicate to check the output.

Orphan instances

MonadFail (SpecM a) Source # 
Instance details

Methods

fail :: String -> SpecM a a0 #

MonadIO (SpecM a) Source # 
Instance details

Methods

liftIO :: IO a0 -> SpecM a a0 #

MonadThrow (SpecM a) Source # 
Instance details

Methods

throwM :: Exception e => e -> SpecM a a0 #

MonadCatch (SpecM a) Source # 
Instance details

Methods

catch :: Exception e => SpecM a a0 -> (e -> SpecM a a0) -> SpecM a a0 #

MonadMask (SpecM a) Source # 
Instance details

Methods

mask :: ((forall a0. SpecM a a0 -> SpecM a a0) -> SpecM a b) -> SpecM a b #

uninterruptibleMask :: ((forall a0. SpecM a a0 -> SpecM a a0) -> SpecM a b) -> SpecM a b #

generalBracket :: SpecM a a0 -> (a0 -> ExitCase b -> SpecM a c) -> (a0 -> SpecM a b) -> SpecM a (b, c) #