checker: report error for test functions that have parameters (#12500)
parent
3b612899bf
commit
26fbf1885d
|
@ -8298,7 +8298,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
|
|||
}
|
||||
}
|
||||
// TODO c.pref.is_vet
|
||||
if node.language == .v && !node.is_method && node.params.len == 0 && node.is_test {
|
||||
if node.language == .v && !node.is_method && node.is_test {
|
||||
if !c.pref.is_test {
|
||||
// simple heuristic
|
||||
for st in node.stmts {
|
||||
|
@ -8309,6 +8309,10 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if node.params.len != 0 {
|
||||
c.error('test functions should take 0 parameters', node.pos)
|
||||
}
|
||||
if node.return_type != ast.void_type_idx
|
||||
&& node.return_type.clear_flag(.optional) != ast.void_type_idx {
|
||||
c.error('test functions should either return nothing at all, or be marked to return `?`',
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
vlib/v/checker/tests/test_functions_should_not_return_test.vv:9:1: error: test functions should either return nothing at all, or be marked to return `?`
|
||||
7 |
|
||||
8 | // should be disallowed:
|
||||
9 | fn test_returning_int() int {
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
10 |
|
||||
11 | }
|
|
@ -0,0 +1,13 @@
|
|||
vlib/v/checker/tests/test_functions_wrong_signature_test.vv:9:1: error: test functions should either return nothing at all, or be marked to return `?`
|
||||
7 |
|
||||
8 | // should be disallowed:
|
||||
9 | fn test_returning_int() int {
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
10 | }
|
||||
11 |
|
||||
vlib/v/checker/tests/test_functions_wrong_signature_test.vv:19:1: error: test functions should take 0 parameters
|
||||
17 |
|
||||
18 | // should be disallowed:
|
||||
19 | fn test_take_parameters(v int) {
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
20 | }
|
|
@ -7,7 +7,6 @@ fn abc() int {
|
|||
|
||||
// should be disallowed:
|
||||
fn test_returning_int() int {
|
||||
|
||||
}
|
||||
|
||||
// NB: this is allowed explicitly now, to allow for shorter tests
|
||||
|
@ -15,3 +14,7 @@ fn test_returning_int() int {
|
|||
fn test_returning_opt() ? {
|
||||
assert true
|
||||
}
|
||||
|
||||
// should be disallowed:
|
||||
fn test_take_parameters(v int) {
|
||||
}
|
Loading…
Reference in New Issue