tools.vpm: add support for env variable VPM_FAIL_ON_PROMPT, to prevent getting stuck in test scenarios with conflicting module dir names (#19960)

This commit is contained in:
Turiiya 2023-11-21 23:50:51 +01:00 committed by GitHub
parent e3d306d1d2
commit b60ef550bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 0 deletions

View File

@ -233,6 +233,10 @@ fn (m Module) confirm_install() bool {
} else { } else {
install_version := at_version(if m.version == '' { 'latest' } else { m.version }) install_version := at_version(if m.version == '' { 'latest' } else { m.version })
println('Module `${m.name}${at_version(m.installed_version)}` is already installed at `${m.install_path_fmted}`.') println('Module `${m.name}${at_version(m.installed_version)}` is already installed at `${m.install_path_fmted}`.')
if settings.fail_on_prompt {
vpm_error('VPM should not have entered a confirmation prompt.')
exit(1)
}
input := os.input('Replace it with `${m.name}${install_version}`? [Y/n]: ') input := os.input('Replace it with `${m.name}${install_version}`? [Y/n]: ')
match input.to_lower() { match input.to_lower() {
'', 'y' { '', 'y' {

View File

@ -16,6 +16,7 @@ fn testsuite_begin() {
os.setenv('VMODULES', test_path, true) os.setenv('VMODULES', test_path, true)
os.setenv('VPM_DEBUG', '', true) os.setenv('VPM_DEBUG', '', true)
os.setenv('VPM_NO_INCREMENT', '1', true) os.setenv('VPM_NO_INCREMENT', '1', true)
os.setenv('VPM_FAIL_ON_PROMPT', '1', true)
} }
fn testsuite_end() { fn testsuite_end() {

View File

@ -14,6 +14,7 @@ fn testsuite_begin() {
os.setenv('VMODULES', test_path, true) os.setenv('VMODULES', test_path, true)
os.setenv('VPM_DEBUG', '', true) os.setenv('VPM_DEBUG', '', true)
os.setenv('VPM_NO_INCREMENT', '1', true) os.setenv('VPM_NO_INCREMENT', '1', true)
os.setenv('VPM_FAIL_ON_PROMPT', '1', true)
} }
fn testsuite_end() { fn testsuite_end() {

View File

@ -13,6 +13,9 @@ mut:
server_urls []string server_urls []string
vmodules_path string vmodules_path string
no_dl_count_increment bool no_dl_count_increment bool
// To ensure that some test scenarios with conflicting module directory names do not get stuck in prompts.
// It is intended that VPM does not display a prompt when `VPM_FAIL_ON_PROMPT` is set.
fail_on_prompt bool
// git is used by default. URL installations can specify `--hg`. For already installed modules // git is used by default. URL installations can specify `--hg`. For already installed modules
// and VPM modules that specify a different VCS in their `v.mod`, the VCS is validated separately. // and VPM modules that specify a different VCS in their `v.mod`, the VCS is validated separately.
vcs VCS vcs VCS
@ -35,5 +38,6 @@ fn init_settings() VpmSettings {
vcs: supported_vcs[if '--hg' in opts { 'hg' } else { 'git' }] vcs: supported_vcs[if '--hg' in opts { 'hg' } else { 'git' }]
vmodules_path: os.vmodules_dir() vmodules_path: os.vmodules_dir()
no_dl_count_increment: os.getenv('CI') != '' || (no_inc_env != '' && no_inc_env != '0') no_dl_count_increment: os.getenv('CI') != '' || (no_inc_env != '' && no_inc_env != '0')
fail_on_prompt: os.getenv('VPM_FAIL_ON_PROMPT') != ''
} }
} }