From 771585546d5b9f593de90713f6a9d700e7dd5656 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 20 Apr 2024 15:09:50 +0100 Subject: [PATCH] import expect= where previously it was copy-pasted --- modules/dhcp6c/acquire-wan-address-test.fnl | 16 ++-------------- pkgs/ifwait/test-ifwait.fnl | 12 +++++------- pkgs/uevent-watch/test.fnl | 9 +-------- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/modules/dhcp6c/acquire-wan-address-test.fnl b/modules/dhcp6c/acquire-wan-address-test.fnl index c71b67b..f735f4a 100644 --- a/modules/dhcp6c/acquire-wan-address-test.fnl +++ b/modules/dhcp6c/acquire-wan-address-test.fnl @@ -1,7 +1,8 @@ (local subject (require :acquire-wan-address)) -(local { : view } (require :fennel)) +(import-macros { : expect= } :anoia.assert) (local { : merge : dup } (require :anoia)) +;; nix-shell --run "cd modules/dhcp6c && fennelrepl acquire-wan-address-test.fnl" (local a1 { @@ -47,19 +48,6 @@ } ) -(macro expect [assertion] - (let [msg (.. "expectation failed: " (view assertion))] - `(when (not ,assertion) - (assert false ,msg)))) - -(macro expect= [actual expected] - `(let [ve# (view ,expected) - va# (view ,actual)] - (when (not (= ve# va#)) - (assert false - (.. "\nexpected " ve# "\ngot " va#) - )))) - (fn first-address [] (let [deleted (subject.deletions diff --git a/pkgs/ifwait/test-ifwait.fnl b/pkgs/ifwait/test-ifwait.fnl index 3381b5a..90e26bc 100644 --- a/pkgs/ifwait/test-ifwait.fnl +++ b/pkgs/ifwait/test-ifwait.fnl @@ -1,16 +1,12 @@ (local { : view &as fennel } (require :fennel)) (local anoia (require :anoia)) +(import-macros { : expect= } :anoia.assert) + +;; nix-shell --run "cd pkgs/ifwait && fennelrepl test-ifwait.fnl" (var fake-system (fn [s] (print "executing " s))) (tset anoia :system #(fake-system $1)) -(macro expect= [actual expected] - `(let [ve# (view ,expected) - va# (view ,actual)] - (when (not (= ve# va#)) - (assert false - (.. "\nexpected " ve# "\ngot " va#) - )))) (fn event-generator [events] (coroutine.wrap @@ -117,3 +113,5 @@ (set upsies []) (ifwait.run ["-s" "addmember" "dummy0" "up"] #gen) (expect= upsies [:u :u :u :u])) + +(print "OK") diff --git a/pkgs/uevent-watch/test.fnl b/pkgs/uevent-watch/test.fnl index 1c8fb7b..38f122b 100644 --- a/pkgs/uevent-watch/test.fnl +++ b/pkgs/uevent-watch/test.fnl @@ -1,16 +1,9 @@ (local { : view} (require :fennel)) +(import-macros { : expect= } :anoia.assert) (set _G.arg (doto [] (tset 0 "test"))) (local subject (require :watch)) -(macro expect= [actual expected] - `(let [ve# (view ,expected) - va# (view ,actual)] - (when (not (= ve# va#)) - (assert false - (.. "\nexpected " ve# "\ngot " va#) - )))) - (let [params {:matches {:devname "foo" :partname "my-usbstick"}}] (expect= (subject.event-matches? params {}) false)