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

compiler_test: handle panics

This commit is contained in:
Alexander Medvednikov 2020-04-25 09:05:14 +02:00
parent 1c46dabc84
commit 6248899d25
4 changed files with 46 additions and 6 deletions

View File

@ -602,12 +602,28 @@ fn (mut g Gen) assign_stmt(node ast.AssignStmt) {
// `a := 1` | `a,b := 1,2`
for i, ident in node.left {
match node.right[0] {
ast.IntegerLiteral { g.allocate_var(ident.name, 4, it.val.int()) }
else {}
ast.IntegerLiteral {
g.allocate_var(ident.name, 4, it.val.int())
}
ast.InfixExpr {
g.infix_expr(it)
g.allocate_var(ident.name, 4, 0)
}
else {
verror('assign_stmt unhandled expr')
}
}
}
}
fn (mut g Gen) infix_expr(node ast.InfixExpr) {
println('infix expr op=$node.op')
match node.op {
.plus {}
else {}
}
}
fn (mut g Gen) if_expr(node ast.IfExpr) {
branch := node.branches[0]
infix_expr := branch.cond as ast.InfixExpr

View File

@ -1,4 +1,4 @@
fn test() {
fn if_test() {
a := 1
if a == 1 {
println('a == 1')
@ -47,8 +47,25 @@ fn args() {
foo(2)
}
/*
fn expr() {
println('===expr===')
a := 1
b := 2
c := a + b
println('c==')
if c == 0 {
println('0')
}
if c == 3 {
println('3')
}
}
*/
fn main() {
test()
if_test()
loop()
args()
//expr()
}

View File

@ -37,6 +37,14 @@ fn test_all() {
}
expected = expected.trim_space().trim('\n').replace('\r\n', '\n')
found := res.output.trim_space().trim('\n').replace('\r\n', '\n')
if expected.contains('V panic:') {
// panic include backtraces, so can't do char by char comparison
panic_msg := expected.find_between('V panic:', '\n').trim_space()
if found.contains('V panic:') && found.contains(panic_msg) {
println(term.green('OK (panic)'))
continue
}
}
if expected != found {
println(term.red('FAIL'))
// println(x.output.limit(30))
@ -48,8 +56,7 @@ fn test_all() {
println(found)
println('============\n')
total_errors++
}
else {
} else {
println(term.green('OK'))
}
}