From 45aca26340e9b028bc6854b3d334909f015869d1 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Wed, 29 Jan 2020 21:26:45 +0100 Subject: [PATCH] Fix tests --- streamly-filesystem.cabal | 2 +- test/Main.hs | 70 +++++++++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/streamly-filesystem.cabal b/streamly-filesystem.cabal index f3688b9..eba01a8 100644 --- a/streamly-filesystem.cabal +++ b/streamly-filesystem.cabal @@ -14,7 +14,7 @@ category: Streaming build-type: Simple extra-source-files: CHANGELOG.md -library +library streamly-filesystem if os(windows) -- not supported yet build-depends: unbuildable<0 buildable: False diff --git a/test/Main.hs b/test/Main.hs index ce8e370..2ceceed 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -3,37 +3,57 @@ module Main where -import Data.ByteString (ByteString) -import Data.Word (Word8) -import GHC.IO.Handle (Handle) -import Streamly -import Streamly.FileSystem.Handle (readChunks) -import Streamly.Memory.Array (Array) -import System.IO (openFile, IOMode(ReadMode)) -import System.IO.Temp (withSystemTempFile) -import Test.Hspec -import Test.Hspec.QuickCheck +import Data.ByteString ( ByteString ) +import Data.Word ( Word8 ) +import GHC.IO.Handle ( Handle ) +import Streamly +import Streamly.FileSystem.Handle ( readChunks ) +import Streamly.Memory.Array ( Array ) +import System.IO ( openFile + , IOMode(ReadMode) + ) +import System.IO.Temp ( withSystemTempFile ) +import Test.Hspec +import Test.Hspec.QuickCheck -import qualified Data.ByteString as BS -import qualified Data.ByteString.Lazy as BSL -import Streamly.External.FileSystem.Handle.Posix -import qualified Streamly.Prelude as S +import qualified Data.ByteString as BS +import qualified Data.ByteString.Lazy as BSL +import Streamly.External.FileSystem.Handle.Posix +import qualified Streamly.Prelude as S checkCopyLBS :: FilePath -> Handle -> IO () checkCopyLBS filename handle' = do let content = "Some file content" print $ "Checking " <> filename - handle <- openFile filename ReadMode - copyLBS content handle - bsContent <- BS.hGetContents handle' - bsContent `shouldBe` content + copyLBS content handle' + handle <- openFile filename ReadMode + bsContent <- BS.hGetContents handle + bsContent `shouldBe` (BSL.toStrict content) + +checkReadFileLBS :: FilePath -> Handle -> IO () +checkReadFileLBS filename handle' = do + let content = "Some file content" + print $ "Checking " <> filename + copyLBS content handle' + handle <- openFile filename ReadMode + bsContent <- readFileLBS handle + (BSL.toStrict bsContent) `shouldBe` (BSL.toStrict content) + +checkCopyFileHandle :: Handle -> Handle -> IO () +checkCopyFileHandle from to = do + let content = "Some file content" + copyLBS' content from + copyFileHandle' from to + fromContent <- readFileLBS from + toContent <- readFileLBS to + (BSL.toStrict fromContent) `shouldBe` (BSL.toStrict toContent) main :: IO () -main = - hspec $ do - describe "Streamly.External.FileSystem.Handle.Posix" $ do - it "copyLBS" $ - withSystemTempFile "x" checkCopyLBS - - +main = hspec $ do + describe "Streamly.External.FileSystem.Handle.Posix" $ do + it "copyLBS" $ withSystemTempFile "x" checkCopyLBS + it "readFileLBS" $ withSystemTempFile "x" checkReadFileLBS + it "copyFileHandle" $ withSystemTempFile + "x" + (\_ h1 -> withSystemTempFile "y" $ (\_ h2 -> checkCopyFileHandle h1 h2))