Module: test.framework
Source: ./test/framework.reef
Overview
test/framework - Minimal test framework for Reef
Provides basic assertion functions and test result tracking using an Active Object for thread-safe mutable state.
Active Objects
TestRunner
TestRunner active object - holds mutable test state
Fields:
| Name | Type |
|---|---|
count |
int |
passed |
int |
failed |
int |
Methods:
exclusive fn tally(ok: bool, message: string): bool
Bookkeeping plus the FAIL header -- the part that was identical in all nine typed assertions, and the part whose copies drift. Returns true when the caller should print its operands, which is the only thing the typed wrappers do differently.
C4: this is a fn returning "did it fail" rather than a proc taking
pre-rendered operand strings, because assert_eq_float cannot render its
operands the same way. print_float emits C's "%f" (1.500000);
interpolation emits 1.5. That difference is pinned by
test_framework_new.expected, so the float assertion keeps its own
operand printing on purpose.
exclusive proc assert_eq_int(actual: int, expected: int, message: string)
Assert that two integers are equal
exclusive proc assert_eq_bool(actual: bool, expected: bool, message: string)
Assert that two booleans are equal
exclusive proc assert_eq_string(actual: string, expected: string, message: string)
Assert that two strings are equal
exclusive proc assert_eq_float(actual: float, expected: float, epsilon: float, message: string)
Assert that two floats are equal within epsilon tolerance.
Renders its own operands: see the note on tally.
exclusive proc assert_true(condition: bool, message: string)
Assert that a condition is true
exclusive proc assert_false(condition: bool, message: string)
Assert that a condition is false
exclusive proc assert_not_eq_int(actual: int, unexpected: int, message: string)
Assert that two integers are NOT equal
exclusive proc assert_not_eq_bool(actual: bool, unexpected: bool, message: string)
Assert that two booleans are NOT equal
exclusive proc assert_not_eq_string(actual: string, unexpected: string, message: string)
Assert that two strings are NOT equal
exclusive proc assert_contains_string(haystack: string, needle: string, message: string)
Assert that haystack contains needle (substring match).
NOTE: an empty needle always matches per core.str.contains semantics (the empty string is a substring of every string). If you're seeing unexpected passes from this assertion, check that your needle isn't accidentally empty. The framework prints a "WARN: empty needle" notice in that case so silently-vacuous assertions are visible in test output.
exclusive proc report()
Print test summary report
proc run()
Procedures
proc show_operands(label: string, expected_text: string, actual_text: string)
The two operand lines a failed assertion prints. Private: a module-level proc rather than a method because it touches no runner state, so it does not need to be inside the monitor.
Generated by reefc doc