From d30896b4d6643954ad4152966280ccf900766ddf Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Wed, 29 Jan 2020 21:02:45 +0100 Subject: [PATCH] Add test --- streamly-filesystem.cabal | 22 ++++++++++++++++++++++ test/Main.hs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 test/Main.hs diff --git a/streamly-filesystem.cabal b/streamly-filesystem.cabal index 51e1b06..f3688b9 100644 --- a/streamly-filesystem.cabal +++ b/streamly-filesystem.cabal @@ -33,6 +33,28 @@ library default-language: Haskell2010 GHC-Options: -Wall -O2 -fspec-constr-recursive=16 -fmax-worker-args=16 +test-suite sf-test + if os(windows) -- not supported yet + build-depends: unbuildable<0 + buildable: False + type: exitcode-stdio-1.0 + main-is: Main.hs + hs-source-dirs: test + build-depends: base >= 4.12 && < 5 + , bytestring + , hpath-directory >= 0.13 + , hspec + , hspec-discover + , safe-exceptions >= 0.1 + , streamly >= 0.7 + , streamly-bytestring >= 0.1.0.1 + , streamly-filesystem + , temporary + , unix >= 2.7 + , word8 >= 0.1.3 + default-language: Haskell2010 + GHC-Options: -Wall -threaded -rtsopts -with-rtsopts=-N + source-repository head type: git location: https://github.com/hasufell/streamly-filesystem diff --git a/test/Main.hs b/test/Main.hs new file mode 100644 index 0000000..ce8e370 --- /dev/null +++ b/test/Main.hs @@ -0,0 +1,39 @@ +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE OverloadedStrings #-} + +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 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 + + +main :: IO () +main = + hspec $ do + describe "Streamly.External.FileSystem.Handle.Posix" $ do + it "copyLBS" $ + withSystemTempFile "x" checkCopyLBS + +