v2 / vlib / v / tests / hyphenated_module_path_test.v
38 lines · 34 sloc · 918 bytes · e0441fb5342f8c613daae9c1da2269c32fa078aa
Raw
1import os
2import rand
3
4const vexe = @VEXE
5
6fn test_module_in_hyphenated_parent_path_compiles() {
7 test_root := os.join_path(os.vtmp_dir(), 'hyphenated_module_path_${rand.ulid()}')
8 module_dir := os.join_path(test_root, 'some-dir', 'somemodule')
9 os.mkdir_all(module_dir)!
10 defer {
11 os.rmdir_all(test_root) or {}
12 }
13 os.write_file(os.join_path(module_dir, 'somemodule.v'), 'module somemodule
14
15pub fn value() int {
16 return 3
17}
18')!
19 os.write_file(os.join_path(module_dir, 'some_test.v'), 'module somemodule
20
21fn test_value() {
22 assert value() == 3
23}
24')!
25 old_wd := os.getwd()
26 defer {
27 os.chdir(old_wd) or {}
28 }
29 os.chdir(test_root)!
30 module_path := os.join_path('some-dir', 'somemodule')
31 cmd := '${os.quoted_path(vexe)} test ${os.quoted_path(module_path)}'
32 res := os.execute(cmd)
33 if res.exit_code != 0 {
34 eprintln('> failing test cmd: ${cmd}')
35 eprintln('> output:\n${res.output}')
36 }
37 assert res.exit_code == 0
38}
39