diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 0497579cc7..27521b4dbd 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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 `?`', diff --git a/vlib/v/checker/tests/test_functions_should_not_return_test.out b/vlib/v/checker/tests/test_functions_should_not_return_test.out deleted file mode 100644 index 0972921368..0000000000 --- a/vlib/v/checker/tests/test_functions_should_not_return_test.out +++ /dev/null @@ -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 | } diff --git a/vlib/v/checker/tests/test_functions_wrong_signature_test.out b/vlib/v/checker/tests/test_functions_wrong_signature_test.out new file mode 100644 index 0000000000..e0f1404e86 --- /dev/null +++ b/vlib/v/checker/tests/test_functions_wrong_signature_test.out @@ -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 | } diff --git a/vlib/v/checker/tests/test_functions_should_not_return_test.vv b/vlib/v/checker/tests/test_functions_wrong_signature_test.vv similarity index 85% rename from vlib/v/checker/tests/test_functions_should_not_return_test.vv rename to vlib/v/checker/tests/test_functions_wrong_signature_test.vv index 3bebcea061..981cd0269e 100644 --- a/vlib/v/checker/tests/test_functions_should_not_return_test.vv +++ b/vlib/v/checker/tests/test_functions_wrong_signature_test.vv @@ -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) { +}