From 0787807a7f8374587be83decda31ab1bc8cb203f Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 5 Mar 2024 17:56:59 +0000 Subject: [PATCH] ifwait: don't run on load if in test harness --- pkgs/ifwait/ifwait.fnl | 21 +++++++++++++-------- pkgs/ifwait/test-ifwait.fnl | 6 ++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pkgs/ifwait/ifwait.fnl b/pkgs/ifwait/ifwait.fnl index fae01a9..9d6dd9a 100644 --- a/pkgs/ifwait/ifwait.fnl +++ b/pkgs/ifwait/ifwait.fnl @@ -33,12 +33,17 @@ (when (. got params.expecting) (os.exit 0)))) -(let [parameters - (assert (parse-args arg) - (.. "Usage: " (. arg 0) " [-v] ifname [present|up|running]"))] - (when parameters.verbose - (print (.. (. arg 0) ": waiting for " - parameters.link " to be " parameters.expecting))) +(fn run [] + (let [parameters + (assert (parse-args arg) + (.. "Usage: " (. arg 0) " [-v] ifname [present|up|running]"))] + (when parameters.verbose + (print (.. (. arg 0) ": waiting for " + parameters.link " to be " parameters.expecting))) - (each [event (nl.events {:link true})] - (run-event parameters event))) + (each [event (nl.events {:link true})] + (run-event parameters event)))) + +(when (not (= (. arg 0) "test")) (run)) + +{ : run } diff --git a/pkgs/ifwait/test-ifwait.fnl b/pkgs/ifwait/test-ifwait.fnl index 8ac7547..731a2fe 100644 --- a/pkgs/ifwait/test-ifwait.fnl +++ b/pkgs/ifwait/test-ifwait.fnl @@ -11,6 +11,8 @@ (tset package.loaded :anoia.nl { :events events }) -(set _G.arg (doto ["-v" "dummy0" "up"] (tset 0 "ifwait"))) +(set _G.arg (doto ["-v" "dummy0" "up"] (tset 0 "test"))) -(fennel.dofile "ifwait.fnl" { :correlate true }) +(local ifwait (require :ifwait)) + +(ifwait.run)