From 225d319fffbe2f2af8f481b5731f0843313fd20a Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 3 Jan 2025 15:18:53 +0200 Subject: [PATCH] fix live_test.v on windows --- vlib/v/live/live_test.v | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/vlib/v/live/live_test.v b/vlib/v/live/live_test.v index da2b51b30071bd..a708f21d5afc48 100644 --- a/vlib/v/live/live_test.v +++ b/vlib/v/live/live_test.v @@ -36,7 +36,7 @@ const vtmp_folder = os.join_path(os.vtmp_dir(), 'live_tests') const main_source_file = os.join_path(vtmp_folder, 'main.v') const tmp_file = os.join_path(vtmp_folder, 'mymodule', 'generated_live_module.tmp') const source_file = os.join_path(vtmp_folder, 'mymodule', 'mymodule.v') -const genexe_file = os.join_path(vtmp_folder, 'generated_live_program') +const genexe_file = os.join_path(vtmp_folder, 'generated_live_program.exe') const output_file = os.join_path(vtmp_folder, 'generated_live_program.output.txt') const res_original_file = os.join_path(vtmp_folder, 'ORIGINAL.txt') const res_changed_file = os.join_path(vtmp_folder, 'CHANGED.txt') @@ -46,7 +46,7 @@ const live_program_source = get_source_template() fn get_source_template() string { src := os.read_file(os.join_path(os.dir(@FILE), 'live_test_template.vv')) or { panic(err) } - return src.replace('#OUTPUT_FILE#', output_file) + return src.replace('#OUTPUT_FILE#', output_file.replace('\\', '\\\\')) } fn atomic_write_source(source string) { @@ -168,19 +168,30 @@ fn setup_cycles_environment() { os.setenv('WAIT_CYCLES', '${max_wait_cycles}', true) } -// +fn run_in_background(cmd string) { + spawn fn (cmd string) { + res := os.execute(cmd) + if res.exit_code != 0 { + eprintln('----------------------- background command failed: --------------------------') + eprintln('----- exit_code: ${res.exit_code}, cmd: ${cmd}, output:') + eprintln(res.output) + eprintln('-----------------------------------------------------------------------------') + } + assert res.exit_code == 0 + }(cmd) + time.sleep(1000 * time.millisecond) + eprintln('... run_in_background, cmd: ${cmd}') +} + fn test_live_program_can_be_compiled() { setup_cycles_environment() eprintln('Compiling...') compile_cmd := '${os.quoted_path(vexe)} -cg -keepc -nocolor -live -o ${os.quoted_path(genexe_file)} ${os.quoted_path(main_source_file)}' eprintln('> compile_cmd: ${compile_cmd}') - os.system(compile_cmd) - - cmd := '${os.quoted_path(genexe_file)} > /dev/null &' - eprintln('Running with: ${cmd}') - res := os.system(cmd) - assert res == 0 - eprintln('... running in the background') + time.sleep(1000 * time.millisecond) // improve chances of working on windows + compile_res := os.system(compile_cmd) + assert compile_res == 0 + run_in_background('${os.quoted_path(genexe_file)}') wait_for_file('ORIGINAL') }