describe
macro supports tests inline in code
convert existing asserts to use it
This commit is contained in:
parent
8ed87c7d53
commit
ee4a8d28b6
3
Makefile
3
Makefile
@ -1,5 +1,8 @@
|
||||
doc/index.html: doc/index.md
|
||||
pandoc -t html -f gfm < $< > $@
|
||||
|
||||
check:
|
||||
sh test/run.sh
|
||||
|
||||
watch:
|
||||
find . -type f | entr -c -d sh test/run.sh
|
||||
|
@ -34,3 +34,5 @@
|
||||
(.. socketdir "/dunlin.sock")))
|
||||
|
||||
(Gtk.main)
|
||||
|
||||
;; NO-TESTING
|
||||
|
24
keymap.fnl
24
keymap.fnl
@ -1,7 +1,7 @@
|
||||
(local { : Gdk } (require :lgi))
|
||||
(local { : view } (require :fennel))
|
||||
(local lume (require :lume))
|
||||
(import-macros {: trace} :macros)
|
||||
(import-macros {: trace : describe : expect : expect=} :macros)
|
||||
|
||||
(local modifier-keyvals
|
||||
;; we need to detect and discard modifier-only key events when
|
||||
@ -73,11 +73,13 @@
|
||||
(table.insert chars (Gdk.keyval_name keyval))
|
||||
(table.concat chars "-")))
|
||||
|
||||
(let [v (index->string "103:0")] (assert (= v "g") v))
|
||||
(let [v (index->string "65:0")] (assert (= v "A") v))
|
||||
(let [v (index->string "120:4")] (assert (= v "C-x") v))
|
||||
(let [v (index->string "100:8")] (assert (= v "M-d") v))
|
||||
(let [v (index->string "100:12")] (assert (= v "C-M-d") v))
|
||||
(describe
|
||||
index->string
|
||||
(expect= (index->string "103:0") "g")
|
||||
(expect= (index->string "65:0") "A")
|
||||
(expect= (index->string "120:4") "C-x")
|
||||
(expect= (index->string "100:8") "M-d")
|
||||
(expect= (index->string "100:12") "C-M-d"))
|
||||
|
||||
(fn command? [tbl]
|
||||
;; a keymap entry has a string as key, a command
|
||||
@ -101,10 +103,12 @@
|
||||
[k1] (. tbl k1)
|
||||
x tbl)))
|
||||
|
||||
(let [v (ref {:a 1} [:a])] (assert (= v 1) v))
|
||||
(let [v (ref {:a {:c 7}} [:a :c])] (assert (= v 7) v))
|
||||
(let [v (ref {:a {:c 7}} [:a ])] (assert (match v {:c 7} true) (view v)))
|
||||
(let [v (ref {:a {:c 7}} [:z :d])] (assert (not v) v))
|
||||
(describe
|
||||
ref
|
||||
(let [v (ref {:a 1} [:a])] (expect= v 1))
|
||||
(let [v (ref {:a {:c 7}} [:a :c])] (expect= v 7))
|
||||
(let [v (ref {:a {:c 7}} [:a ])] (expect= v {:c 7}))
|
||||
(let [v (ref {:a {:c 7}} [:z :d])] (expect (not v))))
|
||||
|
||||
|
||||
(fn recogniser [source-keymap]
|
||||
|
24
macros.fnl
24
macros.fnl
@ -1,7 +1,27 @@
|
||||
|
||||
(fn trace [x]
|
||||
`(do
|
||||
(print :trace ,(view x) (view ,x))
|
||||
,x))
|
||||
|
||||
{ : trace }
|
||||
(fn expect [assertion]
|
||||
(let [msg (.. "expectation failed: " (view assertion))]
|
||||
`(when (not ,assertion)
|
||||
(assert false ,msg))))
|
||||
|
||||
(fn expect= [actual expected]
|
||||
`(let [view# (. (require :fennel) :view)
|
||||
ve# (view# ,expected)
|
||||
va# (view# ,actual)]
|
||||
(when (not (= ve# va#))
|
||||
(assert false
|
||||
(.. "\nexpected " ve# "\ngot " va#)
|
||||
))))
|
||||
|
||||
(fn describe [thing & body]
|
||||
(when _G.RUNNING_TESTS
|
||||
`(do (print "# " ,(view thing))
|
||||
,(unpack body))))
|
||||
|
||||
{ : trace : expect : expect= : describe }
|
||||
|
||||
;; NO-TESTING
|
||||
|
@ -2,3 +2,8 @@
|
||||
for i in test/*.fnl; do
|
||||
fennel --correlate $i && echo $i OK
|
||||
done
|
||||
for i in *.fnl; do
|
||||
grep -q NO-TESTING "$i" && continue
|
||||
[ "$i" = "macros.fnl" ] && continue
|
||||
fennel test/test-helper.fnl $i && echo $i OK
|
||||
done
|
||||
|
9
test/test-helper.fnl
Normal file
9
test/test-helper.fnl
Normal file
@ -0,0 +1,9 @@
|
||||
(local fennel (require :fennel))
|
||||
(local specials (require :fennel.specials))
|
||||
|
||||
(local compiler-env
|
||||
(doto (. (specials.make-compiler-env) :_G)
|
||||
(tset "RUNNING_TESTS" true)))
|
||||
|
||||
(each [_ f (ipairs arg)]
|
||||
(fennel.dofile f { :correlate true :compilerEnv compiler-env }))
|
Loading…
Reference in New Issue
Block a user