compiler_test: handle panics
parent
1c46dabc84
commit
6248899d25
|
@ -602,9 +602,25 @@ 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 {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
|
@ -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'))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue