vtest,pref: add ability to have platform specific _test.v files (#20810)

This commit is contained in:
syrmel 2024-02-13 11:06:47 +01:00 committed by GitHub
parent c9933da675
commit 6a4f2937ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 89 additions and 7 deletions

View File

@ -210,10 +210,12 @@ pub fn (mut ts TestSession) print_messages() {
pub fn new_test_session(_vargs string, will_compile bool) TestSession { pub fn new_test_session(_vargs string, will_compile bool) TestSession {
mut skip_files := []string{} mut skip_files := []string{}
if will_compile { if will_compile {
// Skip the call_v_from_c files. They need special instructions for compilation. // Skip the call_v_from_* files. They need special instructions for compilation.
// Check the README.md for detailed information. // Check the README.md for detailed information.
skip_files << 'examples/call_v_from_c/v_test_print.v' skip_files << 'examples/call_v_from_c/v_test_print.v'
skip_files << 'examples/call_v_from_c/v_test_math.v' skip_files << 'examples/call_v_from_c/v_test_math.v'
skip_files << 'examples/call_v_from_python/test.v' // the example only makes sense to be compiled, when python is installed
skip_files << 'examples/call_v_from_ruby/test.v' // the example only makes sense to be compiled, when ruby is installed
// Skip the compilation of the coroutines example for now, since the Photon wrapper // Skip the compilation of the coroutines example for now, since the Photon wrapper
// is only available on macos for now, and it is not yet trivial enough to // is only available on macos for now, and it is not yet trivial enough to
// build/install on the CI: // build/install on the CI:
@ -262,8 +264,6 @@ pub fn new_test_session(_vargs string, will_compile bool) TestSession {
} }
if testing.runner_os != 'Linux' || testing.github_job != 'tcc' { if testing.runner_os != 'Linux' || testing.github_job != 'tcc' {
skip_files << 'examples/c_interop_wkhtmltopdf.v' // needs installation of wkhtmltopdf from https://github.com/wkhtmltopdf/packaging/releases skip_files << 'examples/c_interop_wkhtmltopdf.v' // needs installation of wkhtmltopdf from https://github.com/wkhtmltopdf/packaging/releases
skip_files << 'examples/call_v_from_python/test.v' // the example only makes sense to be compiled, when python is installed
skip_files << 'examples/call_v_from_ruby/test.v' // the example only makes sense to be compiled, when ruby is installed
skip_files << 'vlib/vweb/vweb_app_test.v' // imports the `sqlite` module, which in turn includes sqlite3.h skip_files << 'vlib/vweb/vweb_app_test.v' // imports the `sqlite` module, which in turn includes sqlite3.h
skip_files << 'vlib/x/vweb/tests/vweb_app_test.v' // imports the `sqlite` module, which in turn includes sqlite3.h skip_files << 'vlib/x/vweb/tests/vweb_app_test.v' // imports the `sqlite` module, which in turn includes sqlite3.h
} }
@ -296,6 +296,7 @@ pub fn new_test_session(_vargs string, will_compile bool) TestSession {
skip_files << 'examples/wasm/mandelbrot/mandelbrot.wasm.v' skip_files << 'examples/wasm/mandelbrot/mandelbrot.wasm.v'
skip_files << 'examples/wasm/change_color_by_id/change_color_by_id.wasm.v' skip_files << 'examples/wasm/change_color_by_id/change_color_by_id.wasm.v'
} }
skip_files = skip_files.map(os.abs_path)
vargs := _vargs.replace('-progress', '') vargs := _vargs.replace('-progress', '')
vexe := pref.vexe_path() vexe := pref.vexe_path()
vroot := os.dir(vexe) vroot := os.dir(vexe)
@ -439,7 +440,8 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
} }
tls_bench.no_cstep = true tls_bench.no_cstep = true
tls_bench.njobs = ts.benchmark.njobs tls_bench.njobs = ts.benchmark.njobs
mut relative_file := os.real_path(p.get_item[string](idx)) abs_path := os.real_path(p.get_item[string](idx))
mut relative_file := abs_path
mut cmd_options := [ts.vargs] mut cmd_options := [ts.vargs]
mut run_js := false mut run_js := false
@ -521,7 +523,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
} }
ts.benchmark.step() ts.benchmark.step()
tls_bench.step() tls_bench.step()
if relative_file.replace('\\', '/') in ts.skip_files { if abs_path in ts.skip_files {
ts.benchmark.skip() ts.benchmark.skip()
tls_bench.skip() tls_bench.skip()
if !testing.hide_skips { if !testing.hide_skips {

View File

@ -94,6 +94,10 @@ const skip_test_files = [
'vlib/db/pg/pg_orm_test.v', // pg not installed 'vlib/db/pg/pg_orm_test.v', // pg not installed
'vlib/db/pg/pg_test.v', // pg not installed 'vlib/db/pg/pg_test.v', // pg not installed
'vlib/db/pg/pg_double_test.v', // pg not installed 'vlib/db/pg/pg_double_test.v', // pg not installed
'vlib/v/tests/filtering_android_outside_termux_test.v', // platform filtering not baked into v test-self
'vlib/v/tests/filtering_macos_test.v', // platform filtering not baked into v test-self
'vlib/v/tests/filtering_nix_test.v', // platform filtering not baked into v test-self
'vlib/v/tests/filtering_windows_test.v', // platform filtering not baked into v test-self
] ]
// These tests are too slow to be run in the CI on each PR/commit // These tests are too slow to be run in the CI on each PR/commit
// in the sanitized modes: // in the sanitized modes:
@ -474,6 +478,7 @@ fn main() {
$if !macos { $if !macos {
tsession.skip_files << skip_on_non_macos tsession.skip_files << skip_on_non_macos
} }
tsession.skip_files = tsession.skip_files.map(os.abs_path)
tsession.test() tsession.test()
eprintln(tsession.benchmark.total_message(title)) eprintln(tsession.benchmark.total_message(title))
if tsession.benchmark.nfail > 0 { if tsession.benchmark.nfail > 0 {

View File

@ -5,6 +5,8 @@ import os.cmdline
import testing import testing
import v.pref import v.pref
const host_os = pref.get_host_os()
struct Context { struct Context {
mut: mut:
verbose bool verbose bool
@ -56,7 +58,7 @@ fn main() {
continue continue
} }
ts.files << targ ts.files << targ
ts.skip_files << targ ts.skip_files << os.abs_path(targ)
continue continue
} }
.ignore {} .ignore {}
@ -114,7 +116,7 @@ pub fn (mut ctx Context) should_test_dir(path string, backend string) ([]string,
continue continue
} }
res_files << p res_files << p
skip_files << p skip_files << os.abs_path(p)
} }
.ignore {} .ignore {}
} }
@ -130,6 +132,18 @@ enum ShouldTestStatus {
} }
fn (mut ctx Context) should_test(path string, backend string) ShouldTestStatus { fn (mut ctx Context) should_test(path string, backend string) ShouldTestStatus {
// Skip OS-specific tests if we are not running that OS
// Special case for android_outside_termux because of its
// underscores
if path.ends_with('_android_outside_termux_test.v') {
if !host_os.is_target_of('android_outside_termux') {
return .skip
}
}
os_target := path.all_before_last('_test.v').all_after_last('_')
if !host_os.is_target_of(os_target) {
return .skip
}
if path.ends_with('mysql_orm_test.v') { if path.ends_with('mysql_orm_test.v') {
testing.find_started_process('mysqld') or { return .skip } testing.find_started_process('mysqld') or { return .skip }
} }

View File

@ -158,6 +158,7 @@ pub fn (prefs &Preferences) should_compile_native(file string) bool {
return prefs.should_compile_c(file) return prefs.should_compile_c(file)
} }
// TODO: Rework this using is_target_of()
pub fn (prefs &Preferences) should_compile_c(file string) bool { pub fn (prefs &Preferences) should_compile_c(file string) bool {
if file.ends_with('.js.v') { if file.ends_with('.js.v') {
// Probably something like `a.js.v`. // Probably something like `a.js.v`.
@ -276,3 +277,35 @@ pub fn (prefs &Preferences) should_compile_js(file string) bool {
} }
return true return true
} }
// is_target_of returns true if this_os is included in the target specified
// for example, 'nix' is true for Linux and FreeBSD but not Windows
pub fn (this_os OS) is_target_of(target string) bool {
if this_os == .all {
return true
}
// Note: Termux is running natively on Android devices, but the compilers there (clang) usually do not have access
// to the Android SDK. The code here ensures that you can have `_termux.c.v` and `_android_outside_termux.c.v` postfixes,
// to target both the cross compilation case (where the SDK headers are used and available), and the Termux case,
// where the Android SDK is not used.
// 'nix' means "all but Windows"
if (this_os == .windows && target == 'nix')
|| (this_os != .windows && target == 'windows')
|| (this_os != .linux && target == 'linux')
|| (this_os != .macos && target in ['darwin', 'macos'])
|| (this_os != .ios && target == 'ios')
|| (this_os != .freebsd && target == 'freebsd')
|| (this_os != .openbsd && target == 'openbsd')
|| (this_os != .netbsd && target == 'netbsd')
|| (this_os != .dragonfly && target == 'dragonfly')
|| (this_os != .solaris && target == 'solaris')
|| (this_os != .qnx && target == 'qnx')
|| (this_os != .serenity && target == 'serenity')
|| (this_os != .plan9 && target == 'plan9')
|| (this_os != .vinix && target == 'vinix')
|| (this_os != .android && target in ['android', 'android_outside_termux'])
|| (this_os != .termux && target == 'termux') {
return false
}
return true
}

View File

@ -0,0 +1,7 @@
fn test_is_android() {
$if android {
assert true
} $else {
assert false, 'platform-specific test filtering failed'
}
}

View File

@ -0,0 +1,7 @@
fn test_is_macos() {
$if macos {
assert true
} $else {
assert false, 'platform-specific test filtering failed'
}
}

View File

@ -0,0 +1,7 @@
fn test_is_nix() {
$if !windows {
assert true
} $else {
assert false, 'platform-specific test filtering failed'
}
}

View File

@ -0,0 +1,7 @@
fn test_is_windows() {
$if windows {
assert true
} $else {
assert false, 'platform-specific test filtering failed'
}
}