From bae84e49b3b0221af8da4df23f6585340578b84c Mon Sep 17 00:00:00 2001 From: Turiiya Date: Mon, 18 Dec 2023 21:49:59 +0100 Subject: [PATCH] extend tests --- cmd/tools/vpm/update_test.v | 58 ++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/cmd/tools/vpm/update_test.v b/cmd/tools/vpm/update_test.v index 528c83debabfcf..c52ef868c81065 100644 --- a/cmd/tools/vpm/update_test.v +++ b/cmd/tools/vpm/update_test.v @@ -1,4 +1,6 @@ // vtest retry: 3 +module main + import os import rand import test_utils @@ -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