diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index f9eae90eff..2c7c497b55 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -6,6 +6,7 @@ import term import benchmark import sync import v.pref +import v.util.vtest pub struct TestMessageHandler { mut: @@ -69,7 +70,6 @@ pub fn (mut ts TestSession) test() { // ts.init() mut remaining_files := []string{} - vtest_only := os.getenv('VTEST_ONLY').split(',') for dot_relative_file in ts.files { relative_file := dot_relative_file.replace('./', '') file := os.real_path(relative_file) @@ -93,20 +93,9 @@ pub fn (mut ts TestSession) test() { continue } } - if vtest_only.len > 0 { - mut found := 0 - for substring in vtest_only { - if file.contains(substring) { - found++ - break - } - } - if found == 0 { - continue - } - } remaining_files << dot_relative_file } + remaining_files = vtest.filter_vtest_only(remaining_files, fix_slashes: false) ts.files = remaining_files ts.benchmark.set_total_expected_steps(remaining_files.len) mut pool_of_test_runners := sync.new_pool_processor({ diff --git a/vlib/v/compiler_errors_test.v b/vlib/v/compiler_errors_test.v index 9dce236026..1baf458676 100644 --- a/vlib/v/compiler_errors_test.v +++ b/vlib/v/compiler_errors_test.v @@ -1,6 +1,7 @@ import os import term import v.util +import v.util.vtest fn test_all() { mut total_errors := 0 @@ -35,25 +36,10 @@ fn get_tests_in_dir(dir string) []string { } fn check_path(vexe, dir, voptions, result_extension string, tests []string) int { - vtest_only := os.getenv('VTEST_ONLY').split(',') mut nb_fail := 0 - mut paths := []string{} - for test in tests { - path := os.join_path(dir, test).replace('\\', '/') - if vtest_only.len > 0 { - mut found := 0 - for substring in vtest_only { - if path.contains(substring) { - found++ - break - } - } - if found == 0 { - continue - } - } - paths << path - } + paths := vtest.filter_vtest_only(tests, { + basepath: dir + }) for path in paths { program := path.replace('.vv', '.v') print(path + ' ') diff --git a/vlib/v/tests/inout/compiler_test.v b/vlib/v/tests/inout/compiler_test.v index f47401cc70..706363545e 100644 --- a/vlib/v/tests/inout/compiler_test.v +++ b/vlib/v/tests/inout/compiler_test.v @@ -1,6 +1,7 @@ import os import term import v.util +import v.util.vtest fn test_all() { mut total_errors := 0 @@ -18,24 +19,9 @@ fn test_all() { println('no compiler tests found') assert false } - vtest_only := os.getenv('VTEST_ONLY').split(',') - mut paths := []string{} - for test in tests { - path := os.join_path(dir, test).replace('\\', '/') - if vtest_only.len > 0 { - mut found := 0 - for substring in vtest_only { - if path.contains(substring) { - found++ - break - } - } - if found == 0 { - continue - } - } - paths << path - } + paths := vtest.filter_vtest_only(tests, { + basepath: dir + }) for path in paths { print(path + ' ') program := path.replace('.vv', '.v') diff --git a/vlib/v/tests/valgrind/valgrind_test.v b/vlib/v/tests/valgrind/valgrind_test.v index ad8aa89a03..e9454e3c8c 100644 --- a/vlib/v/tests/valgrind/valgrind_test.v +++ b/vlib/v/tests/valgrind/valgrind_test.v @@ -2,6 +2,7 @@ import os import term import benchmark import v.util +import v.util.vtest const ( skip_valgrind_files = [ @@ -9,9 +10,10 @@ const ( ] ) -[if verbose] fn vprintln(s string) { - eprintln(s) + $if verbose ? { + eprintln(s) + } } fn test_all() { @@ -29,7 +31,8 @@ fn test_all() { eprintln(term.header(bench_message, '-')) vexe := os.getenv('VEXE') vroot := os.dir(vexe) - dir := os.join_path(vroot, 'vlib/v/tests/valgrind') + valgrind_test_path := 'vlib/v/tests/valgrind' + dir := os.join_path(vroot, valgrind_test_path) files := os.ls(dir) or { panic(err) } @@ -38,19 +41,23 @@ fn test_all() { os.mkdir_all(wrkdir) os.chdir(wrkdir) // - tests := files.filter(it.ends_with('.vv')) + tests := vtest.filter_vtest_only(files.filter(it.ends_with('.vv')), { + basepath: valgrind_test_path + }) bench.set_total_expected_steps(tests.len) - for test in tests { + for dir_test_path in tests { bench.step() - test_basename := os.file_name(test).replace('.vv', '') + test_basename := os.file_name(dir_test_path).replace('.vv', '') v_filename := '$wrkdir/${test_basename}.v' exe_filename := '$wrkdir/$test_basename' - full_test_path := os.real_path(os.join_path(dir, test)) - dir_test_path := full_test_path.replace(vroot + '/', '') + full_test_path := os.real_path(os.join_path(vroot, dir_test_path)) + // if dir_test_path in skip_valgrind_files { - bench.skip() - eprintln(bench.step_message_skip(dir_test_path)) - continue + $if !noskip ? { + bench.skip() + eprintln(bench.step_message_skip(dir_test_path)) + continue + } } vprintln('$dir_test_path => $v_filename') // diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 5482015d9d..1478a84dc2 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -12,9 +12,7 @@ pub const ( // math.bits is needed by strconv.ftoa pub const ( - builtin_module_parts = ['math.bits', 'strconv', 'strconv.ftoa', 'hash', 'strings', - 'builtin', - ] + builtin_module_parts = ['math.bits', 'strconv', 'strconv.ftoa', 'hash', 'strings', 'builtin'] ) pub const ( diff --git a/vlib/v/util/vtest/vtest.v b/vlib/v/util/vtest/vtest.v new file mode 100644 index 0000000000..7a4572a3f9 --- /dev/null +++ b/vlib/v/util/vtest/vtest.v @@ -0,0 +1,36 @@ +module vtest + +import os + +pub struct FilterVTestConfig { + basepath string = '' + fix_slashes bool = true +} + +pub fn filter_vtest_only(paths []string, config FilterVTestConfig) []string { + mut res := []string{} + patterns := os.getenv('VTEST_ONLY').split(',') + for relative_path in paths { + mut file := relative_path + if config.basepath.len > 0 { + file = os.join_path(config.basepath, file) + } + if config.fix_slashes { + file = file.replace('\\', '/') + } + if patterns.len != 0 { + mut found := 0 + for okpat in patterns { + if file.contains(okpat) { + found++ + break + } + } + if found == 0 { + continue + } + } + res << file + } + return res +} diff --git a/vlib/v/vet/vet_test.v b/vlib/v/vet/vet_test.v index 67f24bab4e..9742b18692 100644 --- a/vlib/v/vet/vet_test.v +++ b/vlib/v/vet/vet_test.v @@ -1,5 +1,6 @@ import os import term +import v.util.vtest fn test_vet() { vexe := os.getenv('VEXE') @@ -20,25 +21,10 @@ fn get_tests_in_dir(dir string) []string { } fn check_path(vexe, dir string, tests []string) int { - vtest_only := os.getenv('VTEST_ONLY').split(',') mut nb_fail := 0 - mut paths := []string{} - for test in tests { - path := os.join_path(dir, test).replace('\\', '/') - if vtest_only.len > 0 { - mut found := 0 - for substring in vtest_only { - if path.contains(substring) { - found++ - break - } - } - if found == 0 { - continue - } - } - paths << path - } + paths := vtest.filter_vtest_only(tests, { + basepath: dir + }) for path in paths { program := path.replace('.vv', '.v') print(path + ' ')