Add test for M_DEFER & M_LET_IF in exceptions

This commit is contained in:
Patrick Pelissier committed 2023-03-18 17:57:46 +01:00
1 parent e33894f1b3
commit 030bea9c11
1 file changed
+52
+52
View File
@@ -371,10 +371,62 @@ static void test2(void)
} }
} }
static void test3(void)
{
volatile int flow = 0;
volatile bool init = false;
flow = 0;
assert(flow ++ == 0);
M_TRY(test1) {
assert(flow ++ == 1);
M_DEFER( assert(flow++ == 3) ) {
assert(flow ++ == 2);
}
} M_CATCH(test1, M_ERROR_MEMORY) {
assert(0);
}
assert(flow ++ == 4);
flow = 0;
assert(flow ++ == 0);
M_TRY(test1) {
assert(flow ++ == 1);
init = true;
M_DEFER( init = false, assert(flow++ == 3) ) {
assert(init == true);
assert(flow ++ == 2);
M_THROW(1);
}
} M_CATCH(test1, 1) {
assert(init == false);
assert(flow ++ == 4);
}
assert(flow ++ == 5);
assert(init == false);
flow = 0;
assert(flow ++ == 0);
M_TRY(test1) {
assert(flow ++ == 1);
M_LET_IF(init = true, init == true, init = false) {
assert(init == true);
assert(flow ++ == 2);
M_THROW(1);
}
} M_CATCH(test1, 1) {
assert(init == false);
assert(flow ++ == 3);
}
assert(flow ++ == 4);
assert(init == false);
}
int main(void) int main(void)
{ {
test1(); test1();
test2(); test2();
test3();
testobj_final_check(); testobj_final_check();
exit(0); exit(0);
} }