1
0
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:
Delyan Angelov 2022-09-16 04:56:19 +03:00 committed by GitHub
parent 7e69619add
commit f922ed0941
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 210 additions and 144 deletions

View File

@ -4,6 +4,7 @@ import os
import time import time
import term import term
import benchmark import benchmark
import sync
import sync.pool import sync.pool
import v.pref import v.pref
import v.util.vtest import v.util.vtest
@ -281,13 +282,17 @@ pub fn (mut ts TestSession) test() {
ts.append_message(.sentinel, '') // send the sentinel ts.append_message(.sentinel, '') // send the sentinel
_ := <-ts.nprint_ended // wait for the stop of the printing thread _ := <-ts.nprint_ended // wait for the stop of the printing thread
eprintln(term.h_divider('-')) eprintln(term.h_divider('-'))
ts.show_list_of_failed_tests()
// cleanup generated .tmp.c files after successful tests: // cleanup generated .tmp.c files after successful tests:
if ts.benchmark.nfail == 0 { if ts.benchmark.nfail == 0 {
if ts.rm_binaries { if ts.rm_binaries {
os.rmdir_all(ts.vtmp_dir) or {} 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 { fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
@ -343,11 +348,9 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
} }
generated_binary_fpath := os.join_path_single(tmpd, generated_binary_fname) generated_binary_fpath := os.join_path_single(tmpd, generated_binary_fname)
if produces_file_output { if produces_file_output {
if os.exists(generated_binary_fpath) {
if ts.rm_binaries { if ts.rm_binaries {
os.rm(generated_binary_fpath) or {} os.rm(generated_binary_fpath) or {}
} }
}
cmd_options << ' -o ${os.quoted_path(generated_binary_fpath)}' 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 {} os.rm(generated_binary_fpath) or {}
} }
return pool.no_result return pool.no_result
@ -571,7 +574,7 @@ pub fn header(msg string) {
pub fn setup_new_vtmp_folder() string { pub fn setup_new_vtmp_folder() string {
now := time.sys_mono_now() 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.mkdir_all(new_vtmp_dir) or { panic(err) }
os.setenv('VTMP', new_vtmp_dir, true) os.setenv('VTMP', new_vtmp_dir, true)
return new_vtmp_dir return new_vtmp_dir

View File

@ -26,13 +26,11 @@ fn get_vexe_path() string {
} }
fn new_tdir() string { fn new_tdir() string {
tdir_ := os.join_path(os.temp_dir(), rand.ulid()) dir := os.join_path(os.temp_dir(), 'v', rand.ulid())
if os.exists(tdir_) { os.rmdir_all(dir) or {}
os.rmdir(tdir_) or { panic(err) } os.mkdir_all(dir) or { panic(err) }
}
os.mkdir(tdir_) or { panic(err) }
C.atexit(cleanup_tdir) C.atexit(cleanup_tdir)
return tdir_ return dir
} }
fn cleanup_tdir() { fn cleanup_tdir() {

View File

@ -1,5 +1,17 @@
import os 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 { struct BumpTestCase {
file_name string file_name string
contents string contents string
@ -62,10 +74,7 @@ fn main() {
] ]
fn run_individual_test(case BumpTestCase) ? { fn run_individual_test(case BumpTestCase) ? {
vexe := @VEXE test_file := os.join_path_single(tfolder, case.file_name)
temp_dir := os.temp_dir()
test_file := os.join_path_single(temp_dir, case.file_name)
os.rm(test_file) or {} os.rm(test_file) or {}
os.write_file(test_file, case.contents)? os.write_file(test_file, case.contents)?

View File

@ -22,7 +22,7 @@ const (
show_progress = os.getenv('GITHUB_JOB') == '' && '-silent' !in os.args show_progress = os.getenv('GITHUB_JOB') == '' && '-silent' !in os.args
non_option_args = cmdline.only_non_options(os.args[2..]) non_option_args = cmdline.only_non_options(os.args[2..])
is_verbose = os.getenv('VERBOSE') != '' 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 { struct CheckResult {

View File

@ -1,6 +1,6 @@
import os import os
const test_path = 'vcreate_test' const test_path = os.join_path(os.temp_dir(), 'v', 'vcreate_test')
fn init_and_check() ? { fn init_and_check() ? {
os.execute_or_exit('${os.quoted_path(@VEXE)} init') os.execute_or_exit('${os.quoted_path(@VEXE)} init')
@ -59,42 +59,27 @@ fn init_and_check() ? {
].join_lines() ].join_lines()
} }
fn test_v_init() ? { fn prepare_test_path() ? {
dir := os.join_path(os.temp_dir(), test_path) os.rmdir_all(test_path) or {}
os.rmdir_all(dir) or {} os.mkdir_all(test_path) or {}
os.mkdir(dir) or {} os.chdir(test_path)?
defer { }
os.rmdir_all(dir) or {}
}
os.chdir(dir)?
fn test_v_init() ? {
prepare_test_path()?
init_and_check()? init_and_check()?
} }
fn test_v_init_in_git_dir() ? { fn test_v_init_in_git_dir() ? {
dir := os.join_path(os.temp_dir(), test_path) prepare_test_path()?
os.rmdir_all(dir) or {}
os.mkdir(dir) or {}
defer {
os.rmdir_all(dir) or {}
}
os.chdir(dir)?
os.execute_or_exit('git init .') os.execute_or_exit('git init .')
init_and_check()? init_and_check()?
} }
fn test_v_init_no_overwrite_gitignore() ? { fn test_v_init_no_overwrite_gitignore() ? {
dir := os.join_path(os.temp_dir(), test_path) prepare_test_path()?
os.rmdir_all(dir) or {} os.write_file('.gitignore', 'blah')?
os.mkdir(dir) or {}
os.write_file('$dir/.gitignore', 'blah')?
defer {
os.rmdir_all(dir) or {}
}
os.chdir(dir)?
os.execute_or_exit('${os.quoted_path(@VEXE)} init') os.execute_or_exit('${os.quoted_path(@VEXE)} init')
assert os.read_file('.gitignore')? == 'blah' assert os.read_file('.gitignore')? == 'blah'
} }
@ -110,19 +95,15 @@ trim_trailing_whitespace = true
indent_style = tab indent_style = tab
indent_size = 4 indent_size = 4
' '
prepare_test_path()?
dir := os.join_path(os.temp_dir(), test_path) os.write_file('.gitattributes', git_attributes_content)?
os.rmdir_all(dir) or {} os.write_file('.editorconfig', editor_config_content)?
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)?
os.execute_or_exit('${os.quoted_path(@VEXE)} init') os.execute_or_exit('${os.quoted_path(@VEXE)} init')
assert os.read_file('.gitattributes')? == git_attributes_content assert os.read_file('.gitattributes')? == git_attributes_content
assert os.read_file('.editorconfig')? == editor_config_content assert os.read_file('.editorconfig')? == editor_config_content
} }
fn testsuite_end() {
os.rmdir_all(test_path) or {}
}

View File

@ -17,6 +17,7 @@ mut:
in_func bool // are we inside a new custom user function in_func bool // are we inside a new custom user function
line string // the current line entered by the user line string // the current line entered by the user
is_pin bool // does the repl 'pin' entered source code 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 modules []string // all the import modules
alias map[string]string // all the alias used in the import 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 vstartup = os.getenv('VSTARTUP')
const repl_folder = os.join_path(os.temp_dir(), 'v', 'repl')
enum FnType { enum FnType {
@none @none
void void
fn_type 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{ return Repl{
readline: readline.Readline{ readline: readline.Readline{
skip_empty: true skip_empty: true
} }
folder: folder
modules: ['os', 'time', 'math'] modules: ['os', 'time', 'math']
vstartup_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 // Test file used to check if a function as a void return or a value return.
// value return. eval_func_lines: vstartup_source
eval_func_lines: os.read_file(vstartup) or { '' }.trim_right('\n\r').split_into_lines()
} }
} }
@ -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: // This function checks which one we have:
fn (r &Repl) check_fn_type_kind(new_line string) FnType { fn (r &Repl) check_fn_type_kind(new_line string) FnType {
source_code := r.current_source_code(true, false) + '\nprintln($new_line)' 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) } os.write_file(check_file, source_code) or { panic(err) }
defer { defer {
os.rm(check_file) or {} os.rm(check_file) or {}
@ -296,7 +301,7 @@ fn run_repl(workdir string, vrepl_prefix string) int {
} }
cleanup_files([file, temp_file]) cleanup_files([file, temp_file])
} }
mut r := new_repl() mut r := new_repl(workdir)
for { for {
if r.indent == 0 { if r.indent == 0 {
prompt = '>>> ' prompt = '>>> '
@ -359,7 +364,7 @@ fn run_repl(workdir string, vrepl_prefix string) int {
continue continue
} }
if r.line == 'reset' { if r.line == 'reset' {
r = new_repl() r = new_repl(workdir)
continue continue
} }
if r.line == 'list' { if r.line == 'list' {
@ -517,7 +522,7 @@ fn main() {
// so that the repl can be launched in parallel by several different // so that the repl can be launched in parallel by several different
// threads by the REPL test runner. // threads by the REPL test runner.
args := cmdline.options_after(os.args, ['repl']) 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()}.') replprefix := cmdline.option(args, '-replprefix', 'noprefix.${rand.ulid()}.')
if !os.exists(os.getenv('VEXE')) { if !os.exists(os.getenv('VEXE')) {
println('Usage:') println('Usage:')

View File

@ -2,12 +2,18 @@ module main
import os import os
import v.vcache import v.vcache
import v.util
fn main() { fn main() {
mut cm := vcache.new_cache_manager([]) wipe_path(vcache.new_cache_manager([]).basepath, 'V cache')
cpath := cm.basepath 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) { if os.exists(cpath) && os.is_dir(cpath) {
os.rmdir_all(cpath) or {} os.rmdir_all(cpath) or {}
} }
println('V cache folder $cpath was wiped.') os.mkdir_all(cpath) or {}
println('$label folder $cpath was wiped.')
} }

View File

@ -1,7 +1,17 @@
import os import os
import net.unix import net.unix
const test_port = os.join_path(os.temp_dir(), 'unix_domain_socket') const tfolder = os.join_path(os.temp_dir(), 'v', 'unix_test')
const test_port = os.join_path(tfolder, 'unix_domain_socket')
fn testsuite_begin() {
os.mkdir_all(tfolder) or {}
}
fn testsuite_end() {
os.rmdir_all(tfolder) or {}
}
fn handle_conn(mut c unix.StreamConn) { fn handle_conn(mut c unix.StreamConn) {
for { for {

View File

@ -5,7 +5,17 @@ import net
// ensure that `net` is used, i.e. no warnings // ensure that `net` is used, i.e. no warnings
const use_net = net.no_timeout const use_net = net.no_timeout
const test_port = os.join_path(os.temp_dir(), 'unix_domain_socket') const tfolder = os.join_path(os.temp_dir(), 'v', 'net_and_unix_together')
const test_port = os.join_path(tfolder, 'unix_domain_socket')
fn testsuite_begin() {
os.mkdir_all(tfolder) or {}
}
fn testsuite_end() {
os.rmdir_all(tfolder) or {}
}
fn test_that_net_and_net_unix_can_be_imported_together_without_conflicts() ? { fn test_that_net_and_net_unix_can_be_imported_together_without_conflicts() ? {
mut l := unix.listen_stream(test_port) or { panic(err) } mut l := unix.listen_stream(test_port) or { panic(err) }

View File

@ -6,7 +6,17 @@ struct User {
name string [unique] name string [unique]
} }
const db_path = os.join_path(os.temp_dir(), 'sql_statement_or_blocks.db') const db_folder = os.join_path(os.temp_dir(), 'v', 'orm_sql')
const db_path = os.join_path(db_folder, 'sql_statement_or_blocks.db')
fn testsuite_begin() {
os.mkdir_all(db_folder) or {}
}
fn testsuite_end() {
os.rmdir_all(db_folder) or {}
}
fn test_ensure_db_exists_and_user_table_is_ok() ? { fn test_ensure_db_exists_and_user_table_is_ok() ? {
mut db := sqlite.connect(db_path)? mut db := sqlite.connect(db_path)?

View File

@ -106,7 +106,7 @@ fn test_create_file() ? {
fn test_is_file() { fn test_is_file() {
// Setup // Setup
work_dir := os.join_path_single(os.getwd(), 'is_file_test') work_dir := os.join_path_single(tfolder, 'is_file_test')
os.mkdir_all(work_dir) or { panic(err) } os.mkdir_all(work_dir) or { panic(err) }
tfile := os.join_path_single(work_dir, 'tmp_file') tfile := os.join_path_single(work_dir, 'tmp_file')
// Test things that shouldn't be a file // Test things that shouldn't be a file
@ -309,7 +309,7 @@ fn test_cp() {
} }
fn test_mv() { fn test_mv() {
work_dir := os.join_path_single(os.getwd(), 'mv_test') work_dir := os.join_path_single(tfolder, 'mv_test')
os.mkdir_all(work_dir) or { panic(err) } os.mkdir_all(work_dir) or { panic(err) }
// Setup test files // Setup test files
tfile1 := os.join_path_single(work_dir, 'file') tfile1 := os.join_path_single(work_dir, 'file')
@ -404,7 +404,7 @@ fn test_realpath_non_existing() {
fn test_realpath_existing() { fn test_realpath_existing() {
existing_file_name := 'existing_file.txt' existing_file_name := 'existing_file.txt'
existing_file := os.join_path_single(os.temp_dir(), existing_file_name) existing_file := os.join_path_single(tfolder, existing_file_name)
os.rm(existing_file) or {} os.rm(existing_file) or {}
os.write_file(existing_file, 'abc') or {} os.write_file(existing_file, 'abc') or {}
assert os.exists(existing_file) assert os.exists(existing_file)

View File

@ -6,12 +6,14 @@ import time
const ( const (
vexe = os.getenv('VEXE') vexe = os.getenv('VEXE')
vroot = os.dir(vexe) vroot = os.dir(vexe)
test_os_process = os.join_path(os.temp_dir(), 'v', 'test_os_process.exe') tfolder = os.join_path(os.temp_dir(), 'v', 'tests', 'os_process')
test_os_process = os.join_path(tfolder, 'test_os_process.exe')
test_os_process_source = os.join_path(vroot, 'cmd/tools/test_os_process.v') test_os_process_source = os.join_path(vroot, 'cmd/tools/test_os_process.v')
) )
fn testsuite_begin() ? { fn testsuite_begin() ? {
os.rm(test_os_process) or {} os.rmdir_all(tfolder) or {}
os.mkdir_all(tfolder)?
if os.getenv('WINE_TEST_OS_PROCESS_EXE') != '' { if os.getenv('WINE_TEST_OS_PROCESS_EXE') != '' {
// Make it easier to run the test under wine emulation, by just // Make it easier to run the test under wine emulation, by just
// prebuilding the executable with: // prebuilding the executable with:
@ -24,6 +26,10 @@ fn testsuite_begin() ? {
assert os.exists(test_os_process) assert os.exists(test_os_process)
} }
fn testsuite_end() ? {
os.rmdir_all(tfolder) or {}
}
fn test_getpid() { fn test_getpid() {
pid := os.getpid() pid := os.getpid()
eprintln('current pid: $pid') eprintln('current pid: $pid')

View File

@ -1,6 +1,16 @@
import os import os
import stbi import stbi
const tfolder = os.join_path(os.temp_dir(), 'v', 'stbi')
fn testsuite_begin() {
os.mkdir_all(tfolder) or {}
}
fn testsuite_end() {
os.rmdir_all(tfolder) or {}
}
fn test_stbi_read_write() { fn test_stbi_read_write() {
vroot := @VEXEROOT vroot := @VEXEROOT
path := os.join_path(vroot, 'examples', 'assets', 'logo.png') path := os.join_path(vroot, 'examples', 'assets', 'logo.png')
@ -8,7 +18,7 @@ fn test_stbi_read_write() {
d_s := stbi.load(path) or { panic(err) } d_s := stbi.load(path) or { panic(err) }
println('Image source data:\n $d_s') println('Image source data:\n $d_s')
out_path := os.join_path(os.temp_dir(), 'test.png') out_path := os.join_path(tfolder, 'test.png')
println('Out path: $out_path') println('Out path: $out_path')
stbi.stbi_write_png(out_path, d_s.width, d_s.height, 4, d_s.data, d_s.width * 4) or { stbi.stbi_write_png(out_path, d_s.width, d_s.height, 4, d_s.data, d_s.width * 4) or {
panic(err) panic(err)

View File

@ -68,7 +68,7 @@ fn test_toml() {
} }
fn test_toml_file() { fn test_toml_file() {
out_path := os.join_path(os.temp_dir(), 'v_toml_tests') out_path := os.join_path(os.temp_dir(), 'v', 'toml_tests')
test_file := os.join_path(out_path, 'toml_example.toml') test_file := os.join_path(out_path, 'toml_example.toml')
os.mkdir_all(out_path) or { assert false } os.mkdir_all(out_path) or { assert false }
defer { defer {

View File

@ -2,44 +2,44 @@ module main
import os import os
const test_path = 'v_run_check' const test_path = os.join_path(os.temp_dir(), 'v', 'run_check')
const vexe = @VEXE
fn testsuite_begin() {
os.mkdir_all(test_path) or {}
}
fn testsuite_end() {
os.rmdir_all(test_path) or {}
}
fn test_conditional_executable_removal() ? { fn test_conditional_executable_removal() ? {
// Setup the sample project os.chdir(test_path)?
dir := os.join_path(os.temp_dir(), test_path) os.execute_or_exit('${os.quoted_path(vexe)} init')
os.rmdir_all(dir) or {} mut executable := 'run_check'
os.mkdir(dir) or {}
defer {
os.rmdir_all(dir) or {}
}
os.chdir(dir)?
os.execute_or_exit('${os.quoted_path(@VEXE)} init')
mut executable := test_path
$if windows { $if windows {
executable += '.exe' executable += '.exe'
} }
original_file_list_ := os.ls(dir)? original_file_list_ := os.ls(test_path)?
dump(original_file_list_) dump(original_file_list_)
assert executable !in original_file_list_ assert executable !in original_file_list_
assert os.execute('${os.quoted_path(@VEXE)} run .').output.trim_space() == 'Hello World!' assert os.execute('${os.quoted_path(vexe)} run .').output.trim_space() == 'Hello World!'
after_run_file_list := os.ls(dir)? after_run_file_list := os.ls(test_path)?
dump(after_run_file_list) dump(after_run_file_list)
assert executable !in after_run_file_list assert executable !in after_run_file_list
assert os.execute('${os.quoted_path(@VEXE)} .').exit_code == 0 assert os.execute('${os.quoted_path(vexe)} .').exit_code == 0
assert os.execute('./$executable').output.trim_space() == 'Hello World!' assert os.execute('./$executable').output.trim_space() == 'Hello World!'
after_compilation__ := os.ls(dir)? after_compilation__ := os.ls(test_path)?
dump(after_compilation__) dump(after_compilation__)
assert executable in after_compilation__ assert executable in after_compilation__
assert os.execute('${os.quoted_path(@VEXE)} run .').output.trim_space() == 'Hello World!' assert os.execute('${os.quoted_path(vexe)} run .').output.trim_space() == 'Hello World!'
after_second_run___ := os.ls(dir)? after_second_run___ := os.ls(test_path)?
dump(after_second_run___) dump(after_second_run___)
assert executable in after_second_run___ assert executable in after_second_run___
} }

View File

@ -9,7 +9,7 @@ fn interpreter_wrap(a string) string {
} }
fn interp_test(expression string, expected string) ? { fn interp_test(expression string, expected string) ? {
tmpdir := os.join_path(os.temp_dir(), 'v_interpret_test_$rand.ulid()') tmpdir := os.join_path(os.temp_dir(), 'v', 'interpret_test_$rand.ulid()')
os.mkdir_all(tmpdir) or {} os.mkdir_all(tmpdir) or {}
defer { defer {
os.rmdir_all(tmpdir) or {} os.rmdir_all(tmpdir) or {}

View File

@ -21,7 +21,7 @@ fn mm(s string) string {
fn test_out_files() ? { fn test_out_files() ? {
println(term.colorize(term.green, '> testing whether .out files match:')) println(term.colorize(term.green, '> testing whether .out files match:'))
os.chdir(vroot) or {} os.chdir(vroot) or {}
output_path := os.join_path(os.temp_dir(), 'coutput', 'out') output_path := os.join_path(os.temp_dir(), 'v', 'coutput', 'out')
os.mkdir_all(output_path)? os.mkdir_all(output_path)?
defer { defer {
os.rmdir_all(output_path) or {} os.rmdir_all(output_path) or {}
@ -92,7 +92,7 @@ fn test_out_files() ? {
fn test_c_must_have_files() ? { fn test_c_must_have_files() ? {
println(term.colorize(term.green, '> testing whether `.c.must_have` files match:')) println(term.colorize(term.green, '> testing whether `.c.must_have` files match:'))
os.chdir(vroot) or {} os.chdir(vroot) or {}
output_path := os.join_path(os.temp_dir(), 'coutput', 'c_must_have') output_path := os.join_path(os.temp_dir(), 'v', 'coutput', 'c_must_have')
os.mkdir_all(output_path)? os.mkdir_all(output_path)?
defer { defer {
os.rmdir_all(output_path) or {} os.rmdir_all(output_path) or {}

View File

@ -19,8 +19,11 @@ fn test_golang() {
dir := os.join_path(vroot, 'vlib/v/gen/golang/tests') dir := os.join_path(vroot, 'vlib/v/gen/golang/tests')
files := os.ls(dir) or { panic(err) } files := os.ls(dir) or { panic(err) }
// //
wrkdir := os.join_path(os.temp_dir(), 'vtests', 'golang') wrkdir := os.join_path(os.temp_dir(), 'v', 'tests', 'golang')
os.mkdir_all(wrkdir) or { panic(err) } os.mkdir_all(wrkdir) or { panic(err) }
defer {
os.rmdir_all(wrkdir) or {}
}
os.chdir(wrkdir) or {} os.chdir(wrkdir) or {}
tests := files.filter(it.ends_with('.vv')) tests := files.filter(it.ends_with('.vv'))
if tests.len == 0 { if tests.len == 0 {

View File

@ -2,7 +2,7 @@ import os
const ( const (
test_dir = os.join_path('vlib', 'v', 'gen', 'js', 'tests') test_dir = os.join_path('vlib', 'v', 'gen', 'js', 'tests')
output_dir = os.join_path(os.temp_dir(), '_js_tests/') output_dir = os.join_path(os.temp_dir(), 'v', '_js_tests/')
v_options = '-b js -w' v_options = '-b js -w'
node_options = '' node_options = ''
) )

View File

@ -20,8 +20,11 @@ fn test_native() {
dir := os.join_path(vroot, 'vlib/v/gen/native/tests') dir := os.join_path(vroot, 'vlib/v/gen/native/tests')
files := os.ls(dir) or { panic(err) } files := os.ls(dir) or { panic(err) }
// //
wrkdir := os.join_path(os.temp_dir(), 'vtests', 'native') wrkdir := os.join_path(os.temp_dir(), 'v', 'tests', 'native')
os.mkdir_all(wrkdir) or { panic(err) } os.mkdir_all(wrkdir) or { panic(err) }
defer {
os.rmdir_all(wrkdir) or {}
}
os.chdir(wrkdir) or {} os.chdir(wrkdir) or {}
tests := files.filter(it.ends_with('.vv')) tests := files.filter(it.ends_with('.vv'))
if tests.len == 0 { if tests.len == 0 {

View File

@ -33,16 +33,15 @@ TODO: Cleanup this when/if v has better process control/communication primitives
*/ */
const ( const (
vexe = os.getenv('VEXE') vexe = os.getenv('VEXE')
tmp_file = os.join_path(os.temp_dir(), 'generated_live_program.tmp.v') vtmp_folder = os.join_path(os.temp_dir(), 'v', 'tests', 'live')
source_file = os.join_path(os.temp_dir(), 'generated_live_program.v') tmp_file = os.join_path(vtmp_folder, 'generated_live_program.tmp.v')
genexe_file = os.join_path(os.temp_dir(), 'generated_live_program') source_file = os.join_path(vtmp_folder, 'generated_live_program.v')
output_file = os.join_path(os.temp_dir(), 'generated_live_program.output.txt') genexe_file = os.join_path(vtmp_folder, 'generated_live_program')
res_original_file = os.join_path(os.temp_dir(), 'ORIGINAL.txt') output_file = os.join_path(vtmp_folder, 'generated_live_program.output.txt')
res_changed_file = os.join_path(os.temp_dir(), 'CHANGED.txt') res_original_file = os.join_path(vtmp_folder, 'ORIGINAL.txt')
res_another_file = os.join_path(os.temp_dir(), 'ANOTHER.txt') res_changed_file = os.join_path(vtmp_folder, 'CHANGED.txt')
res_stop_file = os.join_path(os.temp_dir(), 'STOP.txt') res_another_file = os.join_path(vtmp_folder, 'ANOTHER.txt')
cleanup_files = [tmp_file, source_file, genexe_file, output_file, res_original_file, res_stop_file = os.join_path(vtmp_folder, 'STOP.txt')
res_changed_file, res_another_file, res_stop_file]
live_program_source = get_source_template() live_program_source = get_source_template()
) )
@ -69,16 +68,14 @@ fn atomic_write_source(source string) {
// //
fn testsuite_begin() { fn testsuite_begin() {
os.rmdir_all(vtmp_folder) or {}
os.mkdir_all(vtmp_folder) or {}
if os.user_os() !in ['linux', 'solaris'] && os.getenv('FORCE_LIVE_TEST').len == 0 { if os.user_os() !in ['linux', 'solaris'] && os.getenv('FORCE_LIVE_TEST').len == 0 {
eprintln('Testing the runtime behaviour of -live mode,') eprintln('Testing the runtime behaviour of -live mode,')
eprintln('is reliable only on Linux/macOS for now.') eprintln('is reliable only on Linux/macOS for now.')
eprintln('You can still do it by setting FORCE_LIVE_TEST=1 .') eprintln('You can still do it by setting FORCE_LIVE_TEST=1 .')
exit(0) exit(0)
} }
for f in [tmp_file, source_file, output_file, res_original_file, res_changed_file,
res_another_file, res_stop_file] {
os.rm(f) or {}
}
atomic_write_source(live_program_source) atomic_write_source(live_program_source)
} }
@ -106,9 +103,7 @@ fn testsuite_end() {
assert histogram['ORIGINAL'] > 0 assert histogram['ORIGINAL'] > 0
assert histogram['CHANGED'] + histogram['ANOTHER'] > 0 assert histogram['CHANGED'] + histogram['ANOTHER'] > 0
// assert histogram['END'] > 0 // assert histogram['END'] > 0
for tfile in cleanup_files { os.rmdir_all(vtmp_folder) or {}
os.rm(tfile) or {}
}
} }
fn change_source(new string) { fn change_source(new string) {
@ -120,7 +115,7 @@ fn change_source(new string) {
fn wait_for_file(new string) { fn wait_for_file(new string) {
time.sleep(100 * time.millisecond) time.sleep(100 * time.millisecond)
expected_file := os.join_path(os.temp_dir(), new + '.txt') expected_file := os.join_path(vtmp_folder, new + '.txt')
eprintln('waiting for $expected_file ...') eprintln('waiting for $expected_file ...')
max_wait_cycles := edefault('WAIT_CYCLES', '1').int() max_wait_cycles := edefault('WAIT_CYCLES', '1').int()
for i := 0; i <= max_wait_cycles; i++ { for i := 0; i <= max_wait_cycles; i++ {

View File

@ -5,6 +5,16 @@ import time
const vexe = @VEXE const vexe = @VEXE
const tfolder = os.join_path(os.temp_dir(), 'v', 'custom_compile')
fn testsuite_begin() {
os.mkdir_all(tfolder) or {}
}
fn testsuite_end() {
os.rmdir_all(tfolder) or {}
}
fn test_cflags() ? { fn test_cflags() ? {
os.chdir(os.real_path(@VMODROOT)) or {} os.chdir(os.real_path(@VMODROOT)) or {}
mut debug_arg := '-g3 -O0' mut debug_arg := '-g3 -O0'
@ -39,10 +49,10 @@ fn test_cflags() ? {
fn custom_compile(fname string, cflags_options string) Results { fn custom_compile(fname string, cflags_options string) Results {
mut res := Results{} mut res := Results{}
res.exe = os.join_path(os.temp_dir(), fname) res.exe = os.join_path(tfolder, fname)
res.sw = time.new_stopwatch() res.sw = time.new_stopwatch()
res.compilation = os.execute('${os.quoted_path(vexe)} -cflags "$cflags_options" -o ${os.quoted_path(res.exe)} examples/hello_world.v') res.compilation = os.execute('${os.quoted_path(vexe)} -cflags "$cflags_options" -o ${os.quoted_path(res.exe)} examples/hello_world.v')
res.delta = res.sw.elapsed().microseconds() res.delta = res.sw.elapsed().milliseconds()
res.file_size = os.file_size(res.exe) res.file_size = os.file_size(res.exe)
println('> $fname build took: $res.delta ms with "$cflags_options", file size: $res.file_size') println('> $fname build took: $res.delta ms with "$cflags_options", file size: $res.file_size')
return res return res

View File

@ -162,7 +162,7 @@ fn test_closure_return_${styp}_${i}() ? {
code := v_code.str() code := v_code.str()
println('Compiling V code (${code.count('\n')} lines) ...') println('Compiling V code (${code.count('\n')} lines) ...')
wrkdir := os.join_path(os.temp_dir(), 'vtests', 'closures') wrkdir := os.join_path(os.temp_dir(), 'v', 'tests', 'closures')
os.mkdir_all(wrkdir)? os.mkdir_all(wrkdir)?
os.chdir(wrkdir)? os.chdir(wrkdir)?
os.write_file('closure_return_test.v', code)? os.write_file('closure_return_test.v', code)?

View File

@ -1,7 +1,7 @@
import os import os
import time import time
const crun_folder = os.join_path(os.temp_dir(), 'crun_folder') const crun_folder = os.join_path(os.temp_dir(), 'v', 'crun_folder')
const vprogram_file = os.join_path(crun_folder, 'vprogram.vv') const vprogram_file = os.join_path(crun_folder, 'vprogram.vv')

View File

@ -4,13 +4,19 @@ const vexe = os.getenv('VEXE')
const turn_off_vcolors = os.setenv('VCOLORS', 'never', true) const turn_off_vcolors = os.setenv('VCOLORS', 'never', true)
const vtmp_folder = os.join_path(os.temp_dir(), 'v', 'tests', 'run_v_code')
fn test_vexe_is_set() { fn test_vexe_is_set() {
assert vexe != '' assert vexe != ''
} }
fn pipe_to_v_run() ? { fn pipe_to_v_run() ? {
os.mkdir_all(vtmp_folder) or {}
defer {
os.rmdir_all(vtmp_folder) or {}
}
cat_cmd := if os.user_os() == 'windows' { 'cmd /c type' } else { 'cat' } cat_cmd := if os.user_os() == 'windows' { 'cmd /c type' } else { 'cat' }
tmp_v_file := os.join_path(os.real_path(os.temp_dir()), 'generated_piped_program.v') tmp_v_file := os.join_path(os.real_path(vtmp_folder), 'generated_piped_program.v')
// eprintln('>>> tmp_v_file: $tmp_v_file') // eprintln('>>> tmp_v_file: $tmp_v_file')
os.write_file(tmp_v_file, 'println(1 + 3)\nprintln("hello")\n')? os.write_file(tmp_v_file, 'println(1 + 3)\nprintln("hello")\n')?
assert os.is_file(tmp_v_file) assert os.is_file(tmp_v_file)

View File

@ -66,7 +66,7 @@ fn test_all() {
mut files := os.ls(dir) or { panic(err) } mut files := os.ls(dir) or { panic(err) }
files.sort() files.sort()
// //
wrkdir := os.join_path(os.temp_dir(), 'vtests', 'valgrind') wrkdir := os.join_path(os.temp_dir(), 'v', 'tests', 'valgrind')
os.mkdir_all(wrkdir) or { panic(err) } os.mkdir_all(wrkdir) or { panic(err) }
os.chdir(wrkdir) or {} os.chdir(wrkdir) or {}
// //
@ -122,4 +122,5 @@ fn test_all() {
if bench.nfail > 0 { if bench.nfail > 0 {
exit(1) exit(1)
} }
os.rmdir_all(wrkdir) or {}
} }

View File

@ -2,7 +2,7 @@ import os
import v.vcache import v.vcache
const ( const (
vcache_folder = os.join_path(os.temp_dir(), 'vcache_folder') vcache_folder = os.join_path(os.temp_dir(), 'v', 'cache_folder')
) )
fn check_cache_entry_fpath_invariants(x string, extension string) { fn check_cache_entry_fpath_invariants(x string, extension string) {

View File

@ -1,31 +1,31 @@
import vweb.assets import vweb.assets
import os import os
const base_cache_dir = os.join_path(os.temp_dir(), 'v', 'assets_test_cache')
fn testsuite_begin() {
os.mkdir_all(base_cache_dir) or {}
}
fn testsuite_end() {
os.rmdir_all(base_cache_dir) or {}
}
// clean_cache_dir used before and after tests that write to a cache directory. // clean_cache_dir used before and after tests that write to a cache directory.
// Because of parallel compilation and therefore test running, // Because of parallel compilation and therefore test running,
// unique cache dirs are needed per test function. // unique cache dirs are needed per test function.
fn clean_cache_dir(dir string) { fn clean_cache_dir(dir string) {
if os.is_dir(dir) { os.rmdir_all(dir) or {}
os.rmdir_all(dir) or { panic(err) }
}
}
fn base_cache_dir() string {
return os.join_path(os.temp_dir(), 'assets_test_cache')
} }
fn cache_dir(test_name string) string { fn cache_dir(test_name string) string {
return os.join_path(base_cache_dir(), test_name) return os.join_path(base_cache_dir, test_name)
} }
fn get_test_file_path(file string) string { fn get_test_file_path(file string) string {
path := os.join_path(base_cache_dir(), file) path := os.join_path(base_cache_dir, file)
if !os.is_dir(base_cache_dir()) { os.rm(path) or {}
os.mkdir_all(base_cache_dir()) or { panic(err) }
}
if !os.exists(path) {
os.write_file(path, get_test_file_contents(file)) or { panic(err) } os.write_file(path, get_test_file_contents(file)) or { panic(err) }
}
return path return path
} }