test.fnl (872B)
1 (local watch (require :watch)) 2 3 ;; Events come from the devout socket as an initial summary line 4 ;; followed by a NUL character followed by newline-separated key=value 5 ;; pairs. For ease of editing we don't have NULs in events.txt, 6 ;; so we need to massage it into shape here 7 8 (local events 9 (with-open [f (io.open "./events.txt" :r)] 10 (let [text (string.gsub (f:read "*a") "\n\n" "\0") ] 11 (icollect [n (string.gmatch text "([^\0]+)")] 12 (string.gsub n "\n" "\0" 1))))) 13 14 15 (fn next-event [] 16 (var i 0) 17 (fn [] 18 (let [i_ (+ 1 i) 19 e (. events i_)] 20 (set i i_) 21 e))) 22 23 ;; this tests event parsing but not whether anything 24 ;; happens as a result of processing them 25 (watch.run-with-fh 26 { 27 :read (next-event) 28 :write (fn [payload] ) 29 } 30 ["-s" "foo" "-n" (os.getenv "TMPDIR") "partname=backup-disk" ] 31 ) 32 33 (print "OK")