mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tests: unify all temporary files/folders under $VTMP/v, that can be cleaned by v wipe-cache (#15774)
This commit is contained in:
@@ -4,6 +4,7 @@ import os
|
||||
import time
|
||||
import term
|
||||
import benchmark
|
||||
import sync
|
||||
import sync.pool
|
||||
import v.pref
|
||||
import v.util.vtest
|
||||
@@ -281,13 +282,17 @@ pub fn (mut ts TestSession) test() {
|
||||
ts.append_message(.sentinel, '') // send the sentinel
|
||||
_ := <-ts.nprint_ended // wait for the stop of the printing thread
|
||||
eprintln(term.h_divider('-'))
|
||||
ts.show_list_of_failed_tests()
|
||||
// cleanup generated .tmp.c files after successful tests:
|
||||
if ts.benchmark.nfail == 0 {
|
||||
if ts.rm_binaries {
|
||||
os.rmdir_all(ts.vtmp_dir) or {}
|
||||
}
|
||||
}
|
||||
ts.show_list_of_failed_tests()
|
||||
// remove empty session folders:
|
||||
if os.ls(ts.vtmp_dir) or { [] }.len == 0 {
|
||||
os.rmdir_all(ts.vtmp_dir) or {}
|
||||
}
|
||||
}
|
||||
|
||||
fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
|
||||
@@ -343,10 +348,8 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
|
||||
}
|
||||
generated_binary_fpath := os.join_path_single(tmpd, generated_binary_fname)
|
||||
if produces_file_output {
|
||||
if os.exists(generated_binary_fpath) {
|
||||
if ts.rm_binaries {
|
||||
os.rm(generated_binary_fpath) or {}
|
||||
}
|
||||
if ts.rm_binaries {
|
||||
os.rm(generated_binary_fpath) or {}
|
||||
}
|
||||
|
||||
cmd_options << ' -o ${os.quoted_path(generated_binary_fpath)}'
|
||||
@@ -439,7 +442,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
|
||||
}
|
||||
}
|
||||
}
|
||||
if produces_file_output && os.exists(generated_binary_fpath) && ts.rm_binaries {
|
||||
if produces_file_output && ts.rm_binaries {
|
||||
os.rm(generated_binary_fpath) or {}
|
||||
}
|
||||
return pool.no_result
|
||||
@@ -571,7 +574,7 @@ pub fn header(msg string) {
|
||||
|
||||
pub fn setup_new_vtmp_folder() string {
|
||||
now := time.sys_mono_now()
|
||||
new_vtmp_dir := os.join_path(os.temp_dir(), 'v', 'test_session_$now')
|
||||
new_vtmp_dir := os.join_path(os.temp_dir(), 'v', 'tsession_${sync.thread_id().hex()}_$now')
|
||||
os.mkdir_all(new_vtmp_dir) or { panic(err) }
|
||||
os.setenv('VTMP', new_vtmp_dir, true)
|
||||
return new_vtmp_dir
|
||||
|
||||
@@ -26,13 +26,11 @@ fn get_vexe_path() string {
|
||||
}
|
||||
|
||||
fn new_tdir() string {
|
||||
tdir_ := os.join_path(os.temp_dir(), rand.ulid())
|
||||
if os.exists(tdir_) {
|
||||
os.rmdir(tdir_) or { panic(err) }
|
||||
}
|
||||
os.mkdir(tdir_) or { panic(err) }
|
||||
dir := os.join_path(os.temp_dir(), 'v', rand.ulid())
|
||||
os.rmdir_all(dir) or {}
|
||||
os.mkdir_all(dir) or { panic(err) }
|
||||
C.atexit(cleanup_tdir)
|
||||
return tdir_
|
||||
return dir
|
||||
}
|
||||
|
||||
fn cleanup_tdir() {
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
import os
|
||||
|
||||
const vexe = @VEXE
|
||||
|
||||
const tfolder = os.join_path(os.temp_dir(), 'v', 'vbump')
|
||||
|
||||
fn testsuite_begin() {
|
||||
os.mkdir_all(tfolder) or {}
|
||||
}
|
||||
|
||||
fn testsuite_end() {
|
||||
os.rmdir_all(tfolder) or {}
|
||||
}
|
||||
|
||||
struct BumpTestCase {
|
||||
file_name string
|
||||
contents string
|
||||
@@ -62,10 +74,7 @@ fn main() {
|
||||
]
|
||||
|
||||
fn run_individual_test(case BumpTestCase) ? {
|
||||
vexe := @VEXE
|
||||
|
||||
temp_dir := os.temp_dir()
|
||||
test_file := os.join_path_single(temp_dir, case.file_name)
|
||||
test_file := os.join_path_single(tfolder, case.file_name)
|
||||
|
||||
os.rm(test_file) or {}
|
||||
os.write_file(test_file, case.contents)?
|
||||
|
||||
@@ -22,7 +22,7 @@ const (
|
||||
show_progress = os.getenv('GITHUB_JOB') == '' && '-silent' !in os.args
|
||||
non_option_args = cmdline.only_non_options(os.args[2..])
|
||||
is_verbose = os.getenv('VERBOSE') != ''
|
||||
vcheckfolder = os.join_path_single(os.temp_dir(), 'vcheck_$os.getuid()')
|
||||
vcheckfolder = os.join_path(os.temp_dir(), 'v', 'vcheck_$os.getuid()')
|
||||
)
|
||||
|
||||
struct CheckResult {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
|
||||
const test_path = 'vcreate_test'
|
||||
const test_path = os.join_path(os.temp_dir(), 'v', 'vcreate_test')
|
||||
|
||||
fn init_and_check() ? {
|
||||
os.execute_or_exit('${os.quoted_path(@VEXE)} init')
|
||||
@@ -59,42 +59,27 @@ fn init_and_check() ? {
|
||||
].join_lines()
|
||||
}
|
||||
|
||||
fn test_v_init() ? {
|
||||
dir := os.join_path(os.temp_dir(), test_path)
|
||||
os.rmdir_all(dir) or {}
|
||||
os.mkdir(dir) or {}
|
||||
defer {
|
||||
os.rmdir_all(dir) or {}
|
||||
}
|
||||
os.chdir(dir)?
|
||||
fn prepare_test_path() ? {
|
||||
os.rmdir_all(test_path) or {}
|
||||
os.mkdir_all(test_path) or {}
|
||||
os.chdir(test_path)?
|
||||
}
|
||||
|
||||
fn test_v_init() ? {
|
||||
prepare_test_path()?
|
||||
init_and_check()?
|
||||
}
|
||||
|
||||
fn test_v_init_in_git_dir() ? {
|
||||
dir := os.join_path(os.temp_dir(), test_path)
|
||||
os.rmdir_all(dir) or {}
|
||||
os.mkdir(dir) or {}
|
||||
defer {
|
||||
os.rmdir_all(dir) or {}
|
||||
}
|
||||
os.chdir(dir)?
|
||||
prepare_test_path()?
|
||||
os.execute_or_exit('git init .')
|
||||
init_and_check()?
|
||||
}
|
||||
|
||||
fn test_v_init_no_overwrite_gitignore() ? {
|
||||
dir := os.join_path(os.temp_dir(), test_path)
|
||||
os.rmdir_all(dir) or {}
|
||||
os.mkdir(dir) or {}
|
||||
os.write_file('$dir/.gitignore', 'blah')?
|
||||
defer {
|
||||
os.rmdir_all(dir) or {}
|
||||
}
|
||||
os.chdir(dir)?
|
||||
|
||||
prepare_test_path()?
|
||||
os.write_file('.gitignore', 'blah')?
|
||||
os.execute_or_exit('${os.quoted_path(@VEXE)} init')
|
||||
|
||||
assert os.read_file('.gitignore')? == 'blah'
|
||||
}
|
||||
|
||||
@@ -110,19 +95,15 @@ trim_trailing_whitespace = true
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
'
|
||||
|
||||
dir := os.join_path(os.temp_dir(), test_path)
|
||||
os.rmdir_all(dir) or {}
|
||||
os.mkdir(dir) or {}
|
||||
os.write_file('$dir/.gitattributes', git_attributes_content)?
|
||||
os.write_file('$dir/.editorconfig', editor_config_content)?
|
||||
defer {
|
||||
os.rmdir_all(dir) or {}
|
||||
}
|
||||
os.chdir(dir)?
|
||||
|
||||
prepare_test_path()?
|
||||
os.write_file('.gitattributes', git_attributes_content)?
|
||||
os.write_file('.editorconfig', editor_config_content)?
|
||||
os.execute_or_exit('${os.quoted_path(@VEXE)} init')
|
||||
|
||||
assert os.read_file('.gitattributes')? == git_attributes_content
|
||||
assert os.read_file('.editorconfig')? == editor_config_content
|
||||
}
|
||||
|
||||
fn testsuite_end() {
|
||||
os.rmdir_all(test_path) or {}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ mut:
|
||||
in_func bool // are we inside a new custom user function
|
||||
line string // the current line entered by the user
|
||||
is_pin bool // does the repl 'pin' entered source code
|
||||
folder string // the folder in which the repl will write its temporary source files
|
||||
//
|
||||
modules []string // all the import modules
|
||||
alias map[string]string // all the alias used in the import
|
||||
@@ -35,22 +36,26 @@ const vexe = os.getenv('VEXE')
|
||||
|
||||
const vstartup = os.getenv('VSTARTUP')
|
||||
|
||||
const repl_folder = os.join_path(os.temp_dir(), 'v', 'repl')
|
||||
|
||||
enum FnType {
|
||||
@none
|
||||
void
|
||||
fn_type
|
||||
}
|
||||
|
||||
fn new_repl() Repl {
|
||||
fn new_repl(folder string) Repl {
|
||||
vstartup_source := os.read_file(vstartup) or { '' }.trim_right('\n\r').split_into_lines()
|
||||
os.mkdir_all(folder) or {}
|
||||
return Repl{
|
||||
readline: readline.Readline{
|
||||
skip_empty: true
|
||||
}
|
||||
folder: folder
|
||||
modules: ['os', 'time', 'math']
|
||||
vstartup_lines: os.read_file(vstartup) or { '' }.trim_right('\n\r').split_into_lines()
|
||||
// Test file used to check if a function as a void return or a
|
||||
// value return.
|
||||
eval_func_lines: os.read_file(vstartup) or { '' }.trim_right('\n\r').split_into_lines()
|
||||
vstartup_lines: vstartup_source
|
||||
// Test file used to check if a function as a void return or a value return.
|
||||
eval_func_lines: vstartup_source
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +178,7 @@ fn (r &Repl) current_source_code(should_add_temp_lines bool, not_add_print bool)
|
||||
// This function checks which one we have:
|
||||
fn (r &Repl) check_fn_type_kind(new_line string) FnType {
|
||||
source_code := r.current_source_code(true, false) + '\nprintln($new_line)'
|
||||
check_file := os.join_path(os.temp_dir(), '${rand.ulid()}.vrepl.check.v')
|
||||
check_file := os.join_path(r.folder, '${rand.ulid()}.vrepl.check.v')
|
||||
os.write_file(check_file, source_code) or { panic(err) }
|
||||
defer {
|
||||
os.rm(check_file) or {}
|
||||
@@ -296,7 +301,7 @@ fn run_repl(workdir string, vrepl_prefix string) int {
|
||||
}
|
||||
cleanup_files([file, temp_file])
|
||||
}
|
||||
mut r := new_repl()
|
||||
mut r := new_repl(workdir)
|
||||
for {
|
||||
if r.indent == 0 {
|
||||
prompt = '>>> '
|
||||
@@ -359,7 +364,7 @@ fn run_repl(workdir string, vrepl_prefix string) int {
|
||||
continue
|
||||
}
|
||||
if r.line == 'reset' {
|
||||
r = new_repl()
|
||||
r = new_repl(workdir)
|
||||
continue
|
||||
}
|
||||
if r.line == 'list' {
|
||||
@@ -517,7 +522,7 @@ fn main() {
|
||||
// so that the repl can be launched in parallel by several different
|
||||
// threads by the REPL test runner.
|
||||
args := cmdline.options_after(os.args, ['repl'])
|
||||
replfolder := os.real_path(cmdline.option(args, '-replfolder', os.temp_dir()))
|
||||
replfolder := os.real_path(cmdline.option(args, '-replfolder', repl_folder))
|
||||
replprefix := cmdline.option(args, '-replprefix', 'noprefix.${rand.ulid()}.')
|
||||
if !os.exists(os.getenv('VEXE')) {
|
||||
println('Usage:')
|
||||
|
||||
@@ -2,12 +2,18 @@ module main
|
||||
|
||||
import os
|
||||
import v.vcache
|
||||
import v.util
|
||||
|
||||
fn main() {
|
||||
mut cm := vcache.new_cache_manager([])
|
||||
cpath := cm.basepath
|
||||
wipe_path(vcache.new_cache_manager([]).basepath, 'V cache')
|
||||
wipe_path(util.get_vtmp_folder(), 'V tmp.c')
|
||||
wipe_path(os.join_path(os.temp_dir(), 'v'), 'V tests')
|
||||
}
|
||||
|
||||
fn wipe_path(cpath string, label string) {
|
||||
if os.exists(cpath) && os.is_dir(cpath) {
|
||||
os.rmdir_all(cpath) or {}
|
||||
}
|
||||
println('V cache folder $cpath was wiped.')
|
||||
os.mkdir_all(cpath) or {}
|
||||
println('$label folder $cpath was wiped.')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user