tools: make `v test vlib` and `v test-self` skip _test.js.v files, when `node` is not installed

pull/12761/head
Delyan Angelov 2021-12-07 21:31:29 +02:00
parent c29a3cf6e8
commit 7bbc70820a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 45 additions and 5 deletions

View File

@ -19,6 +19,10 @@ pub const hide_oks = os.getenv('VTEST_HIDE_OK') == '1'
pub const fail_fast = os.getenv('VTEST_FAIL_FAST') == '1' pub const fail_fast = os.getenv('VTEST_FAIL_FAST') == '1'
pub const is_node_present = os.execute('node --version').exit_code == 0
pub const all_processes = os.execute('ps ax').output.split_any('\r\n')
pub struct TestSession { pub struct TestSession {
pub mut: pub mut:
files []string files []string
@ -551,3 +555,12 @@ pub fn get_test_details(file string) TestDetails {
} }
return res return res
} }
pub fn find_started_process(pname string) ?string {
for line in testing.all_processes {
if line.contains(pname) {
return line
}
}
return error('could not find process matching $pname')
}

View File

@ -147,12 +147,22 @@ fn main() {
cmd_prefix := args_string.all_before('test-self') cmd_prefix := args_string.all_before('test-self')
title := 'testing vlib' title := 'testing vlib'
mut all_test_files := os.walk_ext(os.join_path(vroot, 'vlib'), '_test.v') mut all_test_files := os.walk_ext(os.join_path(vroot, 'vlib'), '_test.v')
all_test_files << os.walk_ext(os.join_path(vroot, 'vlib'), '_test.js.v') test_js_files := os.walk_ext(os.join_path(vroot, 'vlib'), '_test.js.v')
all_test_files << test_js_files
testing.eheader(title) testing.eheader(title)
mut tsession := testing.new_test_session(cmd_prefix, true) mut tsession := testing.new_test_session(cmd_prefix, true)
tsession.files << all_test_files.filter(!it.contains('testdata' + os.path_separator)) tsession.files << all_test_files.filter(!it.contains('testdata' + os.path_separator))
tsession.skip_files << skip_test_files tsession.skip_files << skip_test_files
if !testing.is_node_present {
testroot := vroot + os.path_separator
tsession.skip_files << test_js_files.map(it.replace(testroot, ''))
}
testing.find_started_process('mysqld') or {
tsession.skip_files << 'vlib/mysql/mysql_orm_test.v'
}
testing.find_started_process('postgres') or { tsession.skip_files << 'vlib/pg/pg_orm_test.v' }
if github_job == 'windows-tcc' { if github_job == 'windows-tcc' {
// TODO: fix these ASAP // TODO: fix these ASAP
tsession.skip_files << 'vlib/net/tcp_test.v' tsession.skip_files << 'vlib/net/tcp_test.v'

View File

@ -105,17 +105,34 @@ pub fn should_test_dir(path string, backend string) ([]string, []string) { // re
} }
enum ShouldTestStatus { enum ShouldTestStatus {
test // do test test // do test, print OK or FAIL, depending on if it passes
skip skip // print SKIP for the test
ignore ignore // just ignore the file, so it will not be printed at all in the list of tests
} }
fn should_test(path string, backend string) ShouldTestStatus { fn should_test(path string, backend string) ShouldTestStatus {
if path.ends_with('mysql_orm_test.v') {
testing.find_started_process('mysqld') or { return .skip }
}
if path.ends_with('pg_orm_test.v') {
testing.find_started_process('postgres') or { return .skip }
}
if path.ends_with('onecontext_test.v') {
return .skip
}
$if tinyc {
if path.ends_with('naked_attr_test.amd64.v') {
return .skip
}
}
if path.ends_with('_test.v') { if path.ends_with('_test.v') {
return .test return .test
} }
if path.ends_with('_test.js.v') { if path.ends_with('_test.js.v') {
return .test if testing.is_node_present {
return .test
}
return .skip
} }
if path.ends_with('.v') && path.count('.') == 2 { if path.ends_with('.v') && path.count('.') == 2 {
if !path.all_before_last('.v').all_before_last('.').ends_with('_test') { if !path.all_before_last('.v').all_before_last('.').ends_with('_test') {