on master help sign in
Add an executable to manually test fs events
commit7ac5630b54470d84e02fbdc99d8b875f14fcebff authorHarendra Kumar <harendra@composewell.com> dateThu 20 Aug 2020, 21:13 (6 years ago) parent6f94a21
2 files changed+79
streamly.cabal+18 test/Streamly/Test/FileSystem/Event.hs+61
streamly.cabal+18
@@ -216,6 +216,13 @@ flag use-c-malloc
216216
217217common compile-options
218218 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+
219226 if flag(streamk)
220227 cpp-options: -DUSE_STREAMK_ONLY
221228
@@ -840,6 +847,17 @@ test-suite version-bounds
840847 , ghc
841848 , base >= 4.9 && < 5
842849
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+
843861-------------------------------------------------------------------------------
844862-- Examples
845863-------------------------------------------------------------------------------
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)