compiler: support VTMP; tests: delete .tmp.c files on successfull tests
parent
d82e6c9cd9
commit
6b2777e681
|
@ -1,6 +1,7 @@
|
||||||
module testing
|
module testing
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
import term
|
import term
|
||||||
import benchmark
|
import benchmark
|
||||||
import sync
|
import sync
|
||||||
|
@ -59,6 +60,13 @@ pub fn (mut ts TestSession) init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut ts TestSession) test() {
|
pub fn (mut ts TestSession) test() {
|
||||||
|
// Ensure that .tmp.c files generated from compiling _test.v files,
|
||||||
|
// are easy to delete at the end, *without* affecting the existing ones.
|
||||||
|
now := time.sys_mono_now()
|
||||||
|
new_vtmp_dir := os.join_path(os.temp_dir(), 'v', 'test_session_$now')
|
||||||
|
os.mkdir_all(new_vtmp_dir)
|
||||||
|
os.setenv('VTMP', new_vtmp_dir, true)
|
||||||
|
//
|
||||||
ts.init()
|
ts.init()
|
||||||
mut remaining_files := []string{}
|
mut remaining_files := []string{}
|
||||||
for dot_relative_file in ts.files {
|
for dot_relative_file in ts.files {
|
||||||
|
@ -99,6 +107,10 @@ pub fn (mut ts TestSession) test() {
|
||||||
pool_of_test_runners.work_on_pointers(remaining_files.pointers())
|
pool_of_test_runners.work_on_pointers(remaining_files.pointers())
|
||||||
ts.benchmark.stop()
|
ts.benchmark.stop()
|
||||||
eprintln(term.h_divider('-'))
|
eprintln(term.h_divider('-'))
|
||||||
|
// cleanup generated .tmp.c files after successfull tests:
|
||||||
|
if ts.benchmark.nfail == 0 {
|
||||||
|
os.rmdir_all(new_vtmp_dir)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut m TestMessageHandler) display_message() {
|
pub fn (mut m TestMessageHandler) display_message() {
|
||||||
|
|
10
vlib/os/os.v
10
vlib/os/os.v
|
@ -1225,12 +1225,14 @@ pub fn flush() {
|
||||||
|
|
||||||
pub fn mkdir_all(path string) {
|
pub fn mkdir_all(path string) {
|
||||||
mut p := if path.starts_with(os.path_separator) { os.path_separator } else { '' }
|
mut p := if path.starts_with(os.path_separator) { os.path_separator } else { '' }
|
||||||
for subdir in path.split(os.path_separator) {
|
path_parts := path.trim_left(os.path_separator).split(os.path_separator)
|
||||||
|
for subdir in path_parts {
|
||||||
p += subdir + os.path_separator
|
p += subdir + os.path_separator
|
||||||
if !os.is_dir(p) {
|
if os.exists(p) && os.is_dir(p) {
|
||||||
os.mkdir(p) or {
|
continue
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
os.mkdir(p) or {
|
||||||
|
panic('folder: $p, error: $err')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,15 @@ import os
|
||||||
import v.pref
|
import v.pref
|
||||||
|
|
||||||
fn get_vtmp_folder() string {
|
fn get_vtmp_folder() string {
|
||||||
vtmp := os.join_path(os.temp_dir(), 'v')
|
mut vtmp := os.getenv('VTMP')
|
||||||
if !os.is_dir(vtmp) {
|
if vtmp.len > 0 {
|
||||||
os.mkdir(vtmp) or {
|
return vtmp
|
||||||
verror(err)
|
|
||||||
}
|
}
|
||||||
|
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
|
return vtmp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue