on master help sign in
Add an executable to manually test fs events
7ac5630Harendra Kumar
streamly.cabal+18
@@ -216,6 +216,13 @@ flag use-c-malloc
216
216
217common compile-options
217common compile-options
218 default-language: Haskell2010
218 default-language: Haskell2010
219+
220+ if os(darwin)
221+ cpp-options: -DCABAL_OS_DARWIN
222+
223+ if os(linux)
224+ cpp-options: -DCABAL_OS_LINUX
225+
219 if flag(streamk)
226 if flag(streamk)
220 cpp-options: -DUSE_STREAMK_ONLY
227 cpp-options: -DUSE_STREAMK_ONLY
221
228
@@ -840,6 +847,17 @@ test-suite version-bounds
840 , ghc
847 , ghc
841 , base >= 4.9 && < 5
848 , base >= 4.9 && < 5
842
849
850+executable FileSystem.Event
851+ import: test-options
852+ default-language: Haskell2010
853+ main-is: Streamly/Test/FileSystem/Event.hs
854+ hs-source-dirs: test
855+ build-depends:
856+ streamly
857+ , base >= 4.8 && < 5
858+ if os(windows)
859+ buildable: False
860+
843-------------------------------------------------------------------------------
861-------------------------------------------------------------------------------
844-- Examples
862-- Examples
845-------------------------------------------------------------------------------
863-------------------------------------------------------------------------------
test/Streamly/Test/FileSystem/Event.hsnew file+61
@@ -0,0 +1,61 @@
1+-- |
2+-- Module : Streamly.Test.FileSystem.Event
3+-- Copyright : (c) 2020 Composewell Technologies
4+--
5+-- License : BSD3
6+-- Maintainer : streamly@composewell.com
7+-- Stability : experimental
8+-- Portability : GHC
9+--
10+-- Just report all events under the paths provided as arguments
11+
12+module Main (main) where
13+
14+import Control.Monad.IO.Class (MonadIO)
15+import Data.Function ((&))
16+import Data.List.NonEmpty (NonEmpty)
17+import Data.Word (Word8)
18+import Streamly.Internal.Memory.Array (Array)
19+import System.Environment (getArgs)
20+import Streamly (SerialT)
21+
22+import qualified Data.List.NonEmpty as NonEmpty
23+import qualified Streamly.Data.Unicode.Stream as Unicode
24+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
25+#if defined(CABAL_OS_DARWIN)
26+import qualified Streamly.Internal.FileSystem.Event.Darwin as Event
27+#elif defined(CABAL_OS_LINUX)
28+import qualified Streamly.Internal.FileSystem.Event.Linux as Event
29+#else
30+#error "FS Events not supported on this platform
31+#endif
32+import qualified Streamly.Internal.Memory.Array as Array
33+
34+-------------------------------------------------------------------------------
35+-- Utilities
36+-------------------------------------------------------------------------------
37+
38+toUtf8 :: MonadIO m => String -> m (Array Word8)
39+toUtf8 = Array.fromStream . Unicode.encodeUtf8 . Stream.fromList
40+
41+-------------------------------------------------------------------------------
42+-- Main
43+-------------------------------------------------------------------------------
44+
45+watchPaths :: NonEmpty (Array Word8) -> SerialT IO Event.Event
46+
47+#if defined(CABAL_OS_DARWIN)
48+watchPaths = Event.watchTrees
49+#elif defined(CABAL_OS_LINUX)
50+watchPaths = Event.watchPaths
51+#else
52+#error "Unsupported platform
53+#endif
54+
55+main :: IO ()
56+main = do
57+ args <- getArgs
58+ paths <- mapM toUtf8 args
59+
60+ watchPaths (NonEmpty.fromList paths)
61+ & Stream.mapM_ (putStrLn . Event.showEvent)