No matching definitions.

tur/test

stdlib/test.tur

lightweight unit test runner for Turmeric.

Since: Phase B1

defn

assert

(assert [expected actual] :)

assert that expected equals actual; print a failure message and return false if not.

expectedthe expected integer value
actualthe actual integer value to compare against expected

true if equal, false otherwise (with a failure message printed to stdout).

(assert 42 (my-fn))  ; => true when my-fn returns 42
defn

assert-true

(assert-true [x] :)

assert that x is truthy (1); print a failure message and return false if not.

xvalue to test; 1 = true, 0 = false (current int convention)

true if x == 1, false otherwise.

(assert-true (= 1 1))  ; => true
defn

assert-false

(assert-false [x] :)

assert that x is falsy (0); print a failure message and return false if not.

xvalue to test; 0 = false, non-zero = true

true if x == 0, false otherwise.

(assert-false (= 1 2))  ; => true
defn

assert-nil

(assert-nil [x] :)

assert that x represents nil (0); print a failure message and return false if not.

xvalue to test; 0 represents nil

true if x == 0, false otherwise.

(assert-nil (no-op))  ; => true when no-op returns 0
defn

assert-error-result-is-err?

(assert-error-result-is-err? [r : int])

assert that calling thunk raises a panic; return false if it does not.

thunkno-argument callback pointer; expected to panic when called

true if thunk raised a panic (caught via catch-unwind), false if it returned normally.

(assert-error (fn [] : int (panic "boom")))  ; => true
defn

assert-error

(assert-error [^fat thunk] :)
defn

run-test

(run-test [name : cstr ^fat test-fn] :)

invoke test-fn, print "." on pass or "F <name>" on fail, and return 1 or 0.

namehuman-readable test name printed on failure
test-fnno-argument callback that returns 1 on pass, 0 on fail

1 if the test passed, 0 if it failed.

(run-test "my test" (fn [] (assert 1 1)))  ; => 1
defn

register-test

(register-test [name : cstr test-fn ptr<void>] :)

register a named test callback with the runtime for later batch execution.

nametest name string
test-fnno-argument callback returning 1 on pass, 0 on fail.
Must carry no environment -- captures are forbidden. The
runtime stores test-fn as a bare C function pointer and
calls it directly; a captured value would be silently
dropped at the storage boundary. Pass a top-level defn,
or a (fn ...) literal with no free variables.

Non-zero on successful registration.

defn

run-tests!

(run-tests! :)

run all tests registered with register-test and return a process exit code.

0 if all tests passed, non-zero if any failed.

defmacro

deftest

(deftest [test-name & body])

register a named test whose body is one or more assertion expressions.

test-namestring name for the test
bodyone or more expressions; the test passes if none abort
(deftest "addition" (assert 4 (+ 2 2)))