1
1
import os
2
2
import v.vmod
3
3
4
- // Running tests appends a tsession path to VTMP, which is automatically cleaned up after the test.
5
- // The following will result in e.g. `$VTMP/tsession_7fe8e93bd740_1612958707536/test-vmodules/`.
6
- const test_path = os.join_path (os.vtmp_dir (), 'test-vmodules' )
4
+ const (
5
+ v = os.quoted_path (@VEXE)
6
+ // Running tests appends a tsession path to VTMP, which is automatically cleaned up after the test.
7
+ // The following will result in e.g. `$VTMP/tsession_7fe8e93bd740_1612958707536/test-vmodules/`.
8
+ test_path = os.join_path (os.vtmp_dir (), 'test-vmodules' )
9
+ )
7
10
8
11
fn testsuite_begin () {
9
12
os.setenv ('VMODULES' , test_path, true )
@@ -13,21 +16,8 @@ fn testsuite_end() {
13
16
os.rmdir_all (test_path) or {}
14
17
}
15
18
16
- fn test_install_from_git_url () {
17
- res := os.execute (@VEXE + ' install https://github.com/vlang/markdown' )
18
- assert res.exit_code == 0 , res.output
19
- mod := vmod.from_file (os.join_path (test_path, 'markdown' , 'v.mod' )) or {
20
- assert false , err.str ()
21
- return
22
- }
23
- assert mod.name == 'markdown'
24
- assert mod.dependencies == []string {}
25
- assert res.output.contains ('Installing module "markdown" from "https://github.com/vlang/markdown' )
26
- assert res.output.contains ('Relocating module from "vlang/markdown" to "markdown"' )
27
- }
28
-
29
19
fn test_install_from_vpm_ident () {
30
- res := os.execute (@VEXE + ' install nedpals.args' )
20
+ res := os.execute (' ${v} install nedpals.args' )
31
21
assert res.exit_code == 0 , res.output
32
22
mod := vmod.from_file (os.join_path (test_path, 'nedpals' , 'args' , 'v.mod' )) or {
33
23
assert false , err.str ()
@@ -38,7 +28,7 @@ fn test_install_from_vpm_ident() {
38
28
}
39
29
40
30
fn test_install_from_vpm_short_ident () {
41
- res := os.execute (@VEXE + ' install pcre' )
31
+ res := os.execute (' ${v} install pcre' )
42
32
assert res.exit_code == 0 , res.output
43
33
mod := vmod.from_file (os.join_path (test_path, 'pcre' , 'v.mod' )) or {
44
34
assert false , err.str ()
@@ -48,28 +38,78 @@ fn test_install_from_vpm_short_ident() {
48
38
assert mod.description == 'A simple regex library for V.'
49
39
}
50
40
51
- fn test_install_already_existant () {
52
- // Skip on windows for now due permission errors with rmdir.
41
+ fn test_install_from_git_url () {
42
+ res := os.execute ('${v} install https://github.com/vlang/markdown' )
43
+ assert res.exit_code == 0 , res.output
44
+ assert res.output.contains ('Installing module "markdown" from "https://github.com/vlang/markdown' )
45
+ assert res.output.contains ('Relocating module from "vlang/markdown" to "markdown"' )
46
+ mod := vmod.from_file (os.join_path (test_path, 'markdown' , 'v.mod' )) or {
47
+ assert false , err.str ()
48
+ return
49
+ }
50
+ assert mod.name == 'markdown'
51
+ assert mod.dependencies == []string {}
52
+ }
53
+
54
+ fn test_install_already_existent () {
55
+ // FIXME: Skip this for now on Windows, as `rmdir_all` results in permission
56
+ // errors when vpm tries to remove existing modules.
53
57
$if windows {
54
58
return
55
59
}
56
- mod_url := 'https://github.com/vlang/markdown'
57
- mut res := os.execute (@VEXE + ' install ${mod_url} ' )
58
- assert res.exit_code == 0 , res.output
59
- res = os.execute (@VEXE + ' install ${mod_url} ' )
60
+ mut res := os.execute ('${v} install https://github.com/vlang/markdown' )
60
61
assert res.exit_code == 0 , res.output
62
+ assert res.output.contains ('already exists' )
61
63
mod := vmod.from_file (os.join_path (test_path, 'markdown' , 'v.mod' )) or {
62
64
assert false , err.str ()
63
65
return
64
66
}
65
67
assert mod.name == 'markdown'
66
68
assert mod.dependencies == []string {}
67
- assert res.output.contains ('already exists' )
69
+ }
70
+
71
+ fn test_install_once () {
72
+ // Start with a clean test path.
73
+ $if windows {
74
+ // FIXME: Workaround for failing `rmdir` commands on Windows.
75
+ os.system ('rd /s /q ${test_path} ' )
76
+ } $else {
77
+ os.rmdir_all (test_path) or {}
78
+ }
79
+ os.mkdir_all (test_path) or {}
80
+
81
+ // Install markdown module.
82
+ mut res := os.execute ('${v} install markdown' )
83
+ assert res.exit_code == 0 , res.output
84
+ // Keep track of the last modified state of the v.mod file of the installed markdown module.
85
+ md_last_modified := os.file_last_mod_unix (os.join_path (test_path, 'markdown' , 'v.mod' ))
86
+
87
+ install_cmd := '${@VEXE} install https://github.com/vlang/markdown https://github.com/vlang/pcre --once -v'
88
+ // Try installing two modules, one of which is already installed.
89
+ res = os.execute (install_cmd)
90
+ assert res.exit_code == 0 , res.output
91
+ assert res.output.contains ("Already installed modules: ['markdown']" )
92
+ mod := vmod.from_file (os.join_path (test_path, 'pcre' , 'v.mod' )) or {
93
+ assert false , err.str ()
94
+ return
95
+ }
96
+ assert mod.name == 'pcre'
97
+ assert mod.description == 'A simple regex library for V.'
98
+ // Ensure the before installed markdown module wasn't modified.
99
+ assert md_last_modified == os.file_last_mod_unix (os.join_path (test_path, 'markdown' ,
100
+ 'v.mod' ))
101
+
102
+ // Try installing two modules that are both already installed.
103
+ res = os.execute (install_cmd)
104
+ assert res.exit_code == 0 , res.output
105
+ assert res.output.contains ('All modules are already installed.' )
106
+ assert md_last_modified == os.file_last_mod_unix (os.join_path (test_path, 'markdown' ,
107
+ 'v.mod' ))
68
108
}
69
109
70
110
fn test_missing_repo_name_in_url () {
71
111
incomplete_url := 'https://github.com/vlang'
72
- res := os.execute (@VEXE + ' install ${incomplete_url} ' )
112
+ res := os.execute (' ${v} install ${incomplete_url} ' )
73
113
assert res.exit_code == 1
74
114
assert res.output.trim_space () == 'Errors while retrieving module name for: "${incomplete_url} "'
75
115
}
0 commit comments