v.gen.c: support `-d abort_on_assert` by injecting abort() calls

pull/9756/head
Delyan Angelov 2021-04-15 19:55:09 +03:00
parent d90be54850
commit f0c1e55637
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 6 additions and 0 deletions

View File

@ -33,6 +33,9 @@ fn (mut g Gen) gen_assert_stmt(original_assert_statement ast.AssertStmt) {
g.writeln('\tg_test_fails++;')
metaname_fail := g.gen_assert_metainfo(node)
g.writeln('\tmain__cb_assertion_failed(&$metaname_fail);')
if 'abort_on_assert' in g.pref.compile_defines_all {
g.writeln('\tabort();')
}
g.writeln('\tlongjmp(g_jump_buffer, 1);')
g.writeln('\t// TODO')
g.writeln('\t// Maybe print all vars in a test function if it fails?')
@ -45,6 +48,9 @@ fn (mut g Gen) gen_assert_stmt(original_assert_statement ast.AssertStmt) {
g.writeln(' {')
metaname_panic := g.gen_assert_metainfo(node)
g.writeln('\t__print_assert_failure(&$metaname_panic);')
if 'abort_on_assert' in g.pref.compile_defines_all {
g.writeln('\tabort();')
}
g.writeln('\tv_panic(_SLIT("Assertion failed..."));')
g.writeln('}')
}