Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 8, 2025
1 parent b42f8e7 commit 5d5fc8f
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cmd/tools/vvet/analyze.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import v.token
import arrays

// cutoffs
const indexexpr_cutoff = 5
const infixexpr_cutoff = 5
const indexexpr_cutoff = 10
const infixexpr_cutoff = 10
const selectorexpr_cutoff = 10
const callexpr_cutoff = 10
const stringinterliteral_cutoff = 10
const stringliteral_cutoff = 10
const ascast_cutoff = 10
const stringconcat_cutoff = 5
const stringconcat_cutoff = 10

// minimum size for string literals
const stringliteral_min_size = 20
Expand Down
1 change: 1 addition & 0 deletions cmd/tools/vvet/tests/empty_fn_decl.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmd/tools/vvet/tests/empty_fn_decl.vv:2: notice: Empty function.
3 changes: 3 additions & 0 deletions cmd/tools/vvet/tests/empty_fn_decl.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// vtest vflags: -F
fn foo() {
}
11 changes: 11 additions & 0 deletions cmd/tools/vvet/tests/repeated_assign.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmd/tools/vvet/tests/repeated_assign.vv:4: notice: a += 'foo' occurs 1/11 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_assign.vv:5: notice: a += 'foo' occurs 2/11 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_assign.vv:6: notice: a += 'foo' occurs 3/11 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_assign.vv:7: notice: a += 'foo' occurs 4/11 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_assign.vv:8: notice: a += 'foo' occurs 5/11 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_assign.vv:9: notice: a += 'foo' occurs 6/11 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_assign.vv:10: notice: a += 'foo' occurs 7/11 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_assign.vv:11: notice: a += 'foo' occurs 8/11 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_assign.vv:12: notice: a += 'foo' occurs 9/11 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_assign.vv:13: notice: a += 'foo' occurs 10/11 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_assign.vv:14: notice: a += 'foo' occurs 11/11 times in function scope (main.main).
15 changes: 15 additions & 0 deletions cmd/tools/vvet/tests/repeated_assign.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// vtest vflags: -r
fn main() {
mut a := ''
a += 'foo'
a += 'foo'
a += 'foo'
a += 'foo'
a += 'foo'
a += 'foo'
a += 'foo'
a += 'foo'
a += 'foo'
a += 'foo'
a += 'foo'
}
12 changes: 12 additions & 0 deletions cmd/tools/vvet/tests/repeated_code.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmd/tools/vvet/tests/repeated_code.vv:4: notice: a[0] occurs 1/12 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_code.vv:5: notice: a[0] occurs 2/12 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_code.vv:6: notice: a[0] occurs 3/12 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_code.vv:6: notice: a[0] occurs 4/12 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_code.vv:7: notice: a[0] occurs 5/12 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_code.vv:8: notice: a[0] occurs 6/12 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_code.vv:9: notice: a[0] occurs 7/12 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_code.vv:9: notice: a[0] occurs 8/12 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_code.vv:11: notice: a[0] occurs 9/12 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_code.vv:12: notice: a[0] occurs 10/12 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_code.vv:13: notice: a[0] occurs 11/12 times in function scope (main.main).
cmd/tools/vvet/tests/repeated_code.vv:13: notice: a[0] occurs 12/12 times in function scope (main.main).
16 changes: 16 additions & 0 deletions cmd/tools/vvet/tests/repeated_code.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// vtest vflags: -r
fn main() {
mut a := [0, 2, 4, 6]
if a[0] {
dump(a[0])
dump(a[0] + a[0])
if a[0] {
dump(a[0])
dump(a[0] + a[0])
}
if a[0] {
dump(a[0])
dump(a[0] + a[0])
}
}
}
19 changes: 18 additions & 1 deletion cmd/tools/vvet/vet_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ import term
import v.util.vtest
import v.util.diff

struct FileOptions {
mut:
vflags string
}

fn get_file_options(file string) FileOptions {
mut res := FileOptions{}
lines := os.read_lines(file) or { [] }
for line in lines {
if line.starts_with('// vtest vflags:') {
res.vflags = line.all_after(':').trim_space()
}
}
return res
}

fn test_vet() {
vexe := os.getenv('VEXE')
vroot := os.dir(vexe)
Expand All @@ -26,7 +42,8 @@ fn check_path(vexe string, dir string, tests []string) int {
for path in paths {
program := path
print(path + ' ')
res := os.execute('${os.quoted_path(vexe)} vet -nocolor ${os.quoted_path(program)}')
file_options := get_file_options(path)
res := os.execute('${os.quoted_path(vexe)} vet -nocolor ${file_options.vflags} ${os.quoted_path(program)}')
if res.exit_code < 0 {
panic(res.output)
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/tools/vvet/vvet.v
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ fn (mut vt Vet) expr(expr ast.Expr) {
vt.expr(expr.update_expr)
vt.exprs(expr.init_fields.map(it.expr))
}
ast.DumpExpr {
vt.expr(expr.expr)
}
else {}
}
}
Expand Down

0 comments on commit 5d5fc8f

Please sign in to comment.