From 450d3820b22627dd9ffc4582d0f461c80055ef73 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 20 Apr 2024 16:53:43 +0100 Subject: [PATCH] clean up uevent-watch test using writeFennel and mainFunction requires less cavorting with globals and stuff --- pkgs/uevent-watch/default.nix | 7 +++++-- pkgs/uevent-watch/test.fnl | 7 ++++--- pkgs/uevent-watch/watch.fnl | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pkgs/uevent-watch/default.nix b/pkgs/uevent-watch/default.nix index 304d258..07a7888 100644 --- 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 index 38f122b..5c431a3 100644 --- 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 index b1297ed..1988596 100644 --- 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? }