1
1
import os
2
2
import v.vmod
3
3
4
- // Note: the following uses `test_vcreate` and NOT `vcreate_input_test` deliberately,
5
- // to both avoid confusions with the name of the current test itself, and to
6
- // avoid clashes with the postfix `_test.v`, that V uses for its own test files.
7
4
const (
8
5
// Expect has to be installed for the test.
9
6
expect_exe = os.quoted_path (os.find_abs_path_of_executable ('expect' ) or {
10
7
eprintln ('skipping test, since expect is missing' )
11
8
exit (0 )
12
9
})
13
- // Directory where the Expect scripts will create projects.
14
- test_module_path = os.join_path (os.vtmp_dir (), 'v' , 'test_vcreate_input' )
15
10
// Directory that contains the Expect scripts used in the test.
16
11
expect_tests_path = os.join_path (@VMODROOT, 'cmd' , 'tools' , 'vcreate' , 'tests' )
12
+ // Running tests appends a tsession path to VTMP, which is automatically cleaned up after the test.
13
+ // The following will result in e.g. `$VTMP/tsession_7fe8e93bd740_1612958707536/test_vcreate_input/`.
14
+ // Note: The following uses `test_vcreate_input` deliberately and NOT `vcreate_input_test`.
15
+ // This avoids clashes with the `_test` postfix, which V also uses for test file binaries.
16
+ test_module_path = os.join_path (os.vtmp_dir (), 'test_vcreate_input' )
17
17
)
18
18
19
19
fn testsuite_begin () {
@@ -22,6 +22,10 @@ fn testsuite_begin() {
22
22
dump (expect_tests_path)
23
23
}
24
24
25
+ fn testsuite_end () {
26
+ os.rmdir_all (test_module_path) or {}
27
+ }
28
+
25
29
fn prepare_test_path () ! {
26
30
os.rmdir_all (test_module_path) or {}
27
31
os.mkdir_all (test_module_path) or {}
@@ -36,10 +40,7 @@ fn test_new_with_no_arg_input() {
36
40
assert false , res.output
37
41
}
38
42
// Assert mod data set in `new_no_arg.expect`.
39
- mod := vmod.decode (os.read_file (os.join_path (test_module_path, project_name, 'v.mod' )) or {
40
- assert false , 'Failed reading v.mod of ${project_name} '
41
- return
42
- }) or {
43
+ mod := vmod.from_file (os.join_path (test_module_path, project_name, 'v.mod' )) or {
43
44
assert false , err.str ()
44
45
return
45
46
}
@@ -57,10 +58,7 @@ fn test_new_with_name_arg_input() {
57
58
assert false , res.output
58
59
}
59
60
// Assert mod data set in `new_with_name_arg.expect`.
60
- mod := vmod.decode (os.read_file (os.join_path (test_module_path, project_name, 'v.mod' )) or {
61
- assert false , 'Failed reading v.mod of ${project_name} '
62
- return
63
- }) or {
61
+ mod := vmod.from_file (os.join_path (test_module_path, project_name, 'v.mod' )) or {
64
62
assert false , err.str ()
65
63
return
66
64
}
@@ -79,10 +77,7 @@ fn test_new_with_model_arg_input() {
79
77
assert false , res.output
80
78
}
81
79
// Assert mod data set in `new_with_model_arg.expect`.
82
- mod := vmod.decode (os.read_file (os.join_path (test_module_path, project_name, 'v.mod' )) or {
83
- assert false , 'Failed reading v.mod of ${project_name} '
84
- return
85
- }) or {
80
+ mod := vmod.from_file (os.join_path (test_module_path, project_name, 'v.mod' )) or {
86
81
assert false , err.str ()
87
82
return
88
83
}
@@ -96,25 +91,17 @@ fn test_v_init_in_dir_with_invalid_mod_name() {
96
91
// A project with a directory name with hyphens, which is invalid for a module name.
97
92
dir_name_with_invalid_mod_name := 'my-proj'
98
93
corrected_mod_name := 'my_proj'
99
- proj_path := os.join_path (os.vtmp_dir (), 'v' , dir_name_with_invalid_mod_name)
94
+ proj_path := os.join_path (os.vtmp_dir (), dir_name_with_invalid_mod_name)
100
95
os.mkdir_all (proj_path) or {}
101
96
os.chdir (proj_path)!
102
97
res := os.execute ('${expect_exe} ${os.join_path(expect_tests_path, 'init_in_dir_with_invalid_mod_name.expect')} ${@VMODROOT} ${dir_name_with_invalid_mod_name} ${corrected_mod_name} ' )
103
98
if res.exit_code != 0 {
104
99
assert false , res.output
105
100
}
106
101
// Assert mod data set in `new_with_model_arg.expect`.
107
- mod := vmod.decode (os.read_file (os.join_path (proj_path, 'v.mod' )) or {
108
- assert false , 'Failed reading v.mod of ${proj_path} '
109
- return
110
- }) or {
102
+ mod := vmod.from_file (os.join_path (proj_path, 'v.mod' )) or {
111
103
assert false , err.str ()
112
104
return
113
105
}
114
106
assert mod.name == corrected_mod_name
115
- os.rmdir_all (proj_path) or {}
116
- }
117
-
118
- fn testsuite_end () {
119
- os.rmdir_all (test_module_path) or {}
120
107
}
0 commit comments