cgen: minor cleanup of gen_assert_stmt() (#8018)

pull/8030/head
yuyi 2021-01-11 16:05:15 +08:00 committed by GitHub
parent cc17f145c5
commit 72317975fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 13 deletions

View File

@ -1464,11 +1464,11 @@ fn (mut g Gen) gen_assert_stmt(original_assert_statement ast.AssertStmt) {
} }
} }
g.inside_ternary++ g.inside_ternary++
if g.is_test {
g.write('if (') g.write('if (')
g.expr(a.expr) g.expr(a.expr)
g.write(')') g.write(')')
g.decrement_inside_ternary() g.decrement_inside_ternary()
if g.is_test {
g.writeln(' {') g.writeln(' {')
g.writeln('\tg_test_oks++;') g.writeln('\tg_test_oks++;')
metaname_ok := g.gen_assert_metainfo(a) metaname_ok := g.gen_assert_metainfo(a)
@ -1481,15 +1481,19 @@ fn (mut g Gen) gen_assert_stmt(original_assert_statement ast.AssertStmt) {
g.writeln('\t// TODO') g.writeln('\t// TODO')
g.writeln('\t// Maybe print all vars in a test function if it fails?') g.writeln('\t// Maybe print all vars in a test function if it fails?')
g.writeln('}') g.writeln('}')
return } else {
} g.write('if (!(')
g.writeln(' {} else {') g.expr(a.expr)
g.write('))')
g.decrement_inside_ternary()
g.writeln(' {')
metaname_panic := g.gen_assert_metainfo(a) metaname_panic := g.gen_assert_metainfo(a)
g.writeln('\t__print_assert_failure(&$metaname_panic);') g.writeln('\t__print_assert_failure(&$metaname_panic);')
g.writeln('\tv_panic(_SLIT("Assertion failed..."));') g.writeln('\tv_panic(_SLIT("Assertion failed..."));')
g.writeln('\texit(1);') g.writeln('\texit(1);')
g.writeln('}') g.writeln('}')
} }
}
fn cnewlines(s string) string { fn cnewlines(s string) string {
return s.replace('\n', r'\n') return s.replace('\n', r'\n')