11import os
22import v.vmod
33
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.
74const (
85 // Expect has to be installed for the test.
96 expect_exe = os.quoted_path (os.find_abs_path_of_executable ('expect' ) or {
107 eprintln ('skipping test, since expect is missing' )
118 exit (0 )
129 })
13- // Directory where the Expect scripts will create projects.
14- test_module_path = os.join_path (os.vtmp_dir (), 'v' , 'test_vcreate_input' )
1510 // Directory that contains the Expect scripts used in the test.
1611 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' )
1717)
1818
1919fn testsuite_begin () {
@@ -22,6 +22,10 @@ fn testsuite_begin() {
2222 dump (expect_tests_path)
2323}
2424
25+ fn testsuite_end () {
26+ os.rmdir_all (test_module_path) or {}
27+ }
28+
2529fn prepare_test_path () ! {
2630 os.rmdir_all (test_module_path) or {}
2731 os.mkdir_all (test_module_path) or {}
@@ -36,10 +40,7 @@ fn test_new_with_no_arg_input() {
3640 assert false , res.output
3741 }
3842 // 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 {
4344 assert false , err.str ()
4445 return
4546 }
@@ -57,10 +58,7 @@ fn test_new_with_name_arg_input() {
5758 assert false , res.output
5859 }
5960 // 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 {
6462 assert false , err.str ()
6563 return
6664 }
@@ -79,10 +77,7 @@ fn test_new_with_model_arg_input() {
7977 assert false , res.output
8078 }
8179 // 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 {
8681 assert false , err.str ()
8782 return
8883 }
@@ -96,25 +91,17 @@ fn test_v_init_in_dir_with_invalid_mod_name() {
9691 // A project with a directory name with hyphens, which is invalid for a module name.
9792 dir_name_with_invalid_mod_name := 'my-proj'
9893 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)
10095 os.mkdir_all (proj_path) or {}
10196 os.chdir (proj_path)!
10297 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} ' )
10398 if res.exit_code != 0 {
10499 assert false , res.output
105100 }
106101 // 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 {
111103 assert false , err.str ()
112104 return
113105 }
114106 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 {}
120107}
0 commit comments