tools.vpm: update tests, add get_installed test (#20028)

This commit is contained in:
Turiiya 2023-11-29 18:11:50 +01:00 committed by GitHub
parent f4937aef9e
commit 74c59abf4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 199 additions and 136 deletions

View File

@ -1,10 +1,11 @@
// vtest retry: 3 // vtest retry: 3
import os import os
import v.vmod
import time import time
import rand
import v.vmod
const v = os.quoted_path(@VEXE) const v = os.quoted_path(@VEXE)
const test_path = os.join_path(os.vtmp_dir(), 'vpm_dependency_test') const test_path = os.join_path(os.vtmp_dir(), 'vpm_dependency_test_${rand.ulid()}')
fn testsuite_begin() { fn testsuite_begin() {
os.setenv('VMODULES', test_path, true) os.setenv('VMODULES', test_path, true)
@ -29,10 +30,6 @@ fn test_install_dependencies_in_module_dir() {
os.mkdir_all(test_path) or {} os.mkdir_all(test_path) or {}
mod := 'my_module' mod := 'my_module'
mod_path := os.join_path(test_path, mod) mod_path := os.join_path(test_path, mod)
$if windows {
// Make sure path is clean to work around CI failures with Windows MSVC.
os.system('rd /s /q ${mod_path}')
}
os.mkdir(mod_path)! os.mkdir(mod_path)!
os.chdir(mod_path)! os.chdir(mod_path)!
// Create a v.mod file that lists dependencies. // Create a v.mod file that lists dependencies.
@ -51,7 +48,8 @@ fn test_install_dependencies_in_module_dir() {
} }
assert v_mod.dependencies == ['markdown', 'pcre', 'https://github.com/spytheman/vtray'] assert v_mod.dependencies == ['markdown', 'pcre', 'https://github.com/spytheman/vtray']
// Run `v install` // Run `v install`
mut res := os.execute_or_exit('${v} install --once') mut res := os.execute('${v} install --once')
assert res.exit_code == 0, res.str()
assert res.output.contains('Detected v.mod file inside the project directory. Using it...'), res.output assert res.output.contains('Detected v.mod file inside the project directory. Using it...'), res.output
assert res.output.contains('Installing `markdown`'), res.output assert res.output.contains('Installing `markdown`'), res.output
assert res.output.contains('Installing `pcre`'), res.output assert res.output.contains('Installing `pcre`'), res.output
@ -60,12 +58,14 @@ fn test_install_dependencies_in_module_dir() {
assert get_mod_name(os.join_path(test_path, 'markdown', 'v.mod')) == 'markdown' assert get_mod_name(os.join_path(test_path, 'markdown', 'v.mod')) == 'markdown'
assert get_mod_name(os.join_path(test_path, 'pcre', 'v.mod')) == 'pcre' assert get_mod_name(os.join_path(test_path, 'pcre', 'v.mod')) == 'pcre'
assert get_mod_name(os.join_path(test_path, 'vtray', 'v.mod')) == 'vtray' assert get_mod_name(os.join_path(test_path, 'vtray', 'v.mod')) == 'vtray'
res = os.execute_or_exit('${v} install --once') res = os.execute('${v} install --once')
assert res.exit_code == 0, res.str()
assert res.output.contains('All modules are already installed.'), res.output assert res.output.contains('All modules are already installed.'), res.output
} }
fn test_resolve_external_dependencies_during_module_install() { fn test_resolve_external_dependencies_during_module_install() {
res := os.execute_or_exit('${v} install -v https://github.com/ttytm/emoji-mart-desktop') res := os.execute('${v} install -v https://github.com/ttytm/emoji-mart-desktop')
assert res.exit_code == 0, res.str()
assert res.output.contains('Found 2 dependencies'), res.output assert res.output.contains('Found 2 dependencies'), res.output
assert res.output.contains('Installing `webview`'), res.output assert res.output.contains('Installing `webview`'), res.output
assert res.output.contains('Installing `miniaudio`'), res.output assert res.output.contains('Installing `miniaudio`'), res.output
@ -77,7 +77,9 @@ fn test_resolve_external_dependencies_during_module_install() {
fn test_install_with_recursive_dependencies() { fn test_install_with_recursive_dependencies() {
spawn fn () { spawn fn () {
time.sleep(2 * time.minute) time.sleep(2 * time.minute)
eprintln('Timeout while testing installation with recursive dependencies.')
exit(1) exit(1)
}() }()
os.execute_or_exit('${v} install https://gitlab.com/tobealive/a') res := os.execute('${v} install https://gitlab.com/tobealive/a')
assert res.exit_code == 0, res.str()
} }

View File

@ -1,13 +1,13 @@
// vtest flaky: true
// vtest retry: 3 // vtest retry: 3
module main module main
import os import os
import rand
import v.vmod import v.vmod
// Running tests appends a tsession path to VTMP, which is automatically cleaned up after the test. // 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/`. // 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') const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_test_${rand.ulid()}')
fn testsuite_begin() { fn testsuite_begin() {
os.setenv('VMODULES', test_path, true) os.setenv('VMODULES', test_path, true)
@ -20,62 +20,62 @@ fn testsuite_end() {
os.rmdir_all(test_path) or {} os.rmdir_all(test_path) or {}
} }
fn test_install_from_vpm_ident() { fn get_vmod(path string) vmod.Manifest {
res := os.execute_or_exit('${vexe} install nedpals.args') return vmod.from_file(os.join_path(test_path, path, 'v.mod')) or {
assert res.output.contains('Skipping download count increment for `nedpals.args`.'), res.output eprintln('Failed to parse v.mod for `${path}`')
mod := vmod.from_file(os.join_path(test_path, 'nedpals', 'args', 'v.mod')) or { exit(1)
assert false, err.msg()
return
} }
assert mod.name == 'nedpals.args' }
assert mod.dependencies == []string{}
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() { fn test_install_from_vpm_short_ident() {
os.execute_or_exit('${vexe} install pcre') res := os.execute('${vexe} install pcre')
mod := vmod.from_file(os.join_path(test_path, 'pcre', 'v.mod')) or { assert res.exit_code == 0, res.str()
assert false, err.msg() manifest := get_vmod('pcre')
return assert manifest.name == 'pcre'
} assert manifest.description == 'A simple regex library for V.'
assert mod.name == 'pcre'
assert mod.description == 'A simple regex library for V.'
} }
fn test_install_from_git_url() { fn test_install_from_git_url() {
mut res := os.execute_or_exit('${vexe} install https://github.com/vlang/markdown') 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 assert res.output.contains('Installing `markdown`'), res.output
mut mod := vmod.from_file(os.join_path(test_path, 'markdown', 'v.mod')) or { mut manifest := get_vmod('markdown')
assert false, err.msg() assert manifest.name == 'markdown'
return assert manifest.dependencies == []string{}
} res = os.execute('${vexe} install http://github.com/Wertzui123/HashMap')
assert mod.name == 'markdown' assert res.exit_code == 0, res.str()
assert mod.dependencies == []string{}
res = os.execute_or_exit('${vexe} install http://github.com/Wertzui123/HashMap')
assert res.output.contains('Installing `HashMap`'), res.output assert res.output.contains('Installing `HashMap`'), res.output
assert res.output.contains('`http` is deprecated'), res.output assert res.output.contains('`http` is deprecated'), res.output
mod = vmod.from_file(os.join_path(test_path, 'wertzui123', 'hashmap', 'v.mod')) or { manifest = get_vmod(os.join_path('wertzui123', 'hashmap'))
assert false, err.msg() res = os.execute('${vexe} install http://github.com/Wertzui123/HashMap')
return assert res.exit_code == 0, res.str()
}
res = os.execute_or_exit('${vexe} install http://github.com/Wertzui123/HashMap')
assert res.output.contains('Updating module `wertzui123.hashmap`'), res.output assert res.output.contains('Updating module `wertzui123.hashmap`'), res.output
assert res.output.contains('`http` is deprecated'), res.output assert res.output.contains('`http` is deprecated'), res.output
res = os.execute_or_exit('${vexe} install https://gitlab.com/tobealive/webview') 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 assert res.output.contains('Installed `webview`'), res.output
} }
fn test_install_already_existent() { fn test_install_already_existent() {
mut res := os.execute_or_exit('${vexe} install https://github.com/vlang/markdown') mut res := os.execute('${vexe} install https://github.com/vlang/markdown')
assert res.output.contains('Updating module `markdown` in `${test_path}/markdown`'), res.output assert res.exit_code == 0, res.str()
mod := vmod.from_file(os.join_path(test_path, 'markdown', 'v.mod')) or { assert res.output.contains('Updating module `markdown`'), res.output
assert false, err.msg() manifest := get_vmod('markdown')
return assert manifest.name == 'markdown'
} assert manifest.dependencies == []string{}
assert mod.name == 'markdown'
assert mod.dependencies == []string{}
// The same module but with the `.git` extension added. // The same module but with the `.git` extension added.
os.execute_or_exit('${vexe} install https://github.com/vlang/markdown.git') res = os.execute('${vexe} install https://github.com/vlang/markdown.git')
assert res.output.contains('Updating module `markdown` in `${test_path}/markdown`'), res.output assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `markdown`'), res.output
} }
fn test_install_once() { fn test_install_once() {
@ -89,26 +89,26 @@ fn test_install_once() {
os.mkdir_all(test_path) or {} os.mkdir_all(test_path) or {}
// Install markdown module. // Install markdown module.
os.execute_or_exit('${vexe} install markdown') 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. // 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')) 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' 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. // Try installing two modules, one of which is already installed.
mut res := os.execute_or_exit(install_cmd) res = os.execute(install_cmd)
assert res.exit_code == 0, res.str()
assert res.output.contains("Already installed modules: ['markdown']"), res.output assert res.output.contains("Already installed modules: ['markdown']"), res.output
mod := vmod.from_file(os.join_path(test_path, 'pcre', 'v.mod')) or { manifest := get_vmod('pcre')
assert false, err.msg() assert manifest.name == 'pcre'
return assert manifest.description == 'A simple regex library for V.'
}
assert mod.name == 'pcre'
assert mod.description == 'A simple regex library for V.'
// Ensure the before installed markdown module wasn't modified. // Ensure the before installed markdown module wasn't modified.
assert md_last_modified == os.file_last_mod_unix(os.join_path(test_path, 'markdown', assert md_last_modified == os.file_last_mod_unix(os.join_path(test_path, 'markdown',
'v.mod')) 'v.mod'))
// Try installing two modules that are both already installed. // Try installing two modules that are both already installed.
res = os.execute_or_exit(install_cmd) res = os.execute(install_cmd)
assert res.exit_code == 0, res.str()
assert res.output.contains('All modules are already installed.'), res.output 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', assert md_last_modified == os.file_last_mod_unix(os.join_path(test_path, 'markdown',
'v.mod')) 'v.mod'))
@ -123,19 +123,19 @@ fn test_missing_repo_name_in_url() {
fn test_manifest_detection() { fn test_manifest_detection() {
// head branch == `main`. // head branch == `main`.
mut mod := fetch_manifest('v-analyzer', 'https://github.com/v-analyzer/v-analyzer', mut manifest := fetch_manifest('v-analyzer', 'https://github.com/v-analyzer/v-analyzer',
'', true) or { '', true) or {
assert false assert false
return return
} }
assert mod.name == 'v-analyzer' assert manifest.name == 'v-analyzer'
assert mod.dependencies == ['https://github.com/v-analyzer/v-tree-sitter'] assert manifest.dependencies == ['https://github.com/v-analyzer/v-tree-sitter']
// head branch == `master`. // head branch == `master`.
mod = fetch_manifest('ui', 'https://github.com/pisaiah/ui', '', true) or { manifest = fetch_manifest('ui', 'https://github.com/pisaiah/ui', '', true) or {
assert false assert false
return return
} }
assert mod.name == 'iui' assert manifest.name == 'iui'
// not a V module. // not a V module.
if v := fetch_manifest('octocat', 'https://github.com/octocat/octocat.github.io', if v := fetch_manifest('octocat', 'https://github.com/octocat/octocat.github.io',
'', true) '', true)
@ -147,7 +147,8 @@ fn test_manifest_detection() {
assert res.exit_code == 1 assert res.exit_code == 1
assert res.output.contains('failed to find `v.mod` for `https://github.com/octocat/octocat.github.io`'), res.output 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. // No error for vpm modules yet.
res = os.execute_or_exit('${vexe} install spytheman.regex') 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('`spytheman.regex` is missing a manifest file'), res.output
assert res.output.contains('Installing `spytheman.regex`'), res.output assert res.output.contains('Installing `spytheman.regex`'), res.output
} }
@ -155,16 +156,58 @@ fn test_manifest_detection() {
fn test_install_potentially_conflicting() { fn test_install_potentially_conflicting() {
mut res := os.execute('${vexe} install ui') mut res := os.execute('${vexe} install ui')
assert res.output.contains('Installed `ui`') assert res.output.contains('Installed `ui`')
mut mod := vmod.from_file(os.join_path(test_path, 'ui', 'v.mod')) or { mut manifest := get_vmod('ui')
assert false, err.msg() assert manifest.name == 'ui'
return
}
assert mod.name == 'ui'
res = os.execute('${vexe} install https://github.com/isaiahpatton/ui') res = os.execute('${vexe} install https://github.com/isaiahpatton/ui')
assert res.output.contains('Installed `iui`') assert res.output.contains('Installed `iui`')
mod = vmod.from_file(os.join_path(test_path, 'iui', 'v.mod')) or { manifest = get_vmod('iui')
assert false, err.msg() assert manifest.name == 'iui'
return
} }
assert mod.name == 'iui'
fn test_get_installed_version() {
test_project_path := os.join_path(test_path, 'test_project')
os.mkdir_all(test_project_path)!
os.chdir(test_project_path)!
os.write_file('v.mod', '')!
if os.getenv('CI') != '' {
os.execute_or_exit('git config --global user.email "v@vi.com"')
os.execute_or_exit('git config --global user.name "V CI"')
}
mut res := os.execute('git init')
assert res.exit_code == 0, res.str()
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'
} }

View File

@ -1,9 +1,10 @@
// vtest retry: 3 // vtest retry: 3
import os import os
import rand
import v.vmod import v.vmod
const vexe = os.quoted_path(@VEXE) const vexe = os.quoted_path(@VEXE)
const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_version_input_test') const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_version_input_test_${rand.ulid()}')
const expect_tests_path = os.join_path(@VEXEROOT, 'cmd', 'tools', 'vpm', 'expect') const expect_tests_path = os.join_path(@VEXEROOT, 'cmd', 'tools', 'vpm', 'expect')
const expect_exe = os.quoted_path(os.find_abs_path_of_executable('expect') or { const expect_exe = os.quoted_path(os.find_abs_path_of_executable('expect') or {
eprintln('skipping test, since expect is missing') eprintln('skipping test, since expect is missing')
@ -24,40 +25,42 @@ fn testsuite_end() {
os.rmdir_all(test_path) or {} os.rmdir_all(test_path) or {}
} }
fn get_mod_name_and_version(path string) (string, string) { fn get_vmod(path string) vmod.Manifest {
mod := vmod.from_file(os.join_path(test_path, path, 'v.mod')) or { return vmod.from_file(os.join_path(test_path, path, 'v.mod')) or {
eprintln(err) eprintln('Failed to parse v.mod for `${path}`')
return '', '' exit(1)
} }
return mod.name, mod.version
} }
// Test installing another version of a module of which an explicit version is already installed. // Test installing another version of a module of which an explicit version is already installed.
fn test_reinstall_mod_with_version_installation() { fn test_reinstall_mod_with_version_installation() {
// Install version. // Install version.
mod := 'vsl' ident := 'vsl'
tag := 'v0.1.47' tag := 'v0.1.47'
os.execute_or_exit('${vexe} install ${mod}@${tag}') mut res := os.execute('${vexe} install ${ident}@${tag}')
mut name, mut version := get_mod_name_and_version(mod) assert res.exit_code == 0, res.str()
assert name == mod mut manifest := get_vmod(ident)
assert version == tag.trim_left('v') assert manifest.name == ident
assert manifest.version == tag.trim_left('v')
// Try reinstalling. // Try reinstalling.
new_tag := 'v0.1.50' new_tag := 'v0.1.50'
install_path := os.real_path(os.join_path(test_path, mod)) install_path := os.real_path(os.join_path(test_path, ident))
expect_args := [vexe, mod, tag, new_tag, install_path].join(' ') expect_args := [vexe, ident, tag, new_tag, install_path].join(' ')
// Decline. // Decline.
decline_test := os.join_path(expect_tests_path, 'decline_reinstall_mod_with_version_installation.expect') decline_test := os.join_path(expect_tests_path, 'decline_reinstall_mod_with_version_installation.expect')
manifest_path := os.join_path(install_path, 'v.mod') manifest_path := os.join_path(install_path, 'v.mod')
last_modified := os.file_last_mod_unix(manifest_path) last_modified := os.file_last_mod_unix(manifest_path)
os.execute_or_exit('${expect_exe} ${decline_test} ${expect_args}') res = os.execute('${expect_exe} ${decline_test} ${expect_args}')
assert res.exit_code == 0, res.str()
assert last_modified == os.file_last_mod_unix(manifest_path) assert last_modified == os.file_last_mod_unix(manifest_path)
// Accept. // Accept.
accept_test := os.join_path(expect_tests_path, 'accept_reinstall_mod_with_version_installation.expect') accept_test := os.join_path(expect_tests_path, 'accept_reinstall_mod_with_version_installation.expect')
os.execute_or_exit('${expect_exe} ${accept_test} ${expect_args}') res = os.execute('${expect_exe} ${accept_test} ${expect_args}')
name, version = get_mod_name_and_version(mod) assert res.exit_code == 0, res.str()
assert name == mod, name manifest = get_vmod(ident)
assert version == new_tag.trim_left('v'), version assert manifest.name == ident
assert manifest.version == new_tag.trim_left('v')
} }

View File

@ -2,9 +2,10 @@
module main module main
import os import os
import rand
import v.vmod import v.vmod
const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_version_test') const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_version_test_${rand.ulid()}')
fn testsuite_begin() { fn testsuite_begin() {
os.setenv('VMODULES', test_path, true) os.setenv('VMODULES', test_path, true)
@ -17,84 +18,93 @@ fn testsuite_end() {
os.rmdir_all(test_path) or {} os.rmdir_all(test_path) or {}
} }
fn get_mod_name_and_version(path string) (string, string) { fn get_vmod(path string) vmod.Manifest {
mod := vmod.from_file(os.join_path(test_path, path, 'v.mod')) or { return vmod.from_file(os.join_path(test_path, path, 'v.mod')) or {
eprintln(err) eprintln('Failed to parse v.mod for `${path}`')
return '', '' exit(1)
} }
return mod.name, mod.version
} }
fn test_install_from_vpm_with_git_version_tag() { fn test_install_from_vpm_with_git_version_tag() {
ident := 'ttytm.webview' ident := 'ttytm.webview'
relative_path := ident.replace('.', os.path_separator)
mut tag := 'v0.6.0' mut tag := 'v0.6.0'
mut res := os.execute_or_exit('${vexe} install ${ident}@${tag}') mut res := os.execute('${vexe} install ${ident}@${tag}')
assert res.exit_code == 0, res.str()
assert res.output.contains('Installing `${ident}`'), res.output assert res.output.contains('Installing `${ident}`'), res.output
assert res.output.contains('Installed `${ident}`'), res.output assert res.output.contains('Installed `${ident}`'), res.output
mut name, mut version := get_mod_name_and_version(os.join_path('ttytm', 'webview')) mut manifest := get_vmod(relative_path)
assert name == 'webview' assert manifest.name == 'webview'
assert version == '0.6.0' assert manifest.version == '0.6.0'
// Install same version without force flag. // Install same version without force flag.
res = os.execute_or_exit('${vexe} install ${ident}@${tag}') res = os.execute('${vexe} install ${ident}@${tag}')
assert res.exit_code == 0, res.str()
assert res.output.contains('Module `${ident}@${tag}` is already installed, use --force to overwrite'), res.output assert res.output.contains('Module `${ident}@${tag}` is already installed, use --force to overwrite'), res.output
// Install another version, add force flag to surpass confirmation. // Install another version, add force flag to surpass confirmation.
tag = 'v0.5.0' tag = 'v0.5.0'
res = os.execute_or_exit('${vexe} install -f ${ident}@${tag}') res = os.execute('${vexe} install -f ${ident}@${tag}')
assert res.output.contains('Installed `${ident}`'), res.output assert res.output.contains('Installed `${ident}`'), res.output
name, version = get_mod_name_and_version(os.join_path('ttytm', 'webview')) assert res.exit_code == 0, res.str()
assert name == 'webview' manifest = get_vmod(relative_path)
assert version == '0.5.0' assert manifest.name == 'webview'
assert manifest.version == '0.5.0'
// Install invalid version. // Install invalid version.
tag = '6.0' tag = '6.0'
res = os.execute('${vexe} install -f ${ident}@${tag}') res = os.execute('${vexe} install -f ${ident}@${tag}')
assert res.exit_code == 1 assert res.exit_code == 1, res.str()
assert res.output.contains('failed to install `${ident}`'), res.output assert res.output.contains('failed to install `${ident}`'), res.output
// Install invalid version verbose. // Install invalid version verbose.
res = os.execute('${vexe} install -f -v ${ident}@${tag}') res = os.execute('${vexe} install -f -v ${ident}@${tag}')
assert res.exit_code == 1 assert res.exit_code == 1, res.str()
assert res.output.contains('failed to install `${ident}`'), res.output assert res.output.contains('failed to install `${ident}`'), res.output
assert res.output.contains('Remote branch 6.0 not found in upstream origin'), res.output assert res.output.contains('Remote branch 6.0 not found in upstream origin'), res.output
// Install without version tag after a version was installed // Install without version tag after a version was installed
res = os.execute_or_exit('${vexe} install -f ${ident}') res = os.execute('${vexe} install -f ${ident}')
assert res.exit_code == 0, res.str()
assert res.output.contains('Installing `${ident}`'), res.output assert res.output.contains('Installing `${ident}`'), res.output
// Re-install latest version (without a tag). Should trigger an update, force should not be required. // Re-install latest version (without a tag). Should trigger an update, force should not be required.
res = os.execute_or_exit('${vexe} install ${ident}') res = os.execute('${vexe} install ${ident}')
assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `${ident}`'), res.output assert res.output.contains('Updating module `${ident}`'), res.output
} }
fn test_install_from_url_with_git_version_tag() { fn test_install_from_url_with_git_version_tag() {
mut url := 'https://github.com/vlang/vsl' mut url := 'https://github.com/vlang/vsl'
mut tag := 'v0.1.50' mut tag := 'v0.1.50'
mut res := os.execute_or_exit('${vexe} install ${url}@${tag}') mut res := os.execute('${vexe} install ${url}@${tag}')
assert res.exit_code == 0, res.str()
assert res.output.contains('Installing `vsl`'), res.output assert res.output.contains('Installing `vsl`'), res.output
assert res.output.contains('Installed `vsl`'), res.output assert res.output.contains('Installed `vsl`'), res.output
mut name, mut version := get_mod_name_and_version('vsl') mut manifest := get_vmod('vsl')
assert name == 'vsl' assert manifest.name == 'vsl'
assert version == '0.1.50' assert manifest.version == '0.1.50'
// Install same version without force flag. // Install same version without force flag.
res = os.execute_or_exit('${vexe} install ${url}@${tag}') res = os.execute('${vexe} install ${url}@${tag}')
assert res.exit_code == 0, res.str()
assert res.output.contains('Module `vsl@${tag}` is already installed, use --force to overwrite'), res.output assert res.output.contains('Module `vsl@${tag}` is already installed, use --force to overwrite'), res.output
// Install another version, add force flag to surpass confirmation. // Install another version, add force flag to surpass confirmation.
tag = 'v0.1.47' tag = 'v0.1.47'
res = os.execute_or_exit('${vexe} install -f ${url}@${tag}') res = os.execute('${vexe} install -f ${url}@${tag}')
assert res.exit_code == 0, res.str()
assert res.output.contains('Installed `vsl`'), res.output assert res.output.contains('Installed `vsl`'), res.output
name, version = get_mod_name_and_version('vsl') manifest = get_vmod('vsl')
assert name == 'vsl' assert manifest.name == 'vsl'
assert version == '0.1.47' assert manifest.version == '0.1.47'
// Install invalid version. // Install invalid version.
tag = 'abc' tag = 'abc'
res = os.execute('${vexe} install -f ${url}@${tag}') res = os.execute('${vexe} install -f ${url}@${tag}')
assert res.exit_code == 1 assert res.exit_code == 1, res.str()
// Install invalid version verbose. // Install invalid version verbose.
res = os.execute('${vexe} install -f -v ${url}@${tag}') res = os.execute('${vexe} install -f -v ${url}@${tag}')
assert res.exit_code == 1 assert res.exit_code == 1, res.str()
assert res.output.contains('failed to find `v.mod` for `${url}@${tag}`'), res.output assert res.output.contains('failed to find `v.mod` for `${url}@${tag}`'), res.output
// GitLab // Install from GitLab.
url = 'https://gitlab.com/tobealive/webview' url = 'https://gitlab.com/tobealive/webview'
tag = 'v0.6.0' tag = 'v0.6.0'
res = os.execute_or_exit('${vexe} install ${url}@${tag}') res = os.execute('${vexe} install ${url}@${tag}')
assert res.exit_code == 0, res.str()
assert res.output.contains('Installed `webview`'), res.output assert res.output.contains('Installed `webview`'), res.output
name, version = get_mod_name_and_version('webview') manifest = get_vmod('webview')
assert name == 'webview' assert manifest.name == 'webview'
assert version == '0.6.0' assert manifest.version == '0.6.0'
} }

View File

@ -152,9 +152,9 @@ fn (mut p Parser) parse_module(m string) {
} }
} }
// TODO: add unit test
fn (mut m Module) get_installed() { fn (mut m Module) get_installed() {
refs := os.execute_opt('git ls-remote --refs ${m.install_path}') or { return } refs := os.execute_opt('git ls-remote --refs ${m.install_path}') or { return }
vpm_log(@FILE_LINE, @FN, 'refs: ${refs}')
m.is_installed = true m.is_installed = true
// In case the head just temporarily matches a tag, make sure that there // In case the head just temporarily matches a tag, make sure that there
// really is a version installation before adding it as `installed_version`. // really is a version installation before adding it as `installed_version`.

View File

@ -1,8 +1,9 @@
// vtest retry: 3 // vtest retry: 3
import os import os
import rand
const v = os.quoted_path(@VEXE) const v = os.quoted_path(@VEXE)
const test_path = os.join_path(os.vtmp_dir(), 'vpm_update_test') const test_path = os.join_path(os.vtmp_dir(), 'vpm_update_test_${rand.ulid()}')
fn testsuite_begin() { fn testsuite_begin() {
os.setenv('VMODULES', test_path, true) os.setenv('VMODULES', test_path, true)
@ -19,7 +20,8 @@ fn test_update() {
os.execute_or_exit('${v} install pcre') os.execute_or_exit('${v} install pcre')
os.execute_or_exit('${v} install nedpals.args') os.execute_or_exit('${v} install nedpals.args')
os.execute_or_exit('${v} install https://github.com/spytheman/vtray') os.execute_or_exit('${v} install https://github.com/spytheman/vtray')
res := os.execute_opt('${v} update') or { panic(err) } res := os.execute('${v} update')
assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `pcre`'), res.output assert res.output.contains('Updating module `pcre`'), res.output
assert res.output.contains('Updating module `nedpals.args`'), res.output assert res.output.contains('Updating module `nedpals.args`'), res.output
assert res.output.contains('Updating module `vtray`'), res.output assert res.output.contains('Updating module `vtray`'), res.output
@ -28,21 +30,24 @@ fn test_update() {
} }
fn test_update_idents() { fn test_update_idents() {
mut res := os.execute_or_exit('${v} update pcre') mut res := os.execute('${v} update pcre')
assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `pcre`'), res.output assert res.output.contains('Updating module `pcre`'), res.output
res = os.execute_or_exit('${v} update nedpals.args vtray') res = os.execute('${v} update nedpals.args vtray')
assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `vtray`'), res.output assert res.output.contains('Updating module `vtray`'), res.output
assert res.output.contains('Updating module `nedpals.args`'), res.output assert res.output.contains('Updating module `nedpals.args`'), res.output
// Update installed module using its url. // Update installed module using its url.
res = os.execute('${v} update https://github.com/spytheman/vtray') res = os.execute('${v} update https://github.com/spytheman/vtray')
assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `vtray`'), res.output assert res.output.contains('Updating module `vtray`'), res.output
// Try update not installed. // Try update not installed.
res = os.execute('${v} update vsl') res = os.execute('${v} update vsl')
assert res.exit_code == 1 assert res.exit_code == 1, res.str()
assert res.output.contains('failed to find `vsl`'), res.output assert res.output.contains('failed to find `vsl`'), res.output
// Try update mixed. // Try update mixed.
res = os.execute('${v} update pcre vsl') res = os.execute('${v} update pcre vsl')
assert res.exit_code == 1 assert res.exit_code == 1, res.str()
assert res.output.contains('Updating module `pcre`'), res.output assert res.output.contains('Updating module `pcre`'), res.output
assert res.output.contains('failed to find `vsl`'), res.output assert res.output.contains('failed to find `vsl`'), res.output
} }