Skip to content

Commit

Permalink
extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Dec 19, 2023
1 parent 54f1f6b commit 5d764a3
Showing 1 changed file with 56 additions and 18 deletions.
74 changes: 56 additions & 18 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,75 @@ 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() {
mut res := os.execute('${v} update pcre')
fn test_update_short_ident() {
os.execute_or_exit('git -C ${os.join_path(test_path, 'pcre')} reset --hard HEAD~')
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')
}

fn test_update_ident() {
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.
res = os.execute('${v} update https://github.com/spytheman/vtray')
}

fn test_update_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
}

fn test_update_multi_ident() {
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
// Try update not installed.
res = os.execute('${v} update vsl')
}

fn test_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.
res = os.execute('${v} update pcre vsl')
assert res.output.contains('failed to update `vsl`. Not installed.'), res.output
}

fn test_update_mixed_installed_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 5d764a3

Please sign in to comment.