tasty-golden 2.2.1.2 → 2.2.2
raw patch · 4 files changed
+104/−3 lines, 4 filesdep +containersdep +directorydep +tasty-goldenPVP ok
version bump matches the API change (PVP)
Dependencies added: containers, directory, tasty-golden, tasty-hunit
API changes (from Hackage documentation)
+ Test.Tasty.Golden: findByExtension :: [FilePath] -> FilePath -> IO [FilePath]
Files
- CHANGELOG.md +5/−0
- Test/Tasty/Golden.hs +44/−0
- tasty-golden.cabal +26/−3
- tests/test.hs +29/−0
CHANGELOG.md view
@@ -1,6 +1,11 @@ Changes ======= +Version 2.2.2+-------------++Add `findByExtension`+ Version 2.2.1.2 ---------------
Test/Tasty/Golden.hs view
@@ -48,6 +48,7 @@ , goldenVsFileDiff , goldenVsStringDiff , writeBinaryFile+ , findByExtension ) where @@ -60,9 +61,11 @@ import System.Process import System.Exit import System.FilePath+import System.Directory import Control.Exception import Control.Monad import Control.DeepSeq+import qualified Data.Set as Set -- trick to avoid an explicit dependency on transformers import Control.Monad.Error (liftIO)@@ -191,3 +194,44 @@ -- | Like 'writeFile', but uses binary mode writeBinaryFile :: FilePath -> String -> IO () writeBinaryFile f txt = withBinaryFile f WriteMode (\hdl -> hPutStr hdl txt)++-- | Find all files in the given directory and its subdirectories that have+-- the given extensions.+--+-- It is typically used to find all test files and produce a golden test+-- per test file.+--+-- The returned paths use forward slashes to separate path components,+-- even on Windows. Thus if the file name ends up in a golden file, it+-- will not differ when run on another platform.+--+-- The semantics of extensions is the same as in 'takeExtension'. In+-- particular, non-empty extensions should have the form @".ext"@.+--+-- This function may throw any exception that 'getDirectoryContents' may+-- throw.+--+-- It doesn't do anything special to handle symlinks (in particular, it+-- probably won't work on symlink loops).+--+-- Nor is it optimized to work with huge directory trees (you'd probably+-- want to use some form of coroutines for that).+findByExtension+ :: [FilePath] -- ^ extensions+ -> FilePath -- ^ directory+ -> IO [FilePath] -- ^ paths+findByExtension extsList = go where+ exts = Set.fromList extsList+ go dir = do+ allEntries <- getDirectoryContents dir+ let entries = filter (not . (`elem` [".", ".."])) allEntries+ liftM concat $ forM entries $ \e -> do+ let path = dir ++ "/" ++ e+ isDir <- doesDirectoryExist path+ if isDir+ then go path+ else+ return $+ if takeExtension path `Set.member` exts+ then [path]+ else []
tasty-golden.cabal view
@@ -1,5 +1,5 @@ name: tasty-golden-version: 2.2.1.2+version: 2.2.2 synopsis: Golden tests support for tasty description: This package provides support for «golden testing».@@ -17,7 +17,7 @@ -- copyright: category: Testing build-type: Simple-cabal-version: >=1.8+cabal-version: >=1.16 extra-source-files: CHANGELOG.md Source-repository head@@ -25,6 +25,8 @@ location: git://github.com/feuerbach/tasty-golden.git library+ Default-language:+ Haskell2010 exposed-modules: Test.Tasty.Golden Test.Tasty.Golden.Advanced Test.Tasty.Golden.Manage@@ -43,4 +45,25 @@ filepath, temporary-rc, tagged,- deepseq+ deepseq,+ containers,+ directory++Test-suite test+ Default-language:+ Haskell2010+ Type:+ exitcode-stdio-1.0+ Hs-source-dirs:+ tests+ Main-is:+ test.hs+ Build-depends:+ base >= 4 && < 5+ , tasty >= 0.8+ , tasty-hunit+ , tasty-golden+ , filepath+ , directory+ , process+ , temporary-rc
+ tests/test.hs view
@@ -0,0 +1,29 @@+import Test.Tasty+import Test.Tasty.HUnit+import Test.Tasty.Golden+import System.IO.Temp+import System.FilePath+import System.Directory+import Data.List (sort)++touch f = writeFile f ""++main = defaultMain $+ testCase "findByExtension" $+ withSystemTempDirectory "golden-test" $ \basedir -> do++ setCurrentDirectory basedir++ createDirectory ("d1")+ createDirectory ("d1" </> "d2")+ touch ("f1.c")+ touch ("f2.h")+ touch ("f2.exe")+ touch ("d1" </> "g1.c")+ touch ("d1" </> "d2" </> "h1.c")+ touch ("d1" </> "d2" </> "h1.exe")+ touch ("d1" </> "d2" </> "h1")++ files <- findByExtension [".c", ".h"] "."+ sort files @?= sort+ ["./d1/d2/h1.c","./d1/g1.c","./f1.c","./f2.h"]