Fix tests

This commit is contained in:
Julian Ospald 2020-01-29 21:26:45 +01:00
parent 8ef8bda3ce
commit 45aca26340
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
2 changed files with 46 additions and 26 deletions

View File

@ -14,7 +14,7 @@ category: Streaming
build-type: Simple build-type: Simple
extra-source-files: CHANGELOG.md extra-source-files: CHANGELOG.md
library library streamly-filesystem
if os(windows) -- not supported yet if os(windows) -- not supported yet
build-depends: unbuildable<0 build-depends: unbuildable<0
buildable: False buildable: False

View File

@ -3,37 +3,57 @@
module Main where module Main where
import Data.ByteString (ByteString) import Data.ByteString ( ByteString )
import Data.Word (Word8) import Data.Word ( Word8 )
import GHC.IO.Handle (Handle) import GHC.IO.Handle ( Handle )
import Streamly import Streamly
import Streamly.FileSystem.Handle (readChunks) import Streamly.FileSystem.Handle ( readChunks )
import Streamly.Memory.Array (Array) import Streamly.Memory.Array ( Array )
import System.IO (openFile, IOMode(ReadMode)) import System.IO ( openFile
import System.IO.Temp (withSystemTempFile) , IOMode(ReadMode)
import Test.Hspec )
import Test.Hspec.QuickCheck import System.IO.Temp ( withSystemTempFile )
import Test.Hspec
import Test.Hspec.QuickCheck
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL import qualified Data.ByteString.Lazy as BSL
import Streamly.External.FileSystem.Handle.Posix import Streamly.External.FileSystem.Handle.Posix
import qualified Streamly.Prelude as S import qualified Streamly.Prelude as S
checkCopyLBS :: FilePath -> Handle -> IO () checkCopyLBS :: FilePath -> Handle -> IO ()
checkCopyLBS filename handle' = do checkCopyLBS filename handle' = do
let content = "Some file content" let content = "Some file content"
print $ "Checking " <> filename print $ "Checking " <> filename
handle <- openFile filename ReadMode copyLBS content handle'
copyLBS content handle handle <- openFile filename ReadMode
bsContent <- BS.hGetContents handle' bsContent <- BS.hGetContents handle
bsContent `shouldBe` content 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 :: IO ()
main = main = hspec $ do
hspec $ do describe "Streamly.External.FileSystem.Handle.Posix" $ do
describe "Streamly.External.FileSystem.Handle.Posix" $ do it "copyLBS" $ withSystemTempFile "x" checkCopyLBS
it "copyLBS" $ it "readFileLBS" $ withSystemTempFile "x" checkReadFileLBS
withSystemTempFile "x" checkCopyLBS it "copyFileHandle" $ withSystemTempFile
"x"
(\_ h1 -> withSystemTempFile "y" $ (\_ h2 -> checkCopyFileHandle h1 h2))