File tree Expand file tree Collapse file tree 8 files changed +36
-13
lines changed
tests/run_project_folders/issue_13443_test_prefixed_fns_in_normal_v_files Expand file tree Collapse file tree 8 files changed +36
-13
lines changed Original file line number Diff line number Diff line change 460
460
is_noreturn bool // true, when [noreturn] is used on a fn
461
461
is_manualfree bool // true, when [manualfree] is used on a fn
462
462
is_main bool // true for `fn main()`
463
- is_test bool // true for `fn test_abcde`
463
+ is_test bool // true for `fn test_abcde() {}`, false for `fn test_abc(x int) {}`, or for fns that do not start with test_
464
464
is_conditional bool // true for `[if abc] fn abc(){}`
465
465
is_exported bool // true for `[export: 'exact_C_name']`
466
466
is_keep_alive bool // passed memory must not be freed (by GC) before function returns
Original file line number Diff line number Diff line change @@ -270,7 +270,8 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
270
270
}
271
271
}
272
272
// TODO c.pref.is_vet
273
- if node.language == .v && ! node.is_method && node.is_test {
273
+ if c.file.is_test && (! node.is_method && (node.short_name.starts_with ('test_' )
274
+ || node.short_name.starts_with ('testsuite_' ))) {
274
275
if ! c.pref.is_test {
275
276
// simple heuristic
276
277
for st in node.stmts {
@@ -285,6 +286,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
285
286
if node.params.len != 0 {
286
287
c.error ('test functions should take 0 parameters' , node.pos)
287
288
}
289
+
288
290
if node.return_type != ast.void_type_idx
289
291
&& node.return_type.clear_flag (.optional) != ast.void_type_idx {
290
292
c.error ('test functions should either return nothing at all, or be marked to return `?`' ,
Original file line number Diff line number Diff line change @@ -6304,6 +6304,9 @@ fn (g &Gen) get_all_test_function_names() []string {
6304
6304
mut tsuite_begin := ''
6305
6305
mut tsuite_end := ''
6306
6306
for _, f in g.table.fns {
6307
+ if ! f.is_test {
6308
+ continue
6309
+ }
6307
6310
if f.name.ends_with ('.testsuite_begin' ) {
6308
6311
tsuite_begin = f.name
6309
6312
continue
Original file line number Diff line number Diff line change @@ -383,6 +383,9 @@ fn (g &JsGen) get_all_test_function_names() []string {
383
383
mut tsuite_begin := ''
384
384
mut tsuite_end := ''
385
385
for _, f in g.table.fns {
386
+ if ! f.is_test {
387
+ continue
388
+ }
386
389
if f.name.ends_with ('.testsuite_begin' ) {
387
390
tsuite_begin = f.name
388
391
continue
Original file line number Diff line number Diff line change @@ -361,10 +361,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
361
361
end_pos := p.prev_tok.pos ()
362
362
short_fn_name := name
363
363
is_main := short_fn_name == 'main' && p.mod == 'main'
364
- mut is_test := (short_fn_name.starts_with ('test_' ) || short_fn_name.starts_with ('testsuite_' ))
365
- && (p.file_base.ends_with ('_test.v' )
366
- || p.file_base.all_before_last ('.v' ).all_before_last ('.' ).ends_with ('_test' ))
367
-
364
+ is_test := (! is_method && params.len == 0 ) && p.inside_test_file
365
+ && (short_fn_name.starts_with ('test_' ) || short_fn_name.starts_with ('testsuite_' ))
368
366
file_mode := p.file_backend_mode
369
367
// Register
370
368
if is_method {
Original file line number Diff line number Diff line change @@ -162,19 +162,18 @@ pub fn (mut p Parser) set_path(path string) {
162
162
p.file_name = path
163
163
p.file_base = os.base (path)
164
164
p.file_name_dir = os.dir (path)
165
- if p.file_name_dir.contains ('vlib' ) {
166
- p.inside_vlib_file = true
167
- }
165
+ p.inside_vlib_file = p.file_name_dir.contains ('vlib' )
166
+ p.inside_test_file = p.file_base.ends_with ('_test.v' ) || p.file_base.ends_with ('_test.vv' )
167
+ || p.file_base.all_before_last ('.v' ).all_before_last ('.' ).ends_with ('_test' )
168
+
168
169
hash := fnv1 a.sum64_string (path)
169
170
p.unique_prefix = hash.hex_full ()
170
- if p.file_base.ends_with ('_test.v' ) || p.file_base.ends_with ('_test.vv' ) {
171
- p.inside_test_file = true
172
- }
171
+
172
+ p.file_backend_mode = .v
173
173
before_dot_v := path.all_before_last ('.v' ) // also works for .vv and .vsh
174
174
language := before_dot_v.all_after_last ('.' )
175
175
language_with_underscore := before_dot_v.all_after_last ('_' )
176
176
if language == before_dot_v && language_with_underscore == before_dot_v {
177
- p.file_backend_mode = .v
178
177
return
179
178
}
180
179
actual_language := if language == before_dot_v { language_with_underscore } else { language }
Original file line number Diff line number Diff line change
1
+ module main
2
+
3
+ fn test_any_name () {
4
+ println (@FN)
5
+ }
Original file line number Diff line number Diff line change
1
+ fn main () {
2
+ println (@FN)
3
+ println ('OK' )
4
+ }
5
+
6
+ fn test_fn_in_normal_v_file () {
7
+ println (@FN)
8
+ }
9
+
10
+ fn test_any (any_name int ) int {
11
+ println (@FN)
12
+ return 0
13
+ }
You can’t perform that action at this time.
0 commit comments