| 1 | import os |
| 2 | |
| 3 | const vtmp_folder = os.join_path(os.vtmp_dir(), 'run_v_code_tests') |
| 4 | const vexe = os.getenv('VEXE') |
| 5 | |
| 6 | @[markused] |
| 7 | const turn_off_vcolors = os.setenv('VCOLORS', 'never', true) |
| 8 | |
| 9 | fn test_vexe_is_set() { |
| 10 | assert vexe != '' |
| 11 | } |
| 12 | |
| 13 | fn pipe_to_v_run() ! { |
| 14 | os.mkdir_all(vtmp_folder) or {} |
| 15 | defer { |
| 16 | os.rmdir_all(vtmp_folder) or {} |
| 17 | } |
| 18 | cat_cmd := if os.user_os() == 'windows' { 'cmd /c type' } else { 'cat' } |
| 19 | tmp_v_file := os.join_path(os.real_path(vtmp_folder), 'generated_piped_program.v') |
| 20 | // eprintln('>>> tmp_v_file: ${tmp_v_file}') |
| 21 | os.write_file(tmp_v_file, 'println(1 + 3)\nprintln("hello")\n')! |
| 22 | assert os.is_file(tmp_v_file) |
| 23 | cmd := '${cat_cmd} ${os.quoted_path(tmp_v_file)} | ${os.quoted_path(vexe)} run -' |
| 24 | res := os.execute(cmd) |
| 25 | // eprintln('>> cmd: ${cmd} | res: ${res}') |
| 26 | assert res.exit_code == 0 |
| 27 | assert res.output.replace('\r', '').trim_space().split('\n') == ['4', 'hello'] |
| 28 | os.rm(tmp_v_file) or { panic(err) } |
| 29 | assert !os.exists(tmp_v_file) |
| 30 | } |
| 31 | |
| 32 | fn test_pipe_to_v_run() { |
| 33 | pipe_to_v_run() or { panic(err) } |
| 34 | } |
| 35 | |