Skip to content

Commit 07ee934

Browse files
committed
all: test fixes
1 parent 3934e4a commit 07ee934

52 files changed

Lines changed: 309 additions & 356 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ci/common/runner.v

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,23 @@ pub fn run(all_tasks map[string]Task) {
7272
task_name := os.args[1]
7373
if task_name == 'all' {
7474
log.info(term.colorize(term.green, 'Run everything...'))
75+
mut failed_tasks := []string{}
7576
for tname, t in all_tasks {
76-
t.run(tname)
77+
cmd := '${self_command} ${tname}'
78+
log.info('Start ${term.colorize(term.yellow, t.label)}, cmd: `${cmd}`')
79+
start := time.now()
80+
result := os.system(cmd)
81+
dt := time.now() - start
82+
if result != 0 {
83+
log.error('FAILED ${term.colorize(term.red, t.label)} in ${dt.milliseconds()} ms, cmd: `${cmd}`')
84+
failed_tasks << tname
85+
} else {
86+
log.info('Finished ${term.colorize(term.yellow, t.label)} in ${dt.milliseconds()} ms, cmd: `${cmd}`')
87+
}
88+
}
89+
if failed_tasks.len > 0 {
90+
log.error('${failed_tasks.len} task(s) failed: ${failed_tasks}')
91+
exit(1)
7792
}
7893
exit(0)
7994
}

cmd/tools/modules/testing/common.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ pub const show_longest_by_runtime = os.getenv('VTEST_SHOW_LONGEST_BY_RUNTIME').i
3333
pub const show_longest_by_comptime = os.getenv('VTEST_SHOW_LONGEST_BY_COMPTIME').int()
3434
pub const show_longest_by_totaltime = os.getenv('VTEST_SHOW_LONGEST_BY_TOTALTIME').int()
3535

36+
pub const is_ci = os.getenv('CI') != '' || os.getenv('GITHUB_JOB') != ''
37+
3638
pub const hide_skips = os.getenv('VTEST_HIDE_SKIP') == '1'
39+
|| (is_ci && os.getenv('VTEST_HIDE_SKIP') != '0')
3740

3841
pub const hide_oks = os.getenv('VTEST_HIDE_OK') == '1'
42+
|| (is_ci && os.getenv('VTEST_HIDE_OK') != '0')
3943

4044
pub const fail_fast = os.getenv('VTEST_FAIL_FAST') == '1'
4145

cmd/tools/test_if_v_test_system_works.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ fn main() {
118118
exit(1)
119119
}()
120120
println('> vroot: ${vroot} | vexe: ${vexe} | tdir: ${tdir}')
121+
os.setenv('VTEST_HIDE_OK', '0', true)
121122
ok_fpath := create_test('a_single_ok_test.v', 'fn test_ok(){ assert true }')!
122123
if check_ok('${vexe} ${ok_fpath}') != '' {
123124
exit(1)

cmd/tools/vdoc/testdata/output_formats/main.html

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

cmd/tools/vpm/common.v

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,24 @@ fn (selector VpmInstallServerSelector) metadata_server_urls() []string {
153153

154154
fn get_ident_from_url(raw_url string) !(string, string) {
155155
verbose_println_more(@FILE_LINE, @FN, 'raw_url: ${raw_url}')
156+
// On Windows, absolute paths like `C:\...` are misinterpreted by urllib.parse
157+
// (the drive letter `C:` is treated as a URL scheme). Handle local paths first.
158+
if os.is_abs_path(raw_url) || raw_url.starts_with('./') || raw_url.starts_with('../')
159+
|| raw_url.starts_with('~/') || raw_url.starts_with('.\\') || raw_url.starts_with('..\\') {
160+
normalized := raw_url.replace('\\', '/')
161+
_, name := normalized.rsplit_once('/') or {
162+
return '', normalized.trim_string_right('.git')
163+
}
164+
return '', name.trim_string_right('.git')
165+
}
156166
url := urllib.parse(raw_url) or { return error('failed to parse module URL `${raw_url}`.') }
157167
normalized_path := url.path.trim_left('/').trim_space()
158168
publisher, mut name := normalized_path.rsplit_once('/') or {
159169
if settings.vcs == .hg && raw_url.count(':') > 1 {
160170
verbose_println_more(@FILE_LINE, @FN, 'ok, publisher: "", name: "test_module"')
161171
return '', 'test_module'
162172
}
163-
if (url.scheme in ['file', ''] || os.is_abs_path(raw_url)
164-
|| raw_url.starts_with('./') || raw_url.starts_with('../')
165-
|| raw_url.starts_with('~/')) && normalized_path.len > 0 {
173+
if url.scheme in ['file', ''] && normalized_path.len > 0 {
166174
return '', normalized_path
167175
}
168176
final_error := 'failed to retrieve module name for `${url}`.'

cmd/tools/vpm/install_local_test.v

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,15 @@ fn test_install_from_local_git_repository_variants() {
7474
for i, c in cases {
7575
vmodules_path := os.join_path(test_path, 'vmodules_case_${i}')
7676
test_utils.set_test_env(vmodules_path)
77-
mut cmd := '${vexe} install ${c.args}'
77+
cmd := '${vexe} install ${c.args}'
78+
old_dir := os.getwd()
7879
if c.workdir != '' {
79-
cmd = 'cd ${os.quoted_path(c.workdir)} && ${cmd}'
80+
os.chdir(c.workdir) or { panic(err) }
8081
}
8182
res := cmd_ok(@LOCATION, cmd)
83+
if c.workdir != '' {
84+
os.chdir(old_dir) or {}
85+
}
8286
assert res.output.contains('Installed `${c.module_name}`'), res.output
8387
manifest := vmod.from_file(os.join_path(vmodules_path, c.module_name, 'v.mod')) or {
8488
panic('Failed to parse v.mod for `${c.module_name}`. ${err}')

cmd/tools/vpm/link_test.v

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ fn testsuite_end() {
1414
os.rmdir_all(test_path) or {}
1515
}
1616

17+
fn execute_in_dir(dir string, cmd string) os.Result {
18+
old_dir := os.getwd()
19+
os.chdir(dir) or { return os.Result{
20+
exit_code: -1
21+
output: 'failed to chdir: ${err}'
22+
} }
23+
defer {
24+
os.chdir(old_dir) or {}
25+
}
26+
return os.execute(cmd)
27+
}
28+
1729
fn test_link_and_unlink_current_project() {
1830
module_name := 'author.coollib'
1931
project_path := os.join_path(test_path, 'project')
@@ -28,7 +40,7 @@ fn test_link_and_unlink_current_project() {
2840
}
2941
link_path := os.join_path(test_path, 'author', 'coollib')
3042

31-
link_res := os.execute('cd ${os.quoted_path(project_subdir)} && ${vexe} link')
43+
link_res := execute_in_dir(project_subdir, '${vexe} link')
3244
if link_res.exit_code != 0 && is_symlink_privilege_error(link_res.output) {
3345
eprintln('Skipping symlink test due to missing privileges.')
3446
return
@@ -38,12 +50,12 @@ fn test_link_and_unlink_current_project() {
3850
assert os.real_path(link_path) == os.real_path(project_path)
3951
assert link_res.output.contains('Linked `${module_name}`'), link_res.output
4052

41-
link_again_res := os.execute('cd ${os.quoted_path(project_path)} && ${vexe} link')
53+
link_again_res := execute_in_dir(project_path, '${vexe} link')
4254
assert link_again_res.exit_code == 0, link_again_res.output
4355
assert link_again_res.output.contains('already linked')
4456
|| link_again_res.output.contains('already available'), link_again_res.output
4557

46-
unlink_res := os.execute('cd ${os.quoted_path(project_subdir)} && ${vexe} unlink')
58+
unlink_res := execute_in_dir(project_subdir, '${vexe} unlink')
4759
assert unlink_res.exit_code == 0, unlink_res.output
4860
assert !os.exists(link_path) && !os.is_link(link_path)
4961
assert !os.exists(os.join_path(test_path, 'author'))
@@ -56,7 +68,7 @@ fn test_link_without_vmod() {
5668
assert false, err.msg()
5769
return
5870
}
59-
res := os.execute('cd ${os.quoted_path(path)} && ${vexe} link')
71+
res := execute_in_dir(path, '${vexe} link')
6072
assert res.exit_code == 1, res.output
6173
assert res.output.contains('no `v.mod` file found'), res.output
6274
}

cmd/tools/vpm/settings.v

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,21 @@ fn unique_server_urls(urls []string) []string {
111111
fn normalize_server_url(url string) string {
112112
return url.trim_space().trim_string_right('/')
113113
}
114+
115+
fn parse_server_urls(args []string) []string {
116+
mut urls := []string{}
117+
mut i := 0
118+
for i < args.len {
119+
if args[i] in server_url_option_names {
120+
i++
121+
if i < args.len {
122+
url := normalize_server_url(args[i])
123+
if url != '' && url !in urls {
124+
urls << url
125+
}
126+
}
127+
}
128+
i++
129+
}
130+
return urls
131+
}

cmd/tools/vpm/vpm.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import rand
99
import v.help
1010
import v.vmod
1111

12+
const server_url_option_names = ['-m', '--mirror', '-server-url', '--server-url', '--server-urls']
1213
const settings = init_settings()
1314
const default_vpm_server_urls = ['https://vpm.vlang.io', 'https://vpm.url4e.com']
1415
const vpm_server_urls = rand.shuffle_clone(default_vpm_server_urls) or { [] } // ensure that all queries are distributed fairly

cmd/tools/vtest_test.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn testsuite_begin() {
1616
os.setenv('VFLAGS', '', true)
1717
os.setenv('VCOLORS', 'never', true)
1818
os.setenv('VJOBS', '2', true)
19+
os.setenv('VTEST_HIDE_OK', '0', true)
1920
os.rmdir_all(tpath) or {}
2021
os.mkdir_all(tpath)!
2122

0 commit comments

Comments
 (0)