Skip to content

Commit b9d0aed

Browse files
authored
tools: cleanup vcreate tests (#19666)
1 parent fd04c9d commit b9d0aed

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

cmd/tools/vcreate/vcreate_input_test.v

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import os
22
import 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.
74
const (
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

1919
fn 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+
2529
fn 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
}

cmd/tools/vcreate/vcreate_test.v

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import os
2-
import v.vmod
32

4-
// Note: the following uses `test_vcreate` and NOT `vcreate_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-
const test_path = os.join_path(os.vtmp_dir(), 'v', 'test_vcreate')
3+
const (
4+
test_project_dir_name = 'test_project'
5+
// Running tests appends a tsession path to VTMP, which is automatically cleaned up after the test.
6+
// The following will result in e.g. `$VTMP/tsession_7fe8e93bd740_1612958707536/test_project/`.
7+
// Note: The following uses `test_vcreate` deliberately and NOT `vcreate_test`.
8+
// This avoids clashes with the `_test` postfix, which V also uses for test file binaries.
9+
test_path = os.join_path(os.vtmp_dir(), test_project_dir_name)
10+
)
11+
12+
fn testsuite_end() {
13+
os.rmdir_all(test_path) or {}
14+
}
815

916
fn init_and_check() ! {
1017
os.chdir(test_path)!
@@ -35,7 +42,7 @@ fn init_and_check() ! {
3542

3643
assert os.read_file('v.mod')! == [
3744
'Module {',
38-
" name: 'test_vcreate'",
45+
" name: '${test_project_dir_name}'",
3946
" description: ''",
4047
" version: ''",
4148
" license: ''",
@@ -47,7 +54,7 @@ fn init_and_check() ! {
4754
assert os.read_file('.gitignore')! == [
4855
'# Binaries for programs and plugins',
4956
'main',
50-
'test_vcreate',
57+
'${test_project_dir_name}',
5158
'*.exe',
5259
'*.exe~',
5360
'*.so',
@@ -139,7 +146,3 @@ indent_style = tab
139146
assert os.read_file('.gitattributes')! == git_attributes_content
140147
assert os.read_file('.editorconfig')! == editor_config_content
141148
}
142-
143-
fn testsuite_end() {
144-
os.rmdir_all(test_path) or {}
145-
}

0 commit comments

Comments
 (0)