-
-
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools.vpm: add manifest fetch for hg repositories, add test #20107
Changes from all commits
d194887
7c467e5
08b9ead
28d5474
5ad3890
1acbda9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ 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/`. | ||
|
@@ -22,7 +23,7 @@ fn testsuite_end() { | |
|
||
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}`') | ||
eprintln('Failed to parse v.mod for `${path}`. ${err}') | ||
exit(1) | ||
} | ||
} | ||
|
@@ -166,15 +167,14 @@ fn test_install_potentially_conflicting() { | |
|
||
fn test_get_installed_version() { | ||
test_project_path := os.join_path(test_path, 'test_project') | ||
os.mkdir_all(test_project_path)! | ||
mut res := os.execute('git init ${test_project_path}') | ||
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. Very nice ... I did not know, that |
||
assert res.exit_code == 0, res.str() | ||
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"') | ||
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"') | ||
} | ||
mut res := os.execute('git init') | ||
assert res.exit_code == 0, res.str() | ||
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"') | ||
|
@@ -211,3 +211,50 @@ fn test_get_installed_version() { | |
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module test_utils | ||
|
||
import os | ||
import net | ||
import time | ||
|
||
fn hg_serve(hg_path string, path string) (&os.Process, int) { | ||
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. Hm, this should have needed |
||
mut port := 8000 | ||
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. Start probing from some more obscure port. 8000 and 8080 are |
||
for { | ||
if mut l := net.listen_tcp(.ip6, ':${port}') { | ||
l.close() or { panic(err) } | ||
break | ||
} | ||
port++ | ||
} | ||
mut p := os.new_process(hg_path) | ||
p.set_work_folder(path) | ||
p.set_args(['serve', '--print-url', '--port', port.str()]) | ||
p.set_redirect_stdio() | ||
p.run() | ||
mut i := 0 | ||
for p.is_alive() { | ||
if i == 500 { // Wait max. 5 seconds. | ||
p.signal_kill() | ||
eprintln('Failed to serve mercurial repository on localhost.') | ||
exit(1) | ||
} | ||
if p.stdout_read().contains(':${port}') { | ||
break | ||
} | ||
time.sleep(10 * time.millisecond) | ||
i++ | ||
} | ||
return p, port | ||
} |
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.
Anything would be fine here. This just makes sure a name is returned when a localhost address is fetched during tests that doesn't contain a path after the domain. The eventual module name is derived from the manifest.