vxx / vlib / v / tests / skip_unused / interface_dispatch_method_dependencies_test.v
48 lines · 46 sloc · 969 bytes · e13a7085188ab8fa5d9a4713cfed6f00477010b7
Raw
1import os
2
3const vexe = @VEXE
4
5fn test_skip_unused_walks_mut_interface_dispatch_method_dependencies() {
6 tmp_dir := os.join_path(os.vtmp_dir(), 'v_issue_27404')
7 os.mkdir_all(tmp_dir) or { panic(err) }
8 defer {
9 os.rmdir_all(tmp_dir) or {}
10 }
11 source_path := os.join_path(tmp_dir, 'issue_27404.v')
12 binary_path := os.join_path(tmp_dir, 'issue_27404')
13 source := [
14 'module main',
15 '',
16 'interface Visitor {',
17 '\tvisit()',
18 '}',
19 '',
20 'struct Han {',
21 'mut:',
22 '\tn int',
23 '}',
24 '',
25 'fn helper(s string) {',
26 '\tprintln(s)',
27 '}',
28 '',
29 'fn (mut h Han) visit() {',
30 "\thelper('t')",
31 '}',
32 '',
33 'fn run(mut v Visitor) {',
34 '\tv.visit()',
35 '}',
36 '',
37 'fn main() {',
38 '\tmut h := Han{}',
39 '\trun(mut h)',
40 '}',
41 ].join('\n')
42 os.write_file(source_path, source) or { panic(err) }
43 res :=
44 os.execute('${os.quoted_path(vexe)} -o ${os.quoted_path(binary_path)} ${os.quoted_path(source_path)}')
45 if res.exit_code != 0 {
46 panic(res.output)
47 }
48}
49