checker: fix error messages and add checker tests

* checker: fix error messages
* tests: fix command and ignore defect output
pull/4329/head
Daniel Däschle 2020-04-10 10:59:07 +02:00 committed by GitHub
parent 74ac9ef195
commit 0f11d883fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 91 additions and 11 deletions

4
.gitignore vendored
View File

@ -84,3 +84,7 @@ cachegrind.out.*
/thirdparty/pg
exe
vlib/v/tests/inout/*.v
!vlib/v/tests/inout/*_test.v
vlib/v/checker/tests/inout/*.v
vlib/v/checker/tests/inout/*.c
!vlib/v/checker/tests/inout/*_test.v

View File

@ -56,6 +56,7 @@ pub:
val string
is_raw bool
is_c bool
pos token.Position
}
// 'name: $name'
@ -64,6 +65,7 @@ pub:
vals []string
exprs []Expr
expr_fmts []string
pos token.Position
mut:
expr_types []table.Type
}

View File

@ -1067,8 +1067,8 @@ fn expr_pos(node ast.Expr) token.Position {
// ast.ParExpr { }
ast.SelectorExpr { return it.pos }
// ast.SizeOf { }
// ast.StringLiteral { }
// ast.StringInterLiteral { }
ast.StringLiteral { return it.pos }
ast.StringInterLiteral { return it.pos }
ast.StructInit { return it.pos }
// ast.Type { }
// ast.TypeOf { }

View File

@ -0,0 +1,51 @@
import os
import term
fn test_all() {
$if windows {
return
}
mut total_errors := 0
vexe := os.getenv('VEXE')
vroot := os.dir(vexe)
dir := os.join_path(vroot,'vlib/v/checker/tests/inout')
files := os.ls(dir) or {
panic(err)
}
tests := files.filter(it.ends_with('.vv'))
if tests.len == 0 {
println('no compiler tests found')
assert false
}
for test in tests {
path := os.join_path(dir,test)
print(test + ' ')
program := path.replace('.vv', '.v')
os.cp(path, program) or {
panic(err)
}
res := os.exec('$vexe $program') or {
panic(err)
}
mut expected := os.read_file(program.replace('.v', '') + '.out') or {
panic(err)
}
expected = expected.trim_space().replace(' \n', '\n').replace(' \r\n', '\n').replace('\r\n', '\n').trim('\n')
found := res.output.trim_space().replace(' \n', '\n').replace(' \r\n', '\n').replace('\r\n', '\n').trim('\n')
if expected != found {
println(term.red('FAIL'))
println('============')
println('expected:')
println(expected)
println('============')
println('found:')
println(found)
println('============\n')
total_errors++
}
else {
println(term.green('OK'))
}
}
assert total_errors == 0
}

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/inout/enum_err.v:2:13: error: default value for enum has to be an integer
1| enum Color {
2| green = 'green',
~~~~~~~
3| blue,
4| }

View File

@ -0,0 +1,4 @@
enum Color {
green = 'green',
blue,
}

View File

@ -1226,6 +1226,7 @@ fn (p mut Parser) if_expr() ast.IfExpr {
}
fn (p mut Parser) string_expr() ast.Expr {
first_pos := p.tok.position()
is_raw := p.tok.kind == .name && p.tok.lit == 'r'
is_cstr := p.tok.kind == .name && p.tok.lit == 'c'
if is_raw || is_cstr {
@ -1233,13 +1234,20 @@ fn (p mut Parser) string_expr() ast.Expr {
}
mut node := ast.Expr{}
val := p.tok.lit
if p.peek_tok.kind != .str_dollar {
p.next()
last_pos := p.tok.position()
pos := token.Position{
line_nr: first_pos.line_nr
pos: first_pos.pos
len: last_pos.pos - first_pos.pos
}
node = ast.StringLiteral{
val: val
is_raw: is_raw
is_c: is_cstr
pos: pos
}
if p.peek_tok.kind != .str_dollar {
p.next()
return node
}
mut exprs := []ast.Expr
@ -1275,10 +1283,17 @@ fn (p mut Parser) string_expr() ast.Expr {
}
efmts << efmt.join('')
}
last_pos := p.tok.position()
pos := token.Position{
line_nr: first_pos.line_nr
pos: first_pos.pos
len: last_pos.pos - first_pos.pos
}
node = ast.StringInterLiteral{
vals: vals
exprs: exprs
expr_fmts: efmts
pos: pos
}
return node
}

View File

@ -95,10 +95,8 @@ pub fn formatted_error(kind string /*error or warn*/, emsg string, filepath stri
}
continue
}
for i in 0..pos.len {
underline := '~'.repeat(pos.len)
pointerline << if emanager.support_color { term.bold(term.blue(underline)) } else { underline }
}
break
}
clines << ' ' + pointerline.join('')