53 lines
1.0 KiB
V
53 lines
1.0 KiB
V
import (
|
|
os
|
|
filepath
|
|
v.parser
|
|
v.ast
|
|
v.gen
|
|
v.table
|
|
term
|
|
)
|
|
|
|
const (
|
|
nr_tests = 2
|
|
)
|
|
|
|
fn test_c_files() {
|
|
println('Running V => C tests')
|
|
vexe := os.getenv('VEXE')
|
|
vroot := filepath.dir(vexe)
|
|
for i in 1 .. nr_tests + 1 {
|
|
path := '$vroot/vlib/v/gen/tests/${i}.vv'
|
|
ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or {
|
|
panic(err)
|
|
}
|
|
table := &table.Table{}
|
|
program := parser.parse_file(path, table)
|
|
res := gen.cgen([program])
|
|
if compare_texts(res, ctext) {
|
|
eprintln('${i}... ' + term.green('OK'))
|
|
}
|
|
else {
|
|
eprintln('${i}... ' + term.red('FAIL'))
|
|
eprintln('expected:\n$ctext\ngot:\n$res')
|
|
}
|
|
}
|
|
}
|
|
|
|
fn compare_texts(a, b string) bool {
|
|
lines_a := a.trim_space().split_into_lines()
|
|
lines_b := b.trim_space().split_into_lines()
|
|
if lines_a.len != lines_b.len {
|
|
println(term.red('different len'))
|
|
// return false
|
|
}
|
|
for i, line_a in lines_a {
|
|
line_b := lines_b[i]
|
|
if line_a.trim_space() != line_b.trim_space() {
|
|
println(term.red('!' + line_a))
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|