v / cmd / tools / vpm / install_version_input_test.v
70 lines · 62 sloc · 2.18 KB · e2e5cf8db56f3562c7baa735061690be936bdf3e
Raw
1// vtest build: !musl? && !sanitized_job?
2// vtest retry: 3
3import os
4import rand
5import v.vmod
6import test_utils { cmd_ok }
7
8const vexe = os.quoted_path(@VEXE)
9const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_version_input_test_${rand.ulid()}')
10const expect_tests_path = os.join_path(@VEXEROOT, 'cmd', 'tools', 'vpm', 'expect')
11const 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
16fn 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
29fn testsuite_end() {
30 os.rmdir_all(test_path) or {}
31}
32
33fn 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.
41fn 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