From 2cfc6e007dd3647c2fc60d2fa4ac9e50fd154848 Mon Sep 17 00:00:00 2001 From: Dialga Date: Mon, 6 Sep 2021 12:11:58 +1200 Subject: [PATCH] test: allow testing files from a relative directory (#11391) --- cmd/tools/modules/testing/common.v | 6 ++---- cmd/tools/test_if_v_test_system_works.v | 9 ++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 7f9de79d3c..111b579ef7 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -212,8 +212,7 @@ pub fn (mut ts TestSession) test() { ts.init() mut remaining_files := []string{} for dot_relative_file in ts.files { - relative_file := dot_relative_file.replace('./', '') - file := os.real_path(relative_file) + file := os.real_path(dot_relative_file) $if windows { if file.contains('sqlite') || file.contains('httpbin') { continue @@ -267,8 +266,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { p.set_thread_context(idx, tls_bench) } tls_bench.no_cstep = true - dot_relative_file := p.get_item(idx) - mut relative_file := dot_relative_file.replace('./', '') + mut relative_file := os.real_path(p.get_item(idx)) mut cmd_options := [ts.vargs] if relative_file.contains('global') && !ts.vargs.contains('fmt') { cmd_options << ' -enable-globals' diff --git a/cmd/tools/test_if_v_test_system_works.v b/cmd/tools/test_if_v_test_system_works.v index a86abd8b99..d163268928 100644 --- a/cmd/tools/test_if_v_test_system_works.v +++ b/cmd/tools/test_if_v_test_system_works.v @@ -37,10 +37,13 @@ fn new_tdir() string { fn cleanup_tdir() { println('... removing tdir: $tdir') - os.rmdir_all(tdir) or { panic(err) } + os.rmdir_all(tdir) or { eprintln(err) } } fn main() { + defer { + os.chdir(os.wd_at_startup) or {} + } println('> vroot: $vroot | vexe: $vexe | tdir: $tdir') ok_fpath := os.join_path(tdir, 'single_test.v') os.write_file(ok_fpath, 'fn test_ok(){ assert true }') ? @@ -51,6 +54,10 @@ fn main() { check_fail('"$vexe" $fail_fpath') check_fail('"$vexe" test $fail_fpath') check_fail('"$vexe" test $tdir') + rel_dir := os.join_path(tdir, rand.ulid()) + os.mkdir(rel_dir) ? + os.chdir(rel_dir) ? + check_ok('"$vexe" test ..${os.path_separator + os.base(ok_fpath)}') } fn check_ok(cmd string) string {