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

pull/6074/head
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 benchmark
import sync import sync
import v.pref import v.pref
import v.util.vtest
pub struct TestMessageHandler { pub struct TestMessageHandler {
mut: mut:
@ -69,7 +70,6 @@ pub fn (mut ts TestSession) test() {
// //
ts.init() ts.init()
mut remaining_files := []string{} mut remaining_files := []string{}
vtest_only := os.getenv('VTEST_ONLY').split(',')
for dot_relative_file in ts.files { for dot_relative_file in ts.files {
relative_file := dot_relative_file.replace('./', '') relative_file := dot_relative_file.replace('./', '')
file := os.real_path(relative_file) file := os.real_path(relative_file)
@ -93,20 +93,9 @@ pub fn (mut ts TestSession) test() {
continue 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 << dot_relative_file
} }
remaining_files = vtest.filter_vtest_only(remaining_files, fix_slashes: false)
ts.files = remaining_files ts.files = remaining_files
ts.benchmark.set_total_expected_steps(remaining_files.len) ts.benchmark.set_total_expected_steps(remaining_files.len)
mut pool_of_test_runners := sync.new_pool_processor({ mut pool_of_test_runners := sync.new_pool_processor({

View File

@ -1,6 +1,7 @@
import os import os
import term import term
import v.util import v.util
import v.util.vtest
fn test_all() { fn test_all() {
mut total_errors := 0 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 { fn check_path(vexe, dir, voptions, result_extension string, tests []string) int {
vtest_only := os.getenv('VTEST_ONLY').split(',')
mut nb_fail := 0 mut nb_fail := 0
mut paths := []string{} paths := vtest.filter_vtest_only(tests, {
for test in tests { basepath: dir
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
}
for path in paths { for path in paths {
program := path.replace('.vv', '.v') program := path.replace('.vv', '.v')
print(path + ' ') print(path + ' ')

View File

@ -1,6 +1,7 @@
import os import os
import term import term
import v.util import v.util
import v.util.vtest
fn test_all() { fn test_all() {
mut total_errors := 0 mut total_errors := 0
@ -18,24 +19,9 @@ fn test_all() {
println('no compiler tests found') println('no compiler tests found')
assert false assert false
} }
vtest_only := os.getenv('VTEST_ONLY').split(',') paths := vtest.filter_vtest_only(tests, {
mut paths := []string{} basepath: dir
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
}
for path in paths { for path in paths {
print(path + ' ') print(path + ' ')
program := path.replace('.vv', '.v') program := path.replace('.vv', '.v')

View File

@ -2,6 +2,7 @@ import os
import term import term
import benchmark import benchmark
import v.util import v.util
import v.util.vtest
const ( const (
skip_valgrind_files = [ skip_valgrind_files = [
@ -9,9 +10,10 @@ const (
] ]
) )
[if verbose]
fn vprintln(s string) { fn vprintln(s string) {
$if verbose ? {
eprintln(s) eprintln(s)
}
} }
fn test_all() { fn test_all() {
@ -29,7 +31,8 @@ fn test_all() {
eprintln(term.header(bench_message, '-')) eprintln(term.header(bench_message, '-'))
vexe := os.getenv('VEXE') vexe := os.getenv('VEXE')
vroot := os.dir(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 { files := os.ls(dir) or {
panic(err) panic(err)
} }
@ -38,20 +41,24 @@ fn test_all() {
os.mkdir_all(wrkdir) os.mkdir_all(wrkdir)
os.chdir(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) bench.set_total_expected_steps(tests.len)
for test in tests { for dir_test_path in tests {
bench.step() 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' v_filename := '$wrkdir/${test_basename}.v'
exe_filename := '$wrkdir/$test_basename' exe_filename := '$wrkdir/$test_basename'
full_test_path := os.real_path(os.join_path(dir, test)) full_test_path := os.real_path(os.join_path(vroot, dir_test_path))
dir_test_path := full_test_path.replace(vroot + '/', '') //
if dir_test_path in skip_valgrind_files { if dir_test_path in skip_valgrind_files {
$if !noskip ? {
bench.skip() bench.skip()
eprintln(bench.step_message_skip(dir_test_path)) eprintln(bench.step_message_skip(dir_test_path))
continue continue
} }
}
vprintln('$dir_test_path => $v_filename') vprintln('$dir_test_path => $v_filename')
// //
vprintln('cp $full_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 // math.bits is needed by strconv.ftoa
pub const ( pub const (
builtin_module_parts = ['math.bits', 'strconv', 'strconv.ftoa', 'hash', 'strings', builtin_module_parts = ['math.bits', 'strconv', 'strconv.ftoa', 'hash', 'strings', 'builtin']
'builtin',
]
) )
pub const ( pub const (

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 os
import term import term
import v.util.vtest
fn test_vet() { fn test_vet() {
vexe := os.getenv('VEXE') 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 { fn check_path(vexe, dir string, tests []string) int {
vtest_only := os.getenv('VTEST_ONLY').split(',')
mut nb_fail := 0 mut nb_fail := 0
mut paths := []string{} paths := vtest.filter_vtest_only(tests, {
for test in tests { basepath: dir
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
}
for path in paths { for path in paths {
program := path.replace('.vv', '.v') program := path.replace('.vv', '.v')
print(path + ' ') print(path + ' ')