diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 503364c93a..6d32597c01 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -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 { mut skip_files := []string{} - if !is_nodejs_working() { - skip_files << 'vlib/v/gen/js/jsgen_test.v' - } $if solaris { skip_files << 'examples/gg/gg2.v' skip_files << 'examples/pico/pico.v' diff --git a/vlib/v/gen/js/jsgen_test.v b/vlib/v/gen/js/jsgen_test.v index ad3c62aa92..00fdbd3c74 100644 --- a/vlib/v/gen/js/jsgen_test.v +++ b/vlib/v/gen/js/jsgen_test.v @@ -7,28 +7,50 @@ const ( ) 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() { vexe := os.getenv('VEXE') os.chdir(os.dir(vexe)) - os.mkdir_all(output_dir) + os.mkdir_all(main.output_dir) files := find_test_files() for file in files { - path := os.join_path(test_dir, file) + path := os.join_path(main.test_dir, file) println('Testing $file') - v_code := os.system('$vexe $v_options -o ${output_dir}${file}.js $path') - if v_code != 0 { assert false } // Compilation failed - js_code := os.system('node ${output_dir}${file}.js') - if js_code != 0 { assert false } // Running failed + v_code := os.system('$vexe $main.v_options -o $main.output_dir${file}.js $path') + if v_code != 0 { + assert false + } + // 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 { - 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 mut tests := files.filter(it.ends_with('.v')).filter(it != 'life.v') tests.sort() 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 +}