diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-11-12 19:25:57 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-11-12 19:25:57 +0300 |
| commit | a1851986383148593ca85675d3dafd1e8517481a (patch) | |
| tree | a99dbf637b2f5fb6f1465695eee71a9d008fd80e /tests/test.fnl | |
| parent | 32f268f51538bd4c26d9da337e01d3df39ea2f2e (diff) | |
fix(CI): overhaul
Diffstat (limited to 'tests/test.fnl')
| -rw-r--r-- | tests/test.fnl | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test.fnl b/tests/test.fnl new file mode 100644 index 0000000..f678b6b --- /dev/null +++ b/tests/test.fnl @@ -0,0 +1,62 @@ +(local test {}) + +(fn eq-fn [] + `(fn eq# [a# b#] + (if (and (= (type a#) :table) (= (type b#) :table)) + (do (var [res# count-a# count-b#] [true 0 0]) + (each [k# v# (pairs a#)] + (set res# (eq# v# (. b# k#))) + (set count-a# (+ count-a# 1)) + (when (not res#) (lua :break))) + (when res# + (each [_# _# (pairs b#)] + (set count-b# (+ count-b# 1))) + (set res# (= count-a# count-b#))) + res#) + (= a# b#)))) + +(fn test.assert-eq + [expr1 expr2 msg] + `(let [left# ,expr1 + right# ,expr2 + (res# view#) (pcall require :fennelview) + eq# ,(eq-fn) + tostr# (if res# view# tostring)] + (assert (eq# left# right#) + (or ,msg (.. "equality assertion failed + Left: " (tostr# left#) " + Right: " (tostr# right#) "\n"))))) + +(fn test.assert-ne + [expr1 expr2 msg] + `(let [left# ,expr1 + right# ,expr2 + (res# view#) (pcall require :fennelview) + eq# ,(eq-fn) + tostr# (if res# view# tostring)] + (assert (not (eq# left# right#)) + (or ,msg (.. "unequality assertion failed + Left: " (tostr# left#) " + Right: " (tostr# right#) "\n"))))) + +(fn test.assert* + [expr msg] + `(assert ,expr (.. "assertion failed for " + (or ,msg ,(tostring expr))))) +(fn test.assert-not + [expr msg] + `(assert (not ,expr) (.. "assertion failed for " + (or ,msg ,(tostring expr))))) + +(fn test.deftest + [name ...] + "Simple way of grouping tests" + `(do ,...)) + +(fn test.testing + [description ...] + "Print test description and run it." + `(do (io.stderr:write (.. "testing: " ,description "\n")) + ,...)) + +test |