1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.util.vtest: extract the common code for VTEST_ONLY in a single place

This commit is contained in:
Delyan Angelov 2020-08-05 19:34:27 +03:00
parent 1152bbd243
commit 6c27ce58ed
7 changed files with 69 additions and 81 deletions

View File

@ -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({

View File

@ -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 + ' ')

View File

@ -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')

View File

@ -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) {
$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,20 +41,24 @@ 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 {
$if !noskip ? {
bench.skip()
eprintln(bench.step_message_skip(dir_test_path))
continue
}
}
vprintln('$dir_test_path => $v_filename')
//
vprintln('cp $full_test_path $v_filename')

View File

@ -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 (

36
vlib/v/util/vtest/vtest.v Normal file
View File

@ -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
}

View File

@ -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 + ' ')