Skip to content

Commit 24c3d25

Browse files
committed
v2.eval: reuse eval test runner in tests
1 parent 8fc6e03 commit 24c3d25

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

‎vlib/v2/eval/eval_test.v‎

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,41 @@ import os
44
import v2.parser
55
import v2.pref
66
import v2.token
7+
import time
8+
9+
fn eval_backend_tmp_dir() string {
10+
return os.join_path(os.temp_dir(), 'v2_eval_integration_${os.getpid()}')
11+
}
12+
13+
fn ensure_eval_backend_runner(vexe string) !string {
14+
tmp_dir := eval_backend_tmp_dir()
15+
os.mkdir_all(tmp_dir)!
16+
v2_exe := os.join_path(tmp_dir, 'v2_eval_runner')
17+
if os.exists(v2_exe) {
18+
return v2_exe
19+
}
20+
vroot := os.dir(vexe)
21+
build_res := os.execute('${os.quoted_path(vexe)} -o ${os.quoted_path(v2_exe)} ${os.quoted_path(os.join_path(vroot,
22+
'cmd', 'v2', 'v2.v'))}')
23+
if build_res.exit_code != 0 {
24+
return error(build_res.output)
25+
}
26+
return v2_exe
27+
}
728

829
fn run_eval_backend(code string) !os.Result {
930
vexe := os.getenv('VEXE')
1031
if vexe == '' {
1132
return error('VEXE is not set')
1233
}
13-
vroot := os.dir(vexe)
14-
tmp_dir := os.join_path(os.temp_dir(), 'v2_eval_integration_${os.getpid()}')
15-
os.rmdir_all(tmp_dir) or {}
34+
tmp_dir := eval_backend_tmp_dir()
1635
os.mkdir_all(tmp_dir)!
17-
defer {
18-
os.rmdir_all(tmp_dir) or {}
19-
}
20-
tmp_file := os.join_path(tmp_dir, 'sample.v')
21-
v2_exe := os.join_path(tmp_dir, 'v2_eval_runner')
36+
tmp_file := os.join_path(tmp_dir, 'sample_${time.now().unix_micro()}.v')
2237
os.write_file(tmp_file, code)!
23-
build_res := os.execute('${os.quoted_path(vexe)} -o ${os.quoted_path(v2_exe)} ${os.quoted_path(os.join_path(vroot,
24-
'cmd', 'v2', 'v2.v'))}')
25-
if build_res.exit_code != 0 {
26-
return error(build_res.output)
38+
defer {
39+
os.rm(tmp_file) or {}
2740
}
41+
v2_exe := ensure_eval_backend_runner(vexe)!
2842
return os.execute('${os.quoted_path(v2_exe)} -backend eval ${os.quoted_path(tmp_file)}')
2943
}
3044

0 commit comments

Comments
 (0)