| 1 | import os |
| 2 | |
| 3 | const vexe = @VEXE |
| 4 | const tests_dir = os.dir(@FILE) |
| 5 | const v3_dir = os.dir(tests_dir) |
| 6 | const vlib_dir = os.dir(v3_dir) |
| 7 | const v3_src = os.join_path(v3_dir, 'v3.v') |
| 8 | |
| 9 | fn write_project_file(root string, rel string, src string) { |
| 10 | path := os.join_path(root, rel) |
| 11 | os.mkdir_all(os.dir(path)) or { panic(err) } |
| 12 | os.write_file(path, src) or { panic(err) } |
| 13 | } |
| 14 | |
| 15 | fn test_qualified_positional_struct_init_keeps_later_imported_fn() { |
| 16 | v3_bin := os.join_path(os.temp_dir(), 'v3_qualified_positional_struct_init_test') |
| 17 | build := |
| 18 | os.execute('${vexe} -gc none -path "${vlib_dir}|@vlib|@vmodules" -o ${v3_bin} ${v3_src}') |
| 19 | assert build.exit_code == 0, build.output |
| 20 | |
| 21 | root := os.join_path(os.temp_dir(), 'v3_qualified_positional_struct_init_project') |
| 22 | if os.exists(root) { |
| 23 | os.rmdir_all(root) or { panic(err) } |
| 24 | } |
| 25 | os.mkdir_all(root) or { panic(err) } |
| 26 | write_project_file(root, 'main.v', 'module main |
| 27 | |
| 28 | import m |
| 29 | |
| 30 | fn main() { |
| 31 | assert m.after() == 10 |
| 32 | } |
| 33 | ') |
| 34 | write_project_file(root, 'm/m.v', 'module m |
| 35 | |
| 36 | import geom |
| 37 | |
| 38 | const shade = geom.Color{1.0, 2.0, 3.0, 4.0} |
| 39 | |
| 40 | pub fn after() int { |
| 41 | return int(shade.r + shade.g + shade.b + shade.a) |
| 42 | } |
| 43 | ') |
| 44 | write_project_file(root, 'geom/geom.v', 'module geom |
| 45 | |
| 46 | pub struct Color { |
| 47 | pub: |
| 48 | r f64 |
| 49 | g f64 |
| 50 | b f64 |
| 51 | a f64 |
| 52 | } |
| 53 | ') |
| 54 | |
| 55 | bin := os.join_path(os.temp_dir(), 'v3_qualified_positional_struct_init_bin') |
| 56 | main_path := os.join_path(root, 'main.v') |
| 57 | compile := os.execute('${v3_bin} ${main_path} -b c -o ${bin}') |
| 58 | assert compile.exit_code == 0, compile.output |
| 59 | assert !compile.output.contains('unknown function `m.after`'), compile.output |
| 60 | assert !compile.output.contains('C compilation failed'), compile.output |
| 61 | c_code := os.read_file(bin + '.c') or { panic(err) } |
| 62 | assert c_code.contains('(geom__Color){'), c_code |
| 63 | run := os.execute(bin) |
| 64 | assert run.exit_code == 0, run.output |
| 65 | } |
| 66 | |