tests: move is_nodejs_working() to jsgen_test.v

pull/8345/head
Delyan Angelov 2021-01-25 18:46:21 +02:00
parent 3199b982a9
commit cb04e6dccc
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 30 additions and 19 deletions

View File

@ -108,19 +108,8 @@ pub fn (mut ts TestSession) print_messages() {
} }
} }
fn is_nodejs_working() bool {
node_res := os.exec('node --version') or { return false }
if node_res.exit_code != 0 {
return false
}
return true
}
pub fn new_test_session(_vargs string) TestSession { pub fn new_test_session(_vargs string) TestSession {
mut skip_files := []string{} mut skip_files := []string{}
if !is_nodejs_working() {
skip_files << 'vlib/v/gen/js/jsgen_test.v'
}
$if solaris { $if solaris {
skip_files << 'examples/gg/gg2.v' skip_files << 'examples/gg/gg2.v'
skip_files << 'examples/pico/pico.v' skip_files << 'examples/pico/pico.v'

View File

@ -7,28 +7,50 @@ const (
) )
fn testsuite_end() { fn testsuite_end() {
os.rmdir_all(output_dir) os.rmdir_all(main.output_dir)
} }
const there_is_node_available = is_nodejs_working()
fn test_example_compilation() { fn test_example_compilation() {
vexe := os.getenv('VEXE') vexe := os.getenv('VEXE')
os.chdir(os.dir(vexe)) os.chdir(os.dir(vexe))
os.mkdir_all(output_dir) os.mkdir_all(main.output_dir)
files := find_test_files() files := find_test_files()
for file in files { for file in files {
path := os.join_path(test_dir, file) path := os.join_path(main.test_dir, file)
println('Testing $file') println('Testing $file')
v_code := os.system('$vexe $v_options -o ${output_dir}${file}.js $path') v_code := os.system('$vexe $main.v_options -o $main.output_dir${file}.js $path')
if v_code != 0 { assert false } // Compilation failed if v_code != 0 {
js_code := os.system('node ${output_dir}${file}.js') assert false
if js_code != 0 { assert false } // Running failed }
// Compilation failed
assert v_code == 0
if !main.there_is_node_available {
println(' ... skipping running $file, there is no NodeJS present')
continue
}
js_code := os.system('node $main.output_dir${file}.js')
if js_code != 0 {
assert false
}
// Running failed
assert js_code == 0
} }
} }
fn find_test_files() []string { fn find_test_files() []string {
files := os.ls(test_dir) or { panic(err) } files := os.ls(main.test_dir) or { panic(err) }
// The life example never exits, so tests would hang with it, skip // The life example never exits, so tests would hang with it, skip
mut tests := files.filter(it.ends_with('.v')).filter(it != 'life.v') mut tests := files.filter(it.ends_with('.v')).filter(it != 'life.v')
tests.sort() tests.sort()
return tests return tests
} }
fn is_nodejs_working() bool {
node_res := os.exec('node --version') or { return false }
if node_res.exit_code != 0 {
return false
}
return true
}