From 80e688e9a1c4c8e5ebf2b91276e2a6703d601477 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 27 Mar 2024 12:22:19 +0200 Subject: [PATCH] ci: fix vpm tests with `-d network`, add more diagnostic output --- cmd/tools/vpm/dependency_test.v | 19 ++--- ...stall_mod_with_version_installation.expect | 6 +- ...stall_mod_with_version_installation.expect | 4 +- cmd/tools/vpm/install_version_input_test.v | 12 ++- cmd/tools/vpm/install_version_test.v | 73 +++++++------------ cmd/tools/vpm/test_utils/utils.v | 14 ++++ 6 files changed, 56 insertions(+), 72 deletions(-) diff --git a/cmd/tools/vpm/dependency_test.v b/cmd/tools/vpm/dependency_test.v index 06370cdfb..5c1e5c6a7 100644 --- a/cmd/tools/vpm/dependency_test.v +++ b/cmd/tools/vpm/dependency_test.v @@ -3,6 +3,7 @@ import os import time import rand import v.vmod +import test_utils { cmd_ok } const v = os.quoted_path(@VEXE) const test_path = os.join_path(os.vtmp_dir(), 'vpm_dependency_test_${rand.ulid()}') @@ -52,8 +53,7 @@ fn test_install_dependencies_in_module_dir() { } assert v_mod.dependencies == ['markdown', 'pcre', 'https://github.com/spytheman/vtray'] // Run `v install` - mut res := os.execute('${v} install --once') - assert res.exit_code == 0, res.str() + mut res := cmd_ok(@LOCATION, '${v} install --once') assert res.output.contains('Detected v.mod file inside the project directory. Using it...'), res.output assert res.output.contains('Installing `markdown`'), res.output assert res.output.contains('Installing `pcre`'), res.output @@ -62,14 +62,12 @@ fn test_install_dependencies_in_module_dir() { assert get_mod_name(os.join_path(test_path, 'markdown', 'v.mod')) == 'markdown' assert get_mod_name(os.join_path(test_path, 'pcre', 'v.mod')) == 'pcre' assert get_mod_name(os.join_path(test_path, 'vtray', 'v.mod')) == 'vtray' - res = os.execute('${v} install --once') - assert res.exit_code == 0, res.str() + res = cmd_ok(@LOCATION, '${v} install --once') assert res.output.contains('All modules are already installed.'), res.output } fn test_resolve_external_dependencies_during_module_install() { - res := os.execute('${v} install -v https://github.com/ttytm/emoji-mart-desktop') - assert res.exit_code == 0, res.str() + res := cmd_ok(@LOCATION, '${v} install -v https://github.com/ttytm/emoji-mart-desktop') assert res.output.contains('Found 2 dependencies'), res.output assert res.output.contains('Installing `webview`'), res.output assert res.output.contains('Installing `miniaudio`'), res.output @@ -84,14 +82,11 @@ fn test_install_with_recursive_dependencies() { eprintln('Timeout while testing installation with recursive dependencies.') exit(1) }() - mut res := os.execute('${v} install https://gitlab.com/tobealive/a') - assert res.exit_code == 0, res.str() + cmd_ok(@LOCATION, '${v} install https://gitlab.com/tobealive/a') // Test the installation of a module when passing its URL with the `.git` extension. // One of the modules dependencies `https://gitlab.com/tobealive/c` has the // `https://gitlab.com/tobealive/a` dependency without `.git`. - res = os.execute('${v} remove a b c') - assert res.exit_code == 0, res.str() - res = os.execute('${v} install https://gitlab.com/tobealive/a.git') - assert res.exit_code == 0, res.str() + cmd_ok(@LOCATION, '${v} remove a b c') + cmd_ok(@LOCATION, '${v} install https://gitlab.com/tobealive/a.git') } diff --git a/cmd/tools/vpm/expect/accept_reinstall_mod_with_version_installation.expect b/cmd/tools/vpm/expect/accept_reinstall_mod_with_version_installation.expect index 2f936c343..161e5b813 100644 --- a/cmd/tools/vpm/expect/accept_reinstall_mod_with_version_installation.expect +++ b/cmd/tools/vpm/expect/accept_reinstall_mod_with_version_installation.expect @@ -1,6 +1,6 @@ #!/usr/bin/env expect -set timeout 3 +set timeout 10 set vexe [lindex $argv 0] set mod [lindex $argv 1] @@ -11,10 +11,10 @@ set install_path [lindex $argv 4] spawn $vexe install $mod@$new_tag expect "Scanning `$mod@$new_tag`..." {} timeout { exit 1 } -expect "Module `$mod@$cur_tag` is already installed at `$install_path`." {} timeout { exit 1 } +expect "Module `$mod@$cur_tag` is already installed at" {} timeout { exit 1 } expect "Replace it with `$mod@$new_tag`? \\\[Y/n\\\]: " { send "\r" } timeout { exit 1 } expect "Installing `$mod`..." {} timeout { exit 1 } expect "Skipping download count increment for `$mod`." {} timeout { exit 1 } -expect "Installed `$mod`." {} timeout { exit 1 } +expect "Installed `$mod`" {} timeout { exit 1 } expect eof diff --git a/cmd/tools/vpm/expect/decline_reinstall_mod_with_version_installation.expect b/cmd/tools/vpm/expect/decline_reinstall_mod_with_version_installation.expect index e265383c8..97f61079a 100644 --- a/cmd/tools/vpm/expect/decline_reinstall_mod_with_version_installation.expect +++ b/cmd/tools/vpm/expect/decline_reinstall_mod_with_version_installation.expect @@ -1,6 +1,6 @@ #!/usr/bin/env expect -set timeout 3 +set timeout 10 set vexe [lindex $argv 0] set mod [lindex $argv 1] @@ -11,7 +11,7 @@ set install_path [lindex $argv 4] spawn $vexe install $mod@$new_tag expect "Scanning `$mod@$new_tag`..." {} timeout { exit 1 } -expect "Module `$mod@$cur_tag` is already installed at `$install_path`." {} timeout { exit 1 } +expect "Module `$mod@$cur_tag` is already installed at" {} timeout { exit 1 } expect "Replace it with `$mod@$new_tag`? \\\[Y/n\\\]: " { send "n\r" } timeout { exit 1 } expect eof diff --git a/cmd/tools/vpm/install_version_input_test.v b/cmd/tools/vpm/install_version_input_test.v index f2fc47d89..da8f972f4 100644 --- a/cmd/tools/vpm/install_version_input_test.v +++ b/cmd/tools/vpm/install_version_input_test.v @@ -2,7 +2,7 @@ import os import rand import v.vmod -import test_utils +import test_utils { cmd_ok } const vexe = os.quoted_path(@VEXE) const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_version_input_test_${rand.ulid()}') @@ -18,6 +18,7 @@ fn testsuite_begin() { exit(0) } test_utils.set_test_env(test_path) + eprintln('>> test_path: ${test_path}') // Explicitly disable fail on prompt. os.setenv('VPM_FAIL_ON_PROMPT', '', true) os.mkdir_all(test_path) or {} @@ -40,8 +41,7 @@ fn test_reinstall_mod_with_version_installation() { // Install version. ident := 'vsl' tag := 'v0.1.47' - mut res := os.execute('${vexe} install ${ident}@${tag}') - assert res.exit_code == 0, res.str() + cmd_ok(@LOCATION, '${vexe} install ${ident}@${tag}') mut manifest := get_vmod(ident) assert manifest.name == ident assert manifest.version == tag.trim_left('v') @@ -55,14 +55,12 @@ fn test_reinstall_mod_with_version_installation() { decline_test := os.join_path(expect_tests_path, 'decline_reinstall_mod_with_version_installation.expect') manifest_path := os.join_path(install_path, 'v.mod') last_modified := os.file_last_mod_unix(manifest_path) - res = os.execute('${expect_exe} ${decline_test} ${expect_args}') - assert res.exit_code == 0, res.str() + cmd_ok(@LOCATION, '${expect_exe} ${decline_test} ${expect_args}') assert last_modified == os.file_last_mod_unix(manifest_path) // Accept. accept_test := os.join_path(expect_tests_path, 'accept_reinstall_mod_with_version_installation.expect') - res = os.execute('${expect_exe} ${accept_test} ${expect_args}') - assert res.exit_code == 0, res.str() + cmd_ok(@LOCATION, '${expect_exe} ${accept_test} ${expect_args}') manifest = get_vmod(ident) assert manifest.name == ident assert manifest.version == new_tag.trim_left('v') diff --git a/cmd/tools/vpm/install_version_test.v b/cmd/tools/vpm/install_version_test.v index 2c153980f..663ef0dc4 100644 --- a/cmd/tools/vpm/install_version_test.v +++ b/cmd/tools/vpm/install_version_test.v @@ -4,7 +4,7 @@ module main import os import rand import v.vmod -import test_utils +import test_utils { cmd_fail, cmd_ok } const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_version_test_${rand.ulid()}') @@ -31,80 +31,68 @@ fn test_install_from_vpm_with_git_version_tag() { ident := 'ttytm.webview' relative_path := ident.replace('.', os.path_separator) mut tag := 'v0.6.0' - mut res := os.execute('${vexe} install ${ident}@${tag}') - assert res.exit_code == 0, res.str() + mut res := cmd_ok(@LOCATION, '${vexe} install ${ident}@${tag}') assert res.output.contains('Installing `${ident}`'), res.output assert res.output.contains('Installed `${ident}`'), res.output mut manifest := get_vmod(relative_path) assert manifest.name == 'webview' assert manifest.version == '0.6.0' // Install same version without force flag. - res = os.execute('${vexe} install ${ident}@${tag}') - assert res.exit_code == 0, res.str() + res = cmd_ok(@LOCATION, '${vexe} install ${ident}@${tag}') assert res.output.contains('Module `${ident}@${tag}` is already installed, use --force to overwrite'), res.output // Install another version, add force flag to surpass confirmation. tag = 'v0.5.0' - res = os.execute('${vexe} install -f ${ident}@${tag}') + res = cmd_ok(@LOCATION, '${vexe} install -f ${ident}@${tag}') assert res.output.contains('Installed `${ident}`'), res.output - assert res.exit_code == 0, res.str() manifest = get_vmod(relative_path) assert manifest.name == 'webview' assert manifest.version == '0.5.0' // Install invalid version. tag = '6.0' - res = os.execute('${vexe} install -f ${ident}@${tag}') - assert res.exit_code == 1, res.str() + res = cmd_fail(@LOCATION, '${vexe} install -f ${ident}@${tag}') assert res.output.contains('failed to install `${ident}`'), res.output + // Install invalid version verbose. - res = os.execute('${vexe} install -f -v ${ident}@${tag}') - assert res.exit_code == 1, res.str() + res = cmd_fail(@LOCATION, '${vexe} install -f -v ${ident}@${tag}') assert res.output.contains('failed to install `${ident}`'), res.output assert res.output.contains('Remote branch 6.0 not found in upstream origin'), res.output // Install without version tag after a version was installed - res = os.execute('${vexe} install -f ${ident}') - assert res.exit_code == 0, res.str() + res = cmd_ok(@LOCATION, '${vexe} install -f ${ident}') assert res.output.contains('Installing `${ident}`'), res.output // Re-install latest version (without a tag). Should trigger an update, force should not be required. - res = os.execute('${vexe} install ${ident}') - assert res.exit_code == 0, res.str() + res = cmd_ok(@LOCATION, '${vexe} install ${ident}') assert res.output.contains('Updating module `${ident}`'), res.output } fn test_install_from_git_url_with_version_tag() { mut url := 'https://github.com/vlang/vsl' mut tag := 'v0.1.50' - mut res := os.execute('${vexe} install ${url}@${tag}') - assert res.exit_code == 0, res.str() + mut res := cmd_ok(@LOCATION, '${vexe} install ${url}@${tag}') assert res.output.contains('Installing `vsl`'), res.output assert res.output.contains('Installed `vsl`'), res.output mut manifest := get_vmod('vsl') assert manifest.name == 'vsl' assert manifest.version == '0.1.50' // Install same version without force flag. - res = os.execute('${vexe} install ${url}@${tag}') - assert res.exit_code == 0, res.str() + res = cmd_ok(@LOCATION, '${vexe} install ${url}@${tag}') assert res.output.contains('Module `vsl@${tag}` is already installed, use --force to overwrite'), res.output // Install another version, add force flag to surpass confirmation. tag = 'v0.1.47' - res = os.execute('${vexe} install -f ${url}@${tag}') - assert res.exit_code == 0, res.str() + res = cmd_ok(@LOCATION, '${vexe} install -f ${url}@${tag}') assert res.output.contains('Installed `vsl`'), res.output manifest = get_vmod('vsl') assert manifest.name == 'vsl' assert manifest.version == '0.1.47' // Install invalid version. tag = 'abc' - res = os.execute('${vexe} install -f ${url}@${tag}') - assert res.exit_code == 1, res.str() + res = cmd_fail(@LOCATION, '${vexe} install -f ${url}@${tag}') // Install invalid version verbose. - res = os.execute('${vexe} install -f -v ${url}@${tag}') - assert res.exit_code == 1, res.str() + res = cmd_fail(@LOCATION, '${vexe} install -f -v ${url}@${tag}') assert res.output.contains('Could not find remote branch ${tag} to clone.'), res.output // Install from GitLab. url = 'https://gitlab.com/tobealive/webview' tag = 'v0.6.0' - res = os.execute('${vexe} install ${url}@${tag}') - assert res.exit_code == 0, res.str() + res = cmd_ok(@LOCATION, '${vexe} install ${url}@${tag}') assert res.output.contains('Installed `webview`'), res.output manifest = get_vmod('webview') assert manifest.name == 'webview' @@ -120,44 +108,33 @@ fn test_install_from_hg_url_with_version_tag() ! { defer { os.rmdir_all(test_module_path) or {} } - mut res := os.execute('hg init ${test_module_path}') - assert res.exit_code == 0, res.str() + mut res := cmd_ok(@LOCATION, 'hg init ${test_module_path}') os.chdir(test_module_path)! os.write_file('v.mod', "Module{ name: 'my_awesome_v_module' version: '0.1.0' }")! - res = os.execute('hg add') - assert res.exit_code == 0, res.str() - res = os.execute('hg --config ui.username=v_ci commit -m "initial commit"') - assert res.exit_code == 0, res.str() - + cmd_ok(@LOCATION, 'hg add') + cmd_ok(@LOCATION, 'hg --config ui.username=v_ci commit -m "initial commit"') os.write_file('README.md', 'Hello World!')! - res = os.execute('hg add') - assert res.exit_code == 0, res.str() - res = os.execute('hg --config ui.username=v_ci commit -m "add readme"') - assert res.exit_code == 0, res.str() - - res = os.execute('hg tag v0.1.0') - assert res.exit_code == 0, res.str() + cmd_ok(@LOCATION, 'hg add') + cmd_ok(@LOCATION, 'hg --config ui.username=v_ci commit -m "add readme"') + cmd_ok(@LOCATION, 'hg tag v0.1.0') os.write_file('v.mod', "Module{ name: 'my_awesome_v_module' version: '0.2.0' }")! - res = os.execute('hg add') - assert res.exit_code == 0, res.str() - res = os.execute('hg --config ui.username=v_ci commit -m "bump version to v0.2.0"') - assert res.exit_code == 0, res.str() + cmd_ok(@LOCATION, 'hg add') + cmd_ok(@LOCATION, 'hg --config ui.username=v_ci commit -m "bump version to v0.2.0"') mut p, port := test_utils.hg_serve(hg_path, test_module_path) res = os.execute('${vexe} install -v --hg http://127.0.0.1:${port}@v0.1.0') + p.signal_kill() if res.exit_code != 0 { - p.signal_kill() - assert false, res.str() + assert false, 'location: $@LOCATION, res:\n${res}' } - p.signal_kill() // Get manifest from the vmodules directory. manifest := get_vmod('my_awesome_v_module') assert manifest.name == 'my_awesome_v_module' diff --git a/cmd/tools/vpm/test_utils/utils.v b/cmd/tools/vpm/test_utils/utils.v index b8d6a5b2c..79bceee2e 100644 --- a/cmd/tools/vpm/test_utils/utils.v +++ b/cmd/tools/vpm/test_utils/utils.v @@ -40,3 +40,17 @@ pub fn hg_serve(hg_path string, path string) (&os.Process, int) { } return p, port } + +pub fn cmd_ok(location string, cmd string) os.Result { + eprintln('> cmd_ok for cmd: "${cmd}"') + res := os.execute(cmd) + assert res.exit_code == 0, 'success expected, but not found\n location: ${location}\n cmd:\n${cmd}\n res:\n${res}\n' + return res +} + +pub fn cmd_fail(location string, cmd string) os.Result { + eprintln('> cmd_fail for cmd: "${cmd}"') + res := os.execute(cmd) + assert res.exit_code == 1, 'failure expected, but not found\n location: ${location}\n cmd:\n${cmd}\n res:\n${res}\n' + return res +} -- 2.39.5