/
install_test.v
257 lines (236 loc) · 9.06 KB
/
install_test.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
// vtest retry: 3
module main
import os
import rand
import v.vmod
import test_utils
// Running tests appends a tsession path to VTMP, which is automatically cleaned up after the test.
// The following will result in e.g. `$VTMP/tsession_7fe8e93bd740_1612958707536/test-vmodules/`.
const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_test_${rand.ulid()}')
fn testsuite_begin() {
test_utils.set_test_env(test_path)
}
fn testsuite_end() {
os.rmdir_all(test_path) or {}
}
fn get_vmod(path string) vmod.Manifest {
return vmod.from_file(os.join_path(test_path, path, 'v.mod')) or {
eprintln('Failed to parse v.mod for `${path}`. ${err}')
exit(1)
}
}
fn test_install_from_vpm_ident() {
res := os.execute('${vexe} install nedpals.args')
assert res.exit_code == 0, res.str()
assert res.output.contains('Skipping download count increment for `nedpals.args`.'), res.output
manifest := get_vmod(os.join_path('nedpals', 'args'))
assert manifest.name == 'nedpals.args'
assert manifest.dependencies == []string{}
}
fn test_install_from_vpm_short_ident() {
res := os.execute('${vexe} install pcre')
assert res.exit_code == 0, res.str()
manifest := get_vmod('pcre')
assert manifest.name == 'pcre'
assert manifest.description == 'A simple regex library for V.'
}
fn test_install_from_git_url() {
mut res := os.execute('${vexe} install https://github.com/vlang/markdown')
assert res.exit_code == 0, res.str()
assert res.output.contains('Installing `markdown`'), res.output
mut manifest := get_vmod('markdown')
assert manifest.name == 'markdown'
assert manifest.dependencies == []string{}
res = os.execute('${vexe} install http://github.com/Wertzui123/HashMap')
assert res.exit_code == 0, res.str()
assert res.output.contains('Installing `HashMap`'), res.output
assert res.output.contains('`http` is deprecated'), res.output
manifest = get_vmod(os.join_path('wertzui123', 'hashmap'))
res = os.execute('${vexe} install http://github.com/Wertzui123/HashMap')
assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `wertzui123.hashmap`'), res.output
assert res.output.contains('`http` is deprecated'), res.output
res = os.execute('${vexe} install https://gitlab.com/tobealive/webview')
assert res.exit_code == 0, res.str()
assert res.output.contains('Installed `webview`'), res.output
}
fn test_install_already_existent() {
mut res := os.execute('${vexe} install https://github.com/vlang/markdown')
assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `markdown`'), res.output
manifest := get_vmod('markdown')
assert manifest.name == 'markdown'
assert manifest.dependencies == []string{}
// The same module but with the `.git` extension added.
res = os.execute('${vexe} install https://github.com/vlang/markdown.git')
assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `markdown`'), res.output
}
fn test_install_once() {
// Start with a clean test path.
$if windows {
// FIXME: Workaround for failing `rmdir` commands on Windows.
os.system('rd /s /q ${test_path}')
} $else {
os.rmdir_all(test_path) or {}
}
os.mkdir_all(test_path) or {}
// Install markdown module.
mut res := os.execute('${vexe} install markdown')
assert res.exit_code == 0, res.str()
// Keep track of the last modified state of the v.mod file of the installed markdown module.
md_last_modified := os.file_last_mod_unix(os.join_path(test_path, 'markdown', 'v.mod'))
install_cmd := '${@VEXE} install https://github.com/vlang/markdown https://github.com/vlang/pcre --once -v'
// Try installing two modules, one of which is already installed.
res = os.execute(install_cmd)
assert res.exit_code == 0, res.str()
assert res.output.contains("Already installed modules: ['markdown']"), res.output
manifest := get_vmod('pcre')
assert manifest.name == 'pcre'
assert manifest.description == 'A simple regex library for V.'
// Ensure the before installed markdown module wasn't modified.
assert md_last_modified == os.file_last_mod_unix(os.join_path(test_path, 'markdown',
'v.mod'))
// Try installing two modules that are both already installed.
res = os.execute(install_cmd)
assert res.exit_code == 0, res.str()
assert res.output.contains('All modules are already installed.'), res.output
assert md_last_modified == os.file_last_mod_unix(os.join_path(test_path, 'markdown',
'v.mod'))
}
fn test_missing_repo_name_in_url() {
incomplete_url := 'https://github.com/vlang'
res := os.execute('${vexe} install ${incomplete_url}')
assert res.exit_code == 1
assert res.output.contains('failed to retrieve module name for `${incomplete_url}`'), res.output
}
fn test_manifest_detection() {
// head branch == `main`.
mut manifest := fetch_manifest('v-analyzer', 'https://github.com/v-analyzer/v-analyzer',
'', true) or {
assert false
return
}
assert manifest.name == 'v-analyzer'
assert manifest.dependencies == ['https://github.com/v-analyzer/v-tree-sitter']
// head branch == `master`.
manifest = fetch_manifest('ui', 'https://github.com/pisaiah/ui', '', true) or {
assert false
return
}
assert manifest.name == 'iui'
// not a V module.
if v := fetch_manifest('octocat', 'https://github.com/octocat/octocat.github.io',
'', true)
{
assert false, v.str()
return
}
mut res := os.execute('${vexe} install https://github.com/octocat/octocat.github.io')
assert res.exit_code == 1
assert res.output.contains('failed to find `v.mod` for `https://github.com/octocat/octocat.github.io`'), res.output
// No error for vpm modules yet.
res = os.execute('${vexe} install spytheman.regex')
assert res.exit_code == 0, res.str()
assert res.output.contains('`spytheman.regex` is missing a manifest file'), res.output
assert res.output.contains('Installing `spytheman.regex`'), res.output
}
fn test_install_potentially_conflicting() {
mut res := os.execute('${vexe} install ui')
assert res.output.contains('Installed `ui`')
mut manifest := get_vmod('ui')
assert manifest.name == 'ui'
res = os.execute('${vexe} install https://github.com/isaiahpatton/ui')
assert res.output.contains('Installed `iui`')
manifest = get_vmod('iui')
assert manifest.name == 'iui'
}
fn test_get_installed_version() {
test_project_path := os.join_path(test_path, 'test_project')
mut res := os.execute('git init ${test_project_path}')
assert res.exit_code == 0, res.str()
os.chdir(test_project_path)!
if os.execute('git config user.name').exit_code == 1 {
os.execute_or_exit('git config user.email "ci@vlang.io"')
os.execute_or_exit('git config user.name "V CI"')
}
os.write_file('v.mod', '')!
res = os.execute('git add .')
assert res.exit_code == 0, res.str()
res = os.execute('git commit -m "initial commit"')
assert res.exit_code == 0, res.str()
mut mod := Module{
install_path: test_project_path
}
mod.get_installed()
assert mod.is_installed
assert mod.installed_version == ''
// Create a tag -> latests commit and tag are at the same state,
// but it should not be treated as a version installation, when there is another head branch.
res = os.execute('git tag v0.1.0')
assert res.exit_code == 0, res.str()
mod.is_installed = false
mod.get_installed()
assert mod.is_installed
assert mod.installed_version == ''
os.execute('git checkout v0.1.0')
assert res.exit_code == 0, res.str()
mod.is_installed = false
mod.get_installed()
assert mod.is_installed
assert mod.installed_version == ''
os.execute('git branch -D master')
assert res.exit_code == 0, res.str()
os.execute('git reset --hard v0.1.0')
assert res.exit_code == 0, res.str()
mod.is_installed = false
mod.get_installed()
assert mod.is_installed
assert mod.installed_version == 'v0.1.0'
}
fn test_install_from_hg_url() ! {
hg_path := os.find_abs_path_of_executable('hg') or {
eprintln('skipping test, since `hg` is not executable.')
return
}
test_module_path := os.join_path(os.temp_dir(), rand.ulid(), 'hg_test_module')
defer {
os.rmdir_all(test_module_path) or {}
}
// Initialize project without manifest file.
mut res := os.execute('hg init ${test_module_path}')
assert res.exit_code == 0, res.str()
mut p, mut port := test_utils.hg_serve(hg_path, test_module_path)
// Trying to install it should fail.
res = os.execute('${vexe} install --hg http://127.0.0.1:${port}')
if res.exit_code != 1 {
p.signal_kill()
assert false, res.str()
}
assert res.output.contains('failed to find `v.mod`'), res.output
p.signal_kill()
// Create and commit manifest.
name := 'my_awesome_v_module'
version := '1.0.0'
os.write_file(os.join_path(test_module_path, 'v.mod'), "Module{
name: '${name}'
version: '${version}'
}")!
os.chdir(test_module_path)!
res = os.execute('hg add')
assert res.exit_code == 0, res.str()
res = os.execute('hg --config ui.username=v_ci commit -m "add v.mod"')
assert res.exit_code == 0, res.str()
p, port = test_utils.hg_serve(hg_path, test_module_path)
// Trying to install the module should work now.
res = os.execute('${vexe} install --hg http://127.0.0.1:${port}')
if res.exit_code != 0 {
p.signal_kill()
assert false, res.str()
}
p.signal_kill()
// Get manifest from the vmodules directory.
manifest := get_vmod(name)
assert manifest.name == name
assert manifest.version == version
}