checker: warn if fn looks like a test fn but filename doesn't end in `_test.v` (#6469)

pull/6482/head
Nick Treleaven 2020-09-25 17:26:11 +01:00 committed by GitHub
parent ffee3791e8
commit fbae0a7274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -3919,6 +3919,18 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
c.error('.str() methods should have 0 arguments', node.pos)
}
}
// TODO c.pref.is_vet
if node.language == .v && !node.is_method && node.args.len == 0 && node.return_type == table.void_type_idx &&
node.name.after('.').starts_with('test_') && !c.file.path.ends_with('_test.v') {
// simple heuristic
for st in node.stmts {
if st is ast.AssertStmt {
c.warn('tests will not be run because filename does not end with `_test.v`',
node.pos)
break
}
}
}
c.expected_type = table.void_type
c.cur_fn = node
// Add return if `fn(...) ? {...}` have no return at end