From f2a75d5223ba868a4f80a1dc13f31a5c155b0b08 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Sat, 13 Jun 2020 16:20:45 +0200 Subject: [PATCH] test: run all tests even if some fail --- cmd/tools/preludes/tests_assertions.v | 3 ++- vlib/builtin/builtin.v | 2 +- vlib/v/gen/cgen.v | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/tools/preludes/tests_assertions.v b/cmd/tools/preludes/tests_assertions.v index 3746f7f257..7b841a18fd 100644 --- a/cmd/tools/preludes/tests_assertions.v +++ b/cmd/tools/preludes/tests_assertions.v @@ -20,9 +20,10 @@ fn cb_assertion_failed(i &VAssertMetaInfo) { } final_filename := if use_relative_paths { i.fpath } else { os.real_path(i.fpath) } final_funcname := i.fn_name.replace('main__', '').replace('__', '.') + eprintln('') eprintln('$final_filename:${i.line_nr+1}: failed assert in ${final_funcname}') eprintln('Source : ${i.src}') - if i.op != 'call' { + if i.op.len > 0 && i.op != 'call' { eprintln(' left value: ${i.llabel} = ${i.lvalue}') eprintln(' right value: ${i.rlabel} = ${i.rvalue}') } diff --git a/vlib/builtin/builtin.v b/vlib/builtin/builtin.v index e146a1bcae..f445262bb1 100644 --- a/vlib/builtin/builtin.v +++ b/vlib/builtin/builtin.v @@ -237,7 +237,7 @@ pub: } fn __print_assert_failure(i &VAssertMetaInfo) { eprintln('${i.fpath}:${i.line_nr+1}: FAIL: fn ${i.fn_name}: assert ${i.src}') - if i.op != 'call' { + if i.op.len > 0 && i.op != 'call' { eprintln(' left value: ${i.llabel} = ${i.lvalue}') eprintln(' right value: ${i.rlabel} = ${i.rvalue}') } diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index e08e250317..16137677b1 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -942,7 +942,7 @@ fn (mut g Gen) gen_assert_stmt(a ast.AssertStmt) { g.writeln(' g_test_fails++;') metaname_fail := g.gen_assert_metainfo(a) g.writeln(' cb_assertion_failed(&${metaname_fail});') - g.writeln(' exit(1);') + g.writeln(' longjmp(g_jump_buffer, 1);') g.writeln(' // TODO') g.writeln(' // Maybe print all vars in a test function if it fails?') g.writeln('}') @@ -3605,8 +3605,10 @@ fn (g Gen) type_default(typ table.Type) string { } pub fn (mut g Gen) write_tests_main() { + g.includes.writeln('#include // write_tests_main') g.definitions.writeln('int g_test_oks = 0;') g.definitions.writeln('int g_test_fails = 0;') + g.definitions.writeln('jmp_buf g_jump_buffer;') $if windows { g.writeln('int wmain() {') } $else { @@ -3623,7 +3625,7 @@ pub fn (mut g Gen) write_tests_main() { if g.pref.is_stats { g.writeln('\tBenchedTests_testing_step_start(&bt, tos_lit("$t"));') } - g.writeln('\t${t}();') + g.writeln('\tif (!setjmp(g_jump_buffer)) ${t}();') if g.pref.is_stats { g.writeln('\tBenchedTests_testing_step_end(&bt);') }