v2 / vlib / v / tests / run_v_code_from_stdin_test.v
34 lines · 29 sloc · 1.0 KB · 2332ecff4811b8c97dfda8e825170e9397962519
Raw
1import os
2
3const vtmp_folder = os.join_path(os.vtmp_dir(), 'run_v_code_tests')
4const vexe = os.getenv('VEXE')
5
6@[markused]
7const turn_off_vcolors = os.setenv('VCOLORS', 'never', true)
8
9fn test_vexe_is_set() {
10 assert vexe != ''
11}
12
13fn 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
32fn test_pipe_to_v_run() {
33 pipe_to_v_run() or { panic(err) }
34}
35