Skip to content

Commit

Permalink
extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Dec 18, 2023
1 parent 54f1f6b commit bae84e4
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions cmd/tools/vpm/update_test.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// vtest retry: 3
module main

import os
import rand
import test_utils
Expand All @@ -18,39 +20,69 @@ fn testsuite_end() {
os.rmdir_all(test_path) or {}
}

// Tests if `v update` detects installed modules and runs successfully.
fn test_update() {
os.execute_or_exit('${v} install pcre')
os.execute_or_exit('${v} install nedpals.args')
os.execute_or_exit('${v} install https://github.com/spytheman/vtray')
for m in ['pcre', 'https://github.com/spytheman/vtray', 'nedpals.args', 'ttytm.webview'] {
os.execute_or_exit('${v} install ${m}')
}
// "outdate" some modules, by removing their last commit.
for m in ['pcre', 'vtray', os.join_path('nedpals', 'args')] {
path := os.join_path(test_path, m)
os.execute_or_exit('git -C ${path} fetch --unshallow')
os.execute_or_exit('git -C ${path} reset --hard HEAD~')
assert is_outdated(path)
}
// Case: Run `v update` (without args).
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 `nedpals.args`'), res.output
assert res.output.contains('Updating module `vtray`'), res.output
assert res.output.contains('Skipping download count increment for `nedpals.args`.'), res.output
assert res.output.contains('Updating module `nedpals.args`'), res.output
assert res.output.contains('Skipping download count increment for `pcre`.'), res.output
assert res.output.contains('Skipping download count increment for `nedpals.args`.'), res.output
assert !res.output.contains('Updating module `ttytm.webview`'), res.output
assert !res.output.contains('Skipping download count increment for `ttytm.webview`.'), res.output
for m in ['pcre', 'vtray', os.join_path('nedpals', 'args')] {
assert !is_outdated(os.join_path(test_path, m))
}
}

fn test_update_idents() {
// Case: Update installed module using ident.
os.execute_or_exit('git -C ${os.join_path(test_path, 'pcre')} reset --hard HEAD~')
mut res := os.execute('${v} update pcre')
assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `pcre`'), res.output
res = os.execute('${v} update nedpals.args vtray')
os.execute_or_exit('git -C ${os.join_path(test_path, 'nedpals', 'args')} reset --hard HEAD~')
res = os.execute('${v} update nedpals.args')
assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `vtray`'), res.output
assert res.output.contains('Updating module `nedpals.args`'), res.output
// Update installed module using its url.

// Case: Update installed module using its url.
os.execute_or_exit('git -C ${os.join_path(test_path, 'vtray')} reset --hard HEAD~')
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
// Try update not installed.

// Case: Update multiple installed modules.
os.execute_or_exit('git -C ${os.join_path(test_path, 'nedpals', 'args')} reset --hard HEAD~')
os.execute_or_exit('git -C ${os.join_path(test_path, 'vtray')} reset --hard HEAD~')
res = os.execute('${v} update nedpals.args vtray')
assert res.exit_code == 0, res.str()
assert res.output.contains('Updating module `nedpals.args`'), res.output
assert res.output.contains('Updating module `vtray`'), res.output

// Case: Try to update not installed.
res = os.execute('${v} update vsl')
assert res.exit_code == 1, res.str()
assert res.output.contains('failed to find `vsl`'), res.output
// Try update mixed.
assert res.output.contains('failed to update `vsl`. Not installed.'), res.output

// Case: Try to update mixed (installed and not installed).
os.execute_or_exit('git -C ${os.join_path(test_path, 'pcre')} reset --hard HEAD~')
res = os.execute('${v} update pcre vsl')
assert res.exit_code == 1, res.str()
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 update `vsl`. Not installed.'), res.output
}

// TODO: hg tests
// TODO: recursive test

0 comments on commit bae84e4

Please sign in to comment.