diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 17447de8ce..e4d04b7ed0 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -210,6 +210,7 @@ mut: generated_free_methods map[int]bool autofree_scope_stmts []string use_segfault_handler bool = true + test_function_names []string } // global or const variable definition string @@ -368,6 +369,7 @@ pub fn gen(files []&ast.File, table &ast.Table, pref &pref.Preferences) string { global_g.pcs << g.pcs global_g.json_types << g.json_types global_g.hotcode_fn_names << g.hotcode_fn_names + global_g.test_function_names << g.test_function_names unsafe { g.free_builders() } for k, v in g.autofree_methods { global_g.autofree_methods[k] = v @@ -5538,24 +5540,21 @@ fn (mut g Gen) type_default(typ_ ast.Type) string { } } -fn (g &Gen) get_all_test_function_names() []string { +fn (g Gen) get_all_test_function_names() []string { mut tfuncs := []string{} mut tsuite_begin := '' mut tsuite_end := '' - for _, f in g.table.fns { - if !f.is_test { + for name in g.test_function_names { + if name.ends_with('.testsuite_begin') { + tsuite_begin = name continue } - if f.name.ends_with('.testsuite_begin') { - tsuite_begin = f.name + if name.contains('.test_') { + tfuncs << name continue } - if f.name.contains('.test_') { - tfuncs << f.name - continue - } - if f.name.ends_with('.testsuite_end') { - tsuite_end = f.name + if name.ends_with('.testsuite_end') { + tsuite_end = name continue } } diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 2f8c157262..f82b3e0259 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -32,6 +32,9 @@ fn (mut g Gen) fn_decl(node ast.FnDecl) { if node.should_be_skipped { return } + if node.is_test { + g.test_function_names << node.name + } if node.ninstances == 0 && node.generic_names.len > 0 { $if trace_generics ? { eprintln('skipping generic fn with no concrete instances: $node.mod $node.name') diff --git a/vlib/v/gen/c/testdata/comptime_if_attribute_in_test.vv b/vlib/v/gen/c/testdata/comptime_if_attribute_in_test.vv new file mode 100644 index 0000000000..5b2133eba5 --- /dev/null +++ b/vlib/v/gen/c/testdata/comptime_if_attribute_in_test.vv @@ -0,0 +1,4 @@ +[if customflag ?] +fn test_abcdef() { + println('this should not be in the c code') +} \ No newline at end of file diff --git a/vlib/v/gen/c/testdata/comptime_if_attribute_in_test2.c.must_have b/vlib/v/gen/c/testdata/comptime_if_attribute_in_test2.c.must_have new file mode 100644 index 0000000000..d216f3d536 --- /dev/null +++ b/vlib/v/gen/c/testdata/comptime_if_attribute_in_test2.c.must_have @@ -0,0 +1 @@ +println(_SLIT("this should be in the c code")); \ No newline at end of file diff --git a/vlib/v/gen/c/testdata/comptime_if_attribute_in_test2.vv b/vlib/v/gen/c/testdata/comptime_if_attribute_in_test2.vv new file mode 100644 index 0000000000..bae8e290d7 --- /dev/null +++ b/vlib/v/gen/c/testdata/comptime_if_attribute_in_test2.vv @@ -0,0 +1,5 @@ +// vtest vflags: -d customflag +[if customflag ?] +fn test_abcdef() { + println('this should be in the c code') +} \ No newline at end of file