import expect= where previously it was copy-pasted

This commit is contained in:
Daniel Barlow 2024-04-20 15:09:50 +01:00
parent 73abf952d5
commit 771585546d
3 changed files with 8 additions and 29 deletions

View file

@ -1,7 +1,8 @@
(local subject (require :acquire-wan-address)) (local subject (require :acquire-wan-address))
(local { : view } (require :fennel)) (import-macros { : expect= } :anoia.assert)
(local { : merge : dup } (require :anoia)) (local { : merge : dup } (require :anoia))
;; nix-shell --run "cd modules/dhcp6c && fennelrepl acquire-wan-address-test.fnl"
(local a1 (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 [] (fn first-address []
(let [deleted (let [deleted
(subject.deletions (subject.deletions

View file

@ -1,16 +1,12 @@
(local { : view &as fennel } (require :fennel)) (local { : view &as fennel } (require :fennel))
(local anoia (require :anoia)) (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))) (var fake-system (fn [s] (print "executing " s)))
(tset anoia :system #(fake-system $1)) (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] (fn event-generator [events]
(coroutine.wrap (coroutine.wrap
@ -117,3 +113,5 @@
(set upsies []) (set upsies [])
(ifwait.run ["-s" "addmember" "dummy0" "up"] #gen) (ifwait.run ["-s" "addmember" "dummy0" "up"] #gen)
(expect= upsies [:u :u :u :u])) (expect= upsies [:u :u :u :u]))
(print "OK")

View file

@ -1,16 +1,9 @@
(local { : view} (require :fennel)) (local { : view} (require :fennel))
(import-macros { : expect= } :anoia.assert)
(set _G.arg (doto [] (tset 0 "test"))) (set _G.arg (doto [] (tset 0 "test")))
(local subject (require :watch)) (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 (let [params
{:matches {:devname "foo" :partname "my-usbstick"}}] {:matches {:devname "foo" :partname "my-usbstick"}}]
(expect= (subject.event-matches? params {}) false) (expect= (subject.event-matches? params {}) false)