Skip to content

Commit

Permalink
fix live_test.v on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Jan 3, 2025
1 parent aa16e41 commit 225d319
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions vlib/v/live/live_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) {
Expand Down Expand Up @@ -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')
}

Expand Down

0 comments on commit 225d319

Please sign in to comment.