aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/world/file/watch.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test/lux/world/file/watch.lux')
-rw-r--r--stdlib/source/test/lux/world/file/watch.lux131
1 files changed, 78 insertions, 53 deletions
diff --git a/stdlib/source/test/lux/world/file/watch.lux b/stdlib/source/test/lux/world/file/watch.lux
index 9c1b31811..57511136e 100644
--- a/stdlib/source/test/lux/world/file/watch.lux
+++ b/stdlib/source/test/lux/world/file/watch.lux
@@ -5,12 +5,12 @@
[predicate (#+ Predicate)]
[monad (#+ do)]]
[control
- ["." try]
+ ["." try (#+ Try)]
["." exception]
[concurrency
- ["." promise]]]
+ ["." promise (#+ Promise)]]]
[data
- ["." binary ("#\." equivalence)]
+ ["." binary (#+ Binary) ("#\." equivalence)]
["." text ("#\." equivalence)
["%" format (#+ format)]]
[collection
@@ -18,10 +18,11 @@
[math
["." random (#+ Random) ("#\." monad)]]]
{1
- ["." /]}
+ ["." /
+ ["/#" //]]}
[////
[data
- ["_." binary]]])
+ ["$." binary]]])
(def: concern
(Random [/.Concern (Predicate /.Concern)])
@@ -87,6 +88,66 @@
false)))))
)))
+(def: (no_events_prior_to_creation! fs watcher directory)
+ (-> (//.System Promise) (/.Watcher Promise) //.Path (Promise (Try Bit)))
+ (do {! (try.with promise.monad)}
+ [_ (\ fs make_directory directory)
+ _ (\ watcher start /.all directory)]
+ (|> (\ watcher poll [])
+ (\ ! map list.empty?))))
+
+(def: (after_creation! fs watcher expected_path)
+ (-> (//.System Promise) (/.Watcher Promise) //.Path (Promise (Try Bit)))
+ (do (try.with promise.monad)
+ [_ (: (Promise (Try Any))
+ (//.make_file promise.monad fs (binary.create 0) expected_path))
+ poll/pre (\ watcher poll [])
+ poll/post (\ watcher poll [])]
+ (wrap (and (case poll/pre
+ (^ (list [concern actual_path]))
+ (and (text\= expected_path actual_path)
+ (and (/.creation? concern)
+ (not (/.modification? concern))
+ (not (/.deletion? concern))))
+
+ _
+ false)
+ (list.empty? poll/post)))))
+
+(def: (after_modification! fs watcher data expected_path)
+ (-> (//.System Promise) (/.Watcher Promise) Binary //.Path (Promise (Try Bit)))
+ (do (try.with promise.monad)
+ [_ (promise.delay 1 (#try.Success "Delay to make sure the over_write time-stamp always changes."))
+ _ (\ fs write data expected_path)
+ poll/2 (\ watcher poll [])
+ poll/2' (\ watcher poll [])]
+ (wrap (and (case poll/2
+ (^ (list [concern actual_path]))
+ (and (text\= expected_path actual_path)
+ (and (not (/.creation? concern))
+ (/.modification? concern)
+ (not (/.deletion? concern))))
+
+ _
+ false)
+ (list.empty? poll/2')))))
+
+(def: (after_deletion! fs watcher expected_path)
+ (-> (//.System Promise) (/.Watcher Promise) //.Path (Promise (Try Bit)))
+ (do (try.with promise.monad)
+ [_ (\ fs delete expected_path)
+ poll/3 (\ watcher poll [])
+ poll/3' (\ watcher poll [])]
+ (wrap (and (case poll/3
+ (^ (list [concern actual_path]))
+ (and (not (/.creation? concern))
+ (not (/.modification? concern))
+ (/.deletion? concern))
+
+ _
+ false)
+ (list.empty? poll/3')))))
+
(def: #export test
Test
(<| (_.covering /._)
@@ -101,56 +162,20 @@
[fs watcher] (/.mock /)]
expected_path (\ ! map (|>> (format directory /))
(random.ascii/alpha 5))
- data (_binary.random 10)]
+ data ($binary.random 10)]
(wrap (do {! promise.monad}
[verdict (do (try.with !)
- [_ (\ fs create_directory directory)
- _ (\ watcher start /.all directory)
- poll/0 (\ watcher poll [])
- #let [no_events_prior_to_creation!
- (list.empty? poll/0)]
- file (\ fs create_file expected_path)
- poll/1 (\ watcher poll [])
- poll/1' (\ watcher poll [])
- #let [after_creation!
- (and (case poll/1
- (^ (list [actual_path concern]))
- (and (text\= expected_path actual_path)
- (and (/.creation? concern)
- (not (/.modification? concern))
- (not (/.deletion? concern))))
-
- _
- false)
- (list.empty? poll/1'))]
- _ (promise.delay 1 (#try.Success "Delay to make sure the over_write time-stamp always changes."))
- _ (\ file over_write data)
- poll/2 (\ watcher poll [])
- poll/2' (\ watcher poll [])
- #let [after_modification!
- (and (case poll/2
- (^ (list [actual_path concern]))
- (and (text\= expected_path actual_path)
- (and (not (/.creation? concern))
- (/.modification? concern)
- (not (/.deletion? concern))))
-
- _
- false)
- (list.empty? poll/2'))]
- _ (\ file delete [])
- poll/3 (\ watcher poll [])
- poll/3' (\ watcher poll [])
- #let [after_deletion!
- (and (case poll/3
- (^ (list [actual_path concern]))
- (and (not (/.creation? concern))
- (not (/.modification? concern))
- (/.deletion? concern))
-
- _
- false)
- (list.empty? poll/3'))]]
+ [no_events_prior_to_creation!
+ (..no_events_prior_to_creation! fs watcher directory)
+
+ after_creation!
+ (..after_creation! fs watcher expected_path)
+
+ after_modification!
+ (..after_modification! fs watcher data expected_path)
+
+ after_deletion!
+ (..after_deletion! fs watcher expected_path)]
(wrap (and no_events_prior_to_creation!
after_creation!
after_modification!