Test
karkain test discovers and runs native test files. A test file is any
*_test.kark file whose func test_*() functions become individual test
cases.
Usage
$ karkain test [dir] [--filter <substring>]
dir— a directory (recursive*_test.karkdiscovery) or a single*_test.karkfile. Defaults to..--filter <substring>— run only tests whose identity contains the substring. Results stay deterministic.
Example math_test.kark:
func test_addition() {
assert(1 + 1 == 2)
}
func test_values() {
assert_eq(6, 2 * 3)
assert_ne(4, 5)
}
Assertions
The language provides three assertion builtins. Any failure aborts the test with a source location and fails the run:
assert(cond)— fail whencondis falseassert_eq(actual, expected)— fail when the values differ, printingexpectedandactualassert_ne(actual, expected)— fail when the values are equal
assertion failed: assert_eq: assert_eq(actual, expected) [file.kark:5]
expected: 5
actual: 4
std.testing module
The importable std.testing — Assertion and result helpers module layers higher-level helpers on the atomic assertions:
test_expect_true(cond)/test_expect_false(cond)test_expect_eq(actual, expected)/test_expect_ne(actual, expected)test_fail()— always fails (unreachable / not-yet-implemented marker)test_pass_count(results)/test_fail_count(results)— count truthy / falsy entries in an array of check resultstest_all_pass(results)— true when every check passedtest_summary(label, results)— builds a"label: N passed; M failed"string
Test runner output
Each test reports PASS or FAIL; the run ends with the summary line
N passed; M failed; S skipped; T total on both engines.
$ karkain test conformance/
PASS test_integer_arithmetic 1.2ms
PASS test_recursion_fib 1.5ms
PASS test_while_loop 0.8ms
=== Test Summary: 3 tests, 3 passed, 0 failed, 0 skipped ===
Exit codes
0— all tests passed4— one or more tests failed (ExitTest)3— a test failed to compile
Known limitation
The synthesized test driver does not yet support import statements
(Phase 96 boundary); stdlib modules are validated through karkain run
instead of karkain test.
See also
Profile — measure tests and programs. std.testing — Assertion and result helpers — the assertion/check helper module.