Make expected error in test::@error macro optional

If not supplied with a fault, `test::@error` checks if a fault of any
type/value was returned
This commit is contained in:
m0tholith
2025-11-04 17:26:34 +03:00
committed by Christoffer Lerno
parent 07363c6ecd
commit 7063e684ba
2 changed files with 36 additions and 2 deletions

View File

@@ -303,6 +303,34 @@ fn void test_error_not_raised()
test::@error(ffail_int(1, 1), io::FILE_NOT_FOUND);
}
fn void test_error_nofault()
{
TestFailFn ffail_void = fn void?(bool to_fail)
{
if (to_fail) return io::FILE_NOT_FOUND?;
};
TestIntFn ffail_int = fn int?(int a, int b)
{
if (b == 0) return io::FILE_NOT_FOUND?;
return a / b;
};
test::@setup(state.setup_fn, state.teardown_fn);
test::@error(ffail_void(true));
test::@error(ffail_int(1, 0));
}
fn void test_error_nofault_not_raised()
{
TestIntFn ffail_int = fn int?(int a, int b) {
if (b == 0) return io::FILE_NOT_FOUND?;
return a / b;
};
test::@setup(state.setup_fn, state.teardown_fn);
state.expected_fail = true;
test::@error(ffail_int(1, 1));
}
fn void test_error_wrong_error_expected()
{
TestIntFn ffail_int = fn int?(int a, int b) {