v2 / vlib / v / tests / relative_nested_module_lookup_test.v
33 lines · 32 sloc · 1.14 KB · e2e5cf8db56f3562c7baa735061690be936bdf3e
Raw
1import os
2
3fn test_nested_module_lookup_works_with_relative_paths() {
4 os.setenv('VCOLORS', 'never', true)
5 wd := os.getwd()
6 root_name := '.tmp_relative_nested_module_lookup'
7 root := os.join_path(wd, root_name)
8 main_path := os.join_path(root, 'main.v')
9 rel_main_path := os.join_path(root_name, 'main.v')
10 mod_dir := os.join_path(root, 'mod')
11 v2_dir := os.join_path(mod_dir, 'v2')
12 os.rmdir_all(root) or {}
13 os.mkdir_all(v2_dir) or { panic(err) }
14 defer {
15 os.rmdir_all(root) or {}
16 }
17 os.write_file(main_path,
18 'import mod\nimport mod.v2\n\nfn main() {\n\tmod.print_version()\n\tv2.print_version()\n}\n') or {
19 panic(err)
20 }
21 os.write_file(os.join_path(mod_dir, 'mod.v'),
22 "module mod\n\nconst version = 'v1'\n\npub fn print_version() {\n\tprintln(mod.version)\n}\n") or {
23 panic(err)
24 }
25 os.write_file(os.join_path(v2_dir, 'mod.v'),
26 "module v2\n\nconst version = 'v2'\n\npub fn print_version() {\n\tprintln(v2.version)\n}\n") or {
27 panic(err)
28 }
29 cmd := '${os.quoted_path(@VEXE)} run ${os.quoted_path(rel_main_path)}'
30 res := os.execute(cmd)
31 assert res.exit_code == 0, res.output
32 assert res.output.replace('\r\n', '\n').trim_space() == 'v1\nv2'
33}
34