mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tests: support VTEST_ONLY_FN=*test_sincos* ./v test . and ./v test -run-only test_sin .
This commit is contained in:
@@ -190,7 +190,8 @@ pub fn (mut g Gen) gen_c_main_for_tests() {
|
||||
g.writeln('\tmain__vtest_init();')
|
||||
g.writeln('\t_vinit(___argc, (voidptr)___argv);')
|
||||
//
|
||||
all_tfuncs := g.get_all_test_function_names()
|
||||
mut all_tfuncs := g.get_all_test_function_names()
|
||||
all_tfuncs = g.filter_only_matching_fn_names(all_tfuncs)
|
||||
g.writeln('\tstring v_test_file = ${ctoslit(g.pref.path)};')
|
||||
if g.pref.is_stats {
|
||||
g.writeln('\tmain__BenchedTests bt = main__start_testing($all_tfuncs.len, v_test_file);')
|
||||
@@ -248,3 +249,28 @@ pub fn (mut g Gen) gen_c_main_for_tests() {
|
||||
println(g.out.after(main_fn_start_pos))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut g Gen) filter_only_matching_fn_names(fnames []string) []string {
|
||||
if g.pref.run_only.len == 0 {
|
||||
return fnames
|
||||
}
|
||||
mut res := []string{}
|
||||
for tname in fnames {
|
||||
if tname.contains('testsuite_') {
|
||||
res << tname
|
||||
continue
|
||||
}
|
||||
mut is_matching := false
|
||||
for fn_glob_pattern in g.pref.run_only {
|
||||
if tname.match_glob(fn_glob_pattern) {
|
||||
is_matching = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !is_matching {
|
||||
continue
|
||||
}
|
||||
res << tname
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -162,6 +162,8 @@ pub mut:
|
||||
out_name string
|
||||
path string // Path to file/folder to compile
|
||||
// -d vfmt and -d another=0 for `$if vfmt { will execute }` and `$if another ? { will NOT get here }`
|
||||
run_only []string // VTEST_ONLY_FN and -run-only accept comma separated glob patterns.
|
||||
// Only test_ functions that match these patterns will be run. -run-only is valid only for _test.v files.
|
||||
compile_defines []string // just ['vfmt']
|
||||
compile_defines_all []string // contains both: ['vfmt','another']
|
||||
run_args []string // `v run x.v 1 2 3` => `1 2 3`
|
||||
@@ -207,6 +209,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||
$if x64 {
|
||||
res.m64 = true // follow V model by default
|
||||
}
|
||||
res.run_only = os.getenv('VTEST_ONLY_FN').split_any(',')
|
||||
mut command := ''
|
||||
mut command_pos := 0
|
||||
// for i, arg in args {
|
||||
@@ -466,6 +469,10 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||
'-show-depgraph' {
|
||||
res.show_depgraph = true
|
||||
}
|
||||
'-run-only' {
|
||||
res.run_only = cmdline.option(current_args, arg, os.getenv('VTEST_ONLY_FN')).split_any(',')
|
||||
i++
|
||||
}
|
||||
'-test-runner' {
|
||||
res.test_runner = cmdline.option(current_args, arg, res.test_runner)
|
||||
i++
|
||||
|
||||
Reference in New Issue
Block a user