tur/test

stdlib/test.tur
defn

assert

(assert [expected actual] :bool)

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] :bool)

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] :bool)

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] :bool)

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

(assert-error [thunk :ptr<void>] :bool)

assert that calling thunk raises an error; return false if it does not.

thunkno-argument callback pointer; expected to throw when called
true if thunk raised an error, false if it returned normally.

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

run-test

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

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>] :int)

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

Non-zero on successful registration.

defn

run-tests!

(run-tests! :int)

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)))