compiler: support VTMP; tests: delete .tmp.c files on successfull tests
parent
d82e6c9cd9
commit
6b2777e681
|
@ -1,6 +1,7 @@
|
|||
module testing
|
||||
|
||||
import os
|
||||
import time
|
||||
import term
|
||||
import benchmark
|
||||
import sync
|
||||
|
@ -59,6 +60,13 @@ pub fn (mut ts TestSession) init() {
|
|||
}
|
||||
|
||||
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()
|
||||
mut remaining_files := []string{}
|
||||
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())
|
||||
ts.benchmark.stop()
|
||||
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() {
|
||||
|
|
12
vlib/os/os.v
12
vlib/os/os.v
|
@ -1225,12 +1225,14 @@ pub fn flush() {
|
|||
|
||||
pub fn mkdir_all(path string) {
|
||||
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
|
||||
if !os.is_dir(p) {
|
||||
os.mkdir(p) or {
|
||||
panic(err)
|
||||
}
|
||||
if os.exists(p) && os.is_dir(p) {
|
||||
continue
|
||||
}
|
||||
os.mkdir(p) or {
|
||||
panic('folder: $p, error: $err')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,15 @@ import os
|
|||
import v.pref
|
||||
|
||||
fn get_vtmp_folder() string {
|
||||
vtmp := os.join_path(os.temp_dir(), 'v')
|
||||
if !os.is_dir(vtmp) {
|
||||
os.mkdir(vtmp) or {
|
||||
verror(err)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue