-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools.vpm: update tests, add get_installed
test
#20028
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10f37b1
use `execute` and assert instead `execute_or_exit` to get better info…
ttytm add419f
prevent https://discord.com/channels/592103645835821068/6183637365033…
ttytm 8e65d42
add `eprintln` when to recursive installation test timeout
ttytm 1f80937
add `get_vmod` to tests to simplify; standardize tests for easier ove…
ttytm c89a8fa
add `get_installed` test
ttytm File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
// vtest flaky: true | ||
// vtest retry: 3 | ||
module main | ||
|
||
import os | ||
import rand | ||
import v.vmod | ||
|
||
// 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') | ||
const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_test_${rand.ulid()}') | ||
|
||
fn testsuite_begin() { | ||
os.setenv('VMODULES', test_path, true) | ||
|
@@ -20,62 +20,62 @@ 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}`') | ||
exit(1) | ||
} | ||
} | ||
|
||
fn test_install_from_vpm_ident() { | ||
res := os.execute_or_exit('${vexe} install nedpals.args') | ||
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 | ||
mod := vmod.from_file(os.join_path(test_path, 'nedpals', 'args', 'v.mod')) or { | ||
assert false, err.msg() | ||
return | ||
} | ||
assert mod.name == 'nedpals.args' | ||
assert mod.dependencies == []string{} | ||
manifest := get_vmod(os.join_path('nedpals', 'args')) | ||
assert manifest.name == 'nedpals.args' | ||
assert manifest.dependencies == []string{} | ||
} | ||
|
||
fn test_install_from_vpm_short_ident() { | ||
os.execute_or_exit('${vexe} install pcre') | ||
mod := vmod.from_file(os.join_path(test_path, 'pcre', 'v.mod')) or { | ||
assert false, err.msg() | ||
return | ||
} | ||
assert mod.name == 'pcre' | ||
assert mod.description == 'A simple regex library for V.' | ||
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_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 | ||
mut mod := vmod.from_file(os.join_path(test_path, 'markdown', 'v.mod')) or { | ||
assert false, err.msg() | ||
return | ||
} | ||
assert mod.name == 'markdown' | ||
assert mod.dependencies == []string{} | ||
res = os.execute_or_exit('${vexe} install http://github.com/Wertzui123/HashMap') | ||
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 | ||
mod = vmod.from_file(os.join_path(test_path, 'wertzui123', 'hashmap', 'v.mod')) or { | ||
assert false, err.msg() | ||
return | ||
} | ||
res = os.execute_or_exit('${vexe} install http://github.com/Wertzui123/HashMap') | ||
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_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 | ||
} | ||
|
||
fn test_install_already_existent() { | ||
mut res := os.execute_or_exit('${vexe} install https://github.com/vlang/markdown') | ||
assert res.output.contains('Updating module `markdown` in `${test_path}/markdown`'), res.output | ||
mod := vmod.from_file(os.join_path(test_path, 'markdown', 'v.mod')) or { | ||
assert false, err.msg() | ||
return | ||
} | ||
assert mod.name == 'markdown' | ||
assert mod.dependencies == []string{} | ||
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. | ||
os.execute_or_exit('${vexe} install https://github.com/vlang/markdown.git') | ||
assert res.output.contains('Updating module `markdown` in `${test_path}/markdown`'), res.output | ||
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() { | ||
|
@@ -89,26 +89,26 @@ fn test_install_once() { | |
os.mkdir_all(test_path) or {} | ||
|
||
// 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. | ||
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. | ||
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 | ||
mod := vmod.from_file(os.join_path(test_path, 'pcre', 'v.mod')) or { | ||
assert false, err.msg() | ||
return | ||
} | ||
assert mod.name == 'pcre' | ||
assert mod.description == 'A simple regex library for V.' | ||
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_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 md_last_modified == os.file_last_mod_unix(os.join_path(test_path, 'markdown', | ||
'v.mod')) | ||
|
@@ -123,19 +123,19 @@ fn test_missing_repo_name_in_url() { | |
|
||
fn test_manifest_detection() { | ||
// 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 { | ||
assert false | ||
return | ||
} | ||
assert mod.name == 'v-analyzer' | ||
assert mod.dependencies == ['https://github.com/v-analyzer/v-tree-sitter'] | ||
assert manifest.name == 'v-analyzer' | ||
assert manifest.dependencies == ['https://github.com/v-analyzer/v-tree-sitter'] | ||
// 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 | ||
return | ||
} | ||
assert mod.name == 'iui' | ||
assert manifest.name == 'iui' | ||
// not a V module. | ||
if v := fetch_manifest('octocat', 'https://github.com/octocat/octocat.github.io', | ||
'', true) | ||
|
@@ -147,24 +147,67 @@ fn test_manifest_detection() { | |
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_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('Installing `spytheman.regex`'), res.output | ||
} | ||
|
||
fn test_install_potentially_conflicting() { | ||
mut res := os.execute('${vexe} install ui') | ||
assert res.output.contains('Installed `ui`') | ||
mut mod := vmod.from_file(os.join_path(test_path, 'ui', 'v.mod')) or { | ||
assert false, err.msg() | ||
return | ||
} | ||
assert mod.name == '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`') | ||
mod = vmod.from_file(os.join_path(test_path, 'iui', 'v.mod')) or { | ||
assert false, err.msg() | ||
return | ||
manifest = get_vmod('iui') | ||
assert manifest.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"') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
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 | ||
} | ||
assert mod.name == 'iui' | ||
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add
err: $err
in the message too