commit 450d3820b22627dd9ffc4582d0f461c80055ef73
parent 771585546d5b9f593de90713f6a9d700e7dd5656
Author: Daniel Barlow <dan@telent.net>
Date: Sat, 20 Apr 2024 16:53:43 +0100
clean up uevent-watch test using writeFennel and mainFunction
requires less cavorting with globals and stuff
Diffstat:
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/pkgs/uevent-watch/default.nix b/pkgs/uevent-watch/default.nix
@@ -1,7 +1,7 @@
{
lua
, nellie
-, writeFennelScript
+, writeFennel
, runCommand
, anoia
, fennel
@@ -14,7 +14,10 @@ stdenv.mkDerivation {
nativeBuildInputs = [ fennelrepl ];
installPhase = ''
mkdir -p $out/bin
- cp -p ${writeFennelScript "uevent-watch" [fennel anoia nellie lua.pkgs.luafilesystem] ./watch.fnl} $out/bin/uevent-watch
+ cp -p ${writeFennel "uevent-watch" {
+ packages = [fennel anoia nellie lua.pkgs.luafilesystem];
+ mainFunction = "run";
+ } ./watch.fnl} $out/bin/uevent-watch
'';
checkPhase = ''
fennelrepl ./test.fnl
diff --git a/pkgs/uevent-watch/test.fnl b/pkgs/uevent-watch/test.fnl
@@ -1,7 +1,6 @@
(local { : view} (require :fennel))
(import-macros { : expect= } :anoia.assert)
-(set _G.arg (doto [] (tset 0 "test")))
(local subject (require :watch))
(let [params
@@ -35,7 +34,9 @@
;; this tests event parsing but not whether anything
;; happens as a result of processing them
-(subject.run
- ["-s" "foo" "-n" (os.getenv "TMPDIR") "partname=backup-disk" ]
+(subject.run-with-fh
{ :read (next-event) }
+ ["-s" "foo" "-n" (os.getenv "TMPDIR") "partname=backup-disk" ]
)
+
+(print "OK")
diff --git a/pkgs/uevent-watch/watch.fnl b/pkgs/uevent-watch/watch.fnl
@@ -47,7 +47,7 @@
"(%g-)=(%g+)")]
(k:lower) v))))
-(fn run [args fh]
+(fn run-with-fh [fh args]
(set up :unknown)
(let [parameters
(assert (parse-args args) (.. "can't parse args: " (table.concat args " ")))]
@@ -62,9 +62,9 @@
(set finished? (= e nil))
))))
-(when (not (= (. arg 0) "test"))
+(fn run [args]
(let [nellie (require :nellie)
netlink (nellie.open 4)]
- (run arg netlink)))
+ (run-with-fh netlink arg)))
-{ : run : event-matches? }
+{ : run : run-with-fh : event-matches? }