vxx2 / vlib / v3 / tests / selfhost_backend_prune_test.v
45 lines · 40 sloc · 1.93 KB · 05135764f85a9fbf85752c24673a8232e3d3cc26
Raw
1import os
2
3const vexe = @VEXE
4const tests_dir = os.dir(@FILE)
5const v3_dir = os.dir(tests_dir)
6const v3_src = os.join_path(v3_dir, 'v3.v')
7
8fn build_selfhost_prune_v3() string {
9 v3_bin := os.join_path(os.temp_dir(), 'v3_selfhost_backend_prune_boot_${os.getpid()}')
10 os.rm(v3_bin) or {}
11 build :=
12 os.execute('${os.quoted_path(vexe)} -o ${os.quoted_path(v3_bin)} ${os.quoted_path(v3_src)}')
13 assert build.exit_code == 0, build.output
14 return v3_bin
15}
16
17fn selfhost_to_c(v3_bin string, name string, flags string) string {
18 out_bin := os.join_path(os.temp_dir(), 'v3_selfhost_backend_prune_${name}_${os.getpid()}')
19 out_c := out_bin + '.c'
20 os.rm(out_bin) or {}
21 os.rm(out_c) or {}
22 cmd := '${os.quoted_path(v3_bin)} --no-parallel -selfhost ${flags} -o ${os.quoted_path(out_bin)} ${os.quoted_path(v3_src)}'
23 res := os.execute(cmd)
24 assert res.exit_code == 0, res.output
25 assert os.exists(out_c), 'missing generated C output ${out_c}'
26 return os.read_file(out_c) or { panic(err) }
27}
28
29fn test_selfhost_default_prunes_optional_backends() {
30 v3_bin := build_selfhost_prune_v3()
31 c_src := selfhost_to_c(v3_bin, 'default', '')
32 assert !c_src.contains('v3__gen__wasm__'), 'default self-host compiled the wasm backend'
33 assert !c_src.contains('v3__gen__arm64__'), 'default self-host compiled the arm64 backend'
34 assert !c_src.contains('v3__ssa__'), 'default self-host compiled the SSA backend'
35 assert !c_src.contains('v3__eval__'), 'default self-host compiled the eval backend'
36}
37
38fn test_selfhost_compile_backend_wasm_opts_wasm_back_in() {
39 v3_bin := build_selfhost_prune_v3()
40 c_src := selfhost_to_c(v3_bin, 'wasm', '-compile-backend wasm')
41 assert c_src.contains('v3__gen__wasm__Gen__new'), 'wasm backend was not compiled after opt-in'
42 assert !c_src.contains('v3__gen__arm64__'), 'wasm opt-in compiled the arm64 backend'
43 assert !c_src.contains('v3__ssa__'), 'wasm opt-in compiled the SSA backend'
44 assert !c_src.contains('v3__eval__'), 'wasm opt-in compiled the eval backend'
45}
46