| 1 | // vtest build: !musl? && !sanitized_job? |
| 2 | // vtest retry: 3 |
| 3 | import os |
| 4 | import rand |
| 5 | import v.vmod |
| 6 | import test_utils { cmd_ok } |
| 7 | |
| 8 | const vexe = os.quoted_path(@VEXE) |
| 9 | const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_version_input_test_${rand.ulid()}') |
| 10 | const expect_tests_path = os.join_path(@VEXEROOT, 'cmd', 'tools', 'vpm', 'expect') |
| 11 | const expect_exe = os.quoted_path(os.find_abs_path_of_executable('expect') or { |
| 12 | eprintln('skipping test, since expect is missing') |
| 13 | exit(0) |
| 14 | }) |
| 15 | |
| 16 | fn testsuite_begin() { |
| 17 | $if !network ? { |
| 18 | eprintln('> skipping ${@FILE}, when `-d network` is missing') |
| 19 | exit(0) |
| 20 | } |
| 21 | dump(test_path) |
| 22 | test_utils.set_test_env(test_path) |
| 23 | // Explicitly disable fail on prompt. |
| 24 | os.setenv('VPM_FAIL_ON_PROMPT', '', true) |
| 25 | os.mkdir_all(test_path) or {} |
| 26 | os.chdir(test_path)! |
| 27 | } |
| 28 | |
| 29 | fn testsuite_end() { |
| 30 | os.rmdir_all(test_path) or {} |
| 31 | } |
| 32 | |
| 33 | fn get_vmod(path string) vmod.Manifest { |
| 34 | return vmod.from_file(os.join_path(test_path, path, 'v.mod')) or { |
| 35 | eprintln('Failed to parse v.mod for `${path}`. ${err}') |
| 36 | exit(1) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // Test installing another version of a module of which an explicit version is already installed. |
| 41 | fn test_reinstall_mod_with_version_installation() { |
| 42 | // Install version. |
| 43 | ident := 'vsl' |
| 44 | tag := 'v0.1.47' |
| 45 | cmd_ok(@LOCATION, '${vexe} install ${ident}@${tag}') |
| 46 | mut manifest := get_vmod(ident) |
| 47 | assert manifest.name == ident |
| 48 | assert manifest.version == tag.trim_left('v') |
| 49 | |
| 50 | // Try reinstalling. |
| 51 | new_tag := 'v0.1.50' |
| 52 | install_path := os.real_path(os.join_path(test_path, ident)) |
| 53 | expect_args := [vexe, ident, tag, new_tag, install_path].join(' ') |
| 54 | |
| 55 | // Decline. |
| 56 | decline_test := os.join_path(expect_tests_path, |
| 57 | 'decline_reinstall_mod_with_version_installation.expect') |
| 58 | manifest_path := os.join_path(install_path, 'v.mod') |
| 59 | last_modified := os.file_last_mod_unix(manifest_path) |
| 60 | cmd_ok(@LOCATION, '${expect_exe} ${decline_test} ${expect_args}') |
| 61 | assert last_modified == os.file_last_mod_unix(manifest_path) |
| 62 | |
| 63 | // Accept. |
| 64 | accept_test := os.join_path(expect_tests_path, |
| 65 | 'accept_reinstall_mod_with_version_installation.expect') |
| 66 | cmd_ok(@LOCATION, '${expect_exe} ${accept_test} ${expect_args}') |
| 67 | manifest = get_vmod(ident) |
| 68 | assert manifest.name == ident |
| 69 | assert manifest.version == new_tag.trim_left('v') |
| 70 | } |
| 71 | |