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

103 lines
2.4 KiB
V
Raw Normal View History

2019-12-01 12:50:13 +03:00
module main
import (
os
testing
benchmark
filepath
2019-12-06 02:11:39 +03:00
)
2019-12-01 12:50:13 +03:00
pub const (
v_modules_path = os.home_dir() + '.vmodules'
)
fn main() {
args := os.args
args_string := args[1..].join(' ')
v_test_compiler(args_string.all_before('test-compiler'))
}
fn v_test_compiler(vargs string){
v_test_compiler2(vargs)
//make_sure_vfmt_was_run()
}
fn v_test_compiler2(vargs string){
2019-12-01 12:50:13 +03:00
vexe := testing.vexe_path()
2019-12-23 13:09:22 +03:00
parent_dir := filepath.dir(vexe)
2019-12-01 12:50:13 +03:00
testing.vlib_should_be_present( parent_dir )
2019-12-06 02:11:39 +03:00
2019-12-01 12:50:13 +03:00
// Changing the current directory is needed for some of the compiler tests,
// compiler/tests/local_test.v and compiler/tests/repl/repl_test.v
os.chdir( parent_dir )
2019-12-06 02:11:39 +03:00
2019-12-01 12:50:13 +03:00
/*
if !os.exists(parent_dir + '/v.v') {
2019-12-01 16:12:51 +03:00
eprintln('v.v is missing, it must be next to the V executable')
2019-12-01 12:50:13 +03:00
exit(1)
}
*/
2019-12-06 02:11:39 +03:00
2019-12-01 12:50:13 +03:00
// Make sure v.c can be compiled without warnings
$if macos {
if os.exists('/v.v') {
2019-12-01 12:50:13 +03:00
os.system('$vexe -o v.c v.v')
if os.system('cc -Werror v.c') != 0 {
2019-12-01 16:12:51 +03:00
eprintln('cc failed to build v.c without warnings')
2019-12-01 12:50:13 +03:00
exit(1)
}
2019-12-01 16:12:51 +03:00
eprintln('v.c can be compiled without warnings. This is good :)')
2019-12-01 12:50:13 +03:00
}
}
2019-12-06 02:11:39 +03:00
2019-12-01 12:50:13 +03:00
building_tools_failed := testing.v_build_failing(vargs, 'tools')
2019-12-06 02:11:39 +03:00
2019-12-01 16:12:51 +03:00
eprintln('\nTesting all _test.v files...')
2019-12-06 02:11:39 +03:00
mut compiler_test_session := testing.new_test_session( vargs )
2019-12-01 12:50:13 +03:00
compiler_test_session.files << os.walk_ext(parent_dir, '_test.v')
compiler_test_session.test()
2019-12-01 16:12:51 +03:00
eprintln( compiler_test_session.benchmark.total_message('running V tests') )
2019-12-01 12:50:13 +03:00
2019-12-01 16:12:51 +03:00
eprintln('')
2019-12-01 12:50:13 +03:00
building_examples_failed := testing.v_build_failing(vargs, 'examples')
2019-12-01 16:12:51 +03:00
eprintln('')
2019-12-06 02:11:39 +03:00
building_live_failed := testing.v_build_failing(vargs + '-live',
filepath.join( 'examples', 'hot_reload'))
2019-12-01 16:12:51 +03:00
eprintln('')
2019-12-01 12:50:13 +03:00
v_module_install_cmd := '$vexe install nedpals.args'
2019-12-01 16:12:51 +03:00
eprintln('\nInstalling a v module with: $v_module_install_cmd ')
2019-12-01 12:50:13 +03:00
mut vmark := benchmark.new_benchmark()
ret := os.system(v_module_install_cmd)
if ret != 0 {
2019-12-01 16:12:51 +03:00
eprintln('failed to run v install')
2019-12-01 12:50:13 +03:00
}
if !os.exists(v_modules_path + '/nedpals/args') {
2019-12-01 16:12:51 +03:00
eprintln('v failed to install a test module')
2019-12-01 12:50:13 +03:00
}
vmark.stop()
2019-12-01 16:12:51 +03:00
eprintln( 'Installing a v module took: ' + vmark.total_duration().str() + 'ms')
2019-12-06 02:11:39 +03:00
make_sure_vfmt_was_run()
2019-12-06 02:11:39 +03:00
if building_tools_failed ||
compiler_test_session.failed ||
building_examples_failed ||
building_live_failed {
2019-12-01 12:50:13 +03:00
exit(1)
}
2019-12-06 02:11:39 +03:00
2019-12-01 12:50:13 +03:00
}
fn make_sure_vfmt_was_run() {
files := os.walk_ext('.', '_test.v')
for file in files {
println(file)
os.exec('./vfmt $file') or {
println('$file failed')
}
}
}