tur/test
assert
(assert [expected actual] :bool)
assert that expected equals actual; print a failure message and return false if not.
| expected | the expected integer value | |
| actual | the 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
assert-true
(assert-true [x] :bool)
assert that x is truthy (1); print a failure message and return false if not.
| x | value to test; 1 = true, 0 = false (current int convention) |
true if x == 1, false otherwise. (assert-true (= 1 1)) ; => true
assert-false
(assert-false [x] :bool)
assert that x is falsy (0); print a failure message and return false if not.
| x | value to test; 0 = false, non-zero = true |
true if x == 0, false otherwise. (assert-false (= 1 2)) ; => true
assert-nil
(assert-nil [x] :bool)
assert that x represents nil (0); print a failure message and return false if not.
| x | value to test; 0 represents nil |
true if x == 0, false otherwise. (assert-nil (no-op)) ; => true when no-op returns 0
assert-error
(assert-error [thunk :ptr<void>] :bool)
assert that calling thunk raises an error; return false if it does not.
| thunk | no-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
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.
| name | human-readable test name printed on failure | |
| test-fn | no-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
register-test
(register-test [name :cstr test-fn :ptr<void>] :int)
register a named test callback with the runtime for later batch execution.
| name | test name string | |
| test-fn | no-argument callback returning 1 on pass, 0 on fail |
Non-zero on successful registration.
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.
deftest
(deftest [test-name & body])
register a named test whose body is one or more assertion expressions.
| test-name | string name for the test | |
| body | one or more expressions; the test passes if none abort |
(deftest "addition" (assert 4 (+ 2 2)))