From 7bbc70820af4f15fd513eaac3c1f3f6b26e476bf Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 7 Dec 2021 21:31:29 +0200 Subject: [PATCH] tools: make `v test vlib` and `v test-self` skip _test.js.v files, when `node` is not installed --- cmd/tools/modules/testing/common.v | 13 +++++++++++++ cmd/tools/vtest-self.v | 12 +++++++++++- cmd/tools/vtest.v | 25 +++++++++++++++++++++---- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 814f8e4f6a..b3a1085e78 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -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 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 mut: files []string @@ -551,3 +555,12 @@ pub fn get_test_details(file string) TestDetails { } 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') +} diff --git a/cmd/tools/vtest-self.v b/cmd/tools/vtest-self.v index 859029ef3f..27856f6872 100644 --- a/cmd/tools/vtest-self.v +++ b/cmd/tools/vtest-self.v @@ -147,12 +147,22 @@ fn main() { cmd_prefix := args_string.all_before('test-self') title := 'testing vlib' 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) mut tsession := testing.new_test_session(cmd_prefix, true) tsession.files << all_test_files.filter(!it.contains('testdata' + os.path_separator)) 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' { // TODO: fix these ASAP tsession.skip_files << 'vlib/net/tcp_test.v' diff --git a/cmd/tools/vtest.v b/cmd/tools/vtest.v index 8829f67fef..2c7b963a25 100644 --- a/cmd/tools/vtest.v +++ b/cmd/tools/vtest.v @@ -105,17 +105,34 @@ pub fn should_test_dir(path string, backend string) ([]string, []string) { // re } enum ShouldTestStatus { - test // do test - skip - ignore + test // do test, print OK or FAIL, depending on if it passes + skip // print SKIP for the test + 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 { + 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') { return .test } 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.all_before_last('.v').all_before_last('.').ends_with('_test') {