1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tools: let v fmt use VTMP too, stabilise v test-cleancode

This commit is contained in:
Delyan Angelov 2021-01-09 20:41:15 +02:00
parent fb7a5ee3af
commit aa37382e8d
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 20 additions and 16 deletions

View File

@ -40,6 +40,7 @@ const (
['haiku', '_haiku.v'],
['qnx', '_qnx.v'],
]
vtmp_folder = util.get_vtmp_folder()
)
fn main() {
@ -174,7 +175,7 @@ fn (foptions &FormatOptions) format_file(file string) {
formatted_content := fmt.fmt(file_ast, table, foptions.is_debug)
file_name := os.file_name(file)
ulid := rand.ulid()
vfmt_output_path := os.join_path(os.temp_dir(), 'vfmt_${ulid}_$file_name')
vfmt_output_path := os.join_path(vtmp_folder, 'vfmt_${ulid}_$file_name')
os.write_file(vfmt_output_path, formatted_content)
if foptions.is_verbose {
eprintln('fmt.fmt worked and $formatted_content.len bytes were written to $vfmt_output_path .')

View File

@ -82,11 +82,14 @@ fn main() {
fn tsession(vargs string, tool_source string, tool_cmd string, tool_args string, flist []string, slist []string) testing.TestSession {
os.chdir(vroot)
util.prepare_tool_when_needed(tool_source)
testing.eheader('Run `$tool_cmd` over most .v files')
mut test_session := testing.new_test_session('$vargs $tool_args')
test_session.files << flist
test_session.skip_files << slist
util.prepare_tool_when_needed(tool_source)
// note that util.prepare_tool_when_needed will put its temporary files
// in the VTMP from the test session too, so they will be cleaned up
// at the end
test_session.test()
eprintln(test_session.benchmark.total_message('running `$tool_cmd` over most .v files'))
return test_session

View File

@ -9,21 +9,8 @@ import rand
import v.pref
import v.util
fn get_vtmp_folder() string {
mut vtmp := os.getenv('VTMP')
if vtmp.len > 0 {
return vtmp
}
vtmp = os.join_path(os.temp_dir(), 'v')
if !os.exists(vtmp) || !os.is_dir(vtmp) {
os.mkdir_all(vtmp)
}
os.setenv('VTMP', vtmp, true)
return vtmp
}
fn (mut b Builder) get_vtmp_filename(base_file_name string, postfix string) string {
vtmp := get_vtmp_folder()
vtmp := util.get_vtmp_folder()
mut uniq := ''
if !b.pref.reuse_tmpc {
uniq = '.$rand.u64()'

View File

@ -462,6 +462,19 @@ pub fn recompile_file(vexe string, file string) {
}
}
pub fn get_vtmp_folder() string {
mut vtmp := os.getenv('VTMP')
if vtmp.len > 0 {
return vtmp
}
vtmp = os.join_path(os.temp_dir(), 'v')
if !os.exists(vtmp) || !os.is_dir(vtmp) {
os.mkdir_all(vtmp)
}
os.setenv('VTMP', vtmp, true)
return vtmp
}
pub fn should_bundle_module(mod string) bool {
return mod in bundle_modules || (mod.contains('.') && mod.all_before('.') in bundle_modules)
}