compiler_test: handle panics
parent
1c46dabc84
commit
6248899d25
|
@ -602,12 +602,28 @@ fn (mut g Gen) assign_stmt(node ast.AssignStmt) {
|
||||||
// `a := 1` | `a,b := 1,2`
|
// `a := 1` | `a,b := 1,2`
|
||||||
for i, ident in node.left {
|
for i, ident in node.left {
|
||||||
match node.right[0] {
|
match node.right[0] {
|
||||||
ast.IntegerLiteral { g.allocate_var(ident.name, 4, it.val.int()) }
|
ast.IntegerLiteral {
|
||||||
else {}
|
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) {
|
fn (mut g Gen) if_expr(node ast.IfExpr) {
|
||||||
branch := node.branches[0]
|
branch := node.branches[0]
|
||||||
infix_expr := branch.cond as ast.InfixExpr
|
infix_expr := branch.cond as ast.InfixExpr
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
fn test() {
|
fn if_test() {
|
||||||
a := 1
|
a := 1
|
||||||
if a == 1 {
|
if a == 1 {
|
||||||
println('a == 1')
|
println('a == 1')
|
||||||
|
@ -47,8 +47,25 @@ fn args() {
|
||||||
foo(2)
|
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() {
|
fn main() {
|
||||||
test()
|
if_test()
|
||||||
loop()
|
loop()
|
||||||
args()
|
args()
|
||||||
|
//expr()
|
||||||
}
|
}
|
|
@ -37,6 +37,14 @@ fn test_all() {
|
||||||
}
|
}
|
||||||
expected = expected.trim_space().trim('\n').replace('\r\n', '\n')
|
expected = expected.trim_space().trim('\n').replace('\r\n', '\n')
|
||||||
found := res.output.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 {
|
if expected != found {
|
||||||
println(term.red('FAIL'))
|
println(term.red('FAIL'))
|
||||||
// println(x.output.limit(30))
|
// println(x.output.limit(30))
|
||||||
|
@ -48,8 +56,7 @@ fn test_all() {
|
||||||
println(found)
|
println(found)
|
||||||
println('============\n')
|
println('============\n')
|
||||||
total_errors++
|
total_errors++
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
println(term.green('OK'))
|
println(term.green('OK'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue