1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
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

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('}')
}