diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index e1e679e3e8..fff400da8c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -527,6 +527,9 @@ pub fn (c mut Checker) array_init(array_init mut ast.ArrayInit) table.Type { fn (c mut Checker) stmt(node ast.Stmt) { // c.expected_type = table.void_type match mut node { + ast.AssertStmt { + c.expr(it.expr) + } ast.AssignStmt { c.assign_stmt(mut it) c.expected_type = table.void_type diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index dd6d4930db..1cb9f7267c 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -268,12 +268,21 @@ fn (g mut Gen) stmt(node ast.Stmt) { // println('cgen.stmt()') // g.writeln('//// stmt start') match node { - ast.AssignStmt { - g.gen_assign_stmt(it) - } ast.AssertStmt { g.writeln('// assert') - // TODO + g.write('if (!(') + g.expr(it.expr) + g.writeln(')) {') + g.writeln('g_test_fails++;') + g.writeln('puts("FAILED assertion");') + g.writeln('puts("function: $g.fn_decl.name");') + g.writeln('} else {') + g.writeln('g_test_oks++;') + g.writeln('puts("OK $g.fn_decl.name");') + g.writeln('}') + } + ast.AssignStmt { + g.gen_assign_stmt(it) } ast.Attr { g.writeln('//[$it.name]') diff --git a/vlib/v/gen/cheaders.v b/vlib/v/gen/cheaders.v index 94deb93e4b..34961516a0 100644 --- a/vlib/v/gen/cheaders.v +++ b/vlib/v/gen/cheaders.v @@ -186,6 +186,8 @@ extern wchar_t **_wenviron; //================================== GLOBALS =================================*/ byte g_str_buf[1024]; +int g_test_fails = 0; +int g_test_oks = 0; int load_so(byteptr); void reload_so(); void _vinit();