| 1 | // vtest build: !musl? && !sanitized_job? |
| 2 | // vtest retry: 3 |
| 3 | module main |
| 4 | |
| 5 | import os |
| 6 | import rand |
| 7 | import v.vmod |
| 8 | import test_utils { cmd_fail, cmd_ok } |
| 9 | |
| 10 | const test_path = os.join_path(os.vtmp_dir(), 'vpm_install_version_test_${rand.ulid()}') |
| 11 | |
| 12 | fn testsuite_begin() { |
| 13 | $if !network ? { |
| 14 | eprintln('> skipping ${@FILE}, when `-d network` is missing') |
| 15 | exit(0) |
| 16 | } |
| 17 | dump(test_path) |
| 18 | test_utils.set_test_env(test_path) |
| 19 | } |
| 20 | |
| 21 | fn testsuite_end() { |
| 22 | os.rmdir_all(test_path) or {} |
| 23 | } |
| 24 | |
| 25 | fn get_vmod(path string) vmod.Manifest { |
| 26 | return vmod.from_file(os.join_path(test_path, path, 'v.mod')) or { |
| 27 | eprintln('Failed to parse v.mod for `${path}`. ${err}') |
| 28 | exit(1) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | fn test_install_from_vpm_with_git_version_tag() { |
| 33 | ident := 'ttytm.webview' |
| 34 | relative_path := ident.replace('.', os.path_separator) |
| 35 | mut tag := 'v0.6.0' |
| 36 | mut res := cmd_ok(@LOCATION, '${vexe} install ${ident}@${tag}') |
| 37 | assert res.output.contains('Installing `${ident}`'), res.output |
| 38 | assert res.output.contains('Installed `${ident}`'), res.output |
| 39 | mut manifest := get_vmod(relative_path) |
| 40 | assert manifest.name == 'webview' |
| 41 | assert manifest.version == '0.6.0' |
| 42 | // Install same version without force flag. |
| 43 | res = cmd_ok(@LOCATION, '${vexe} install ${ident}@${tag}') |
| 44 | assert res.output.contains('Module `${ident}@${tag}` is already installed, use --force to overwrite'), res.output |
| 45 | // Install another version, add force flag to surpass confirmation. |
| 46 | tag = 'v0.5.0' |
| 47 | res = cmd_ok(@LOCATION, '${vexe} install -f ${ident}@${tag}') |
| 48 | assert res.output.contains('Installed `${ident}`'), res.output |
| 49 | manifest = get_vmod(relative_path) |
| 50 | assert manifest.name == 'webview' |
| 51 | assert manifest.version == '0.5.0' |
| 52 | // Install invalid version. |
| 53 | tag = '6.0' |
| 54 | res = cmd_fail(@LOCATION, '${vexe} install -f ${ident}@${tag}') |
| 55 | assert res.output.contains('failed to install `${ident}`'), res.output |
| 56 | |
| 57 | // Install invalid version verbose. |
| 58 | res = cmd_fail(@LOCATION, '${vexe} install -f -v ${ident}@${tag}') |
| 59 | assert res.output.contains('failed to install `${ident}`'), res.output |
| 60 | assert res.output.contains('Remote branch 6.0 not found in upstream origin'), res.output |
| 61 | // Install without version tag after a version was installed |
| 62 | res = cmd_ok(@LOCATION, '${vexe} install -f ${ident}') |
| 63 | assert res.output.contains('Installing `${ident}`'), res.output |
| 64 | // Re-install latest version (without a tag). Should trigger an update, force should not be required. |
| 65 | res = cmd_ok(@LOCATION, '${vexe} install ${ident}') |
| 66 | assert res.output.contains('Updating module `${ident}`'), res.output |
| 67 | } |
| 68 | |
| 69 | fn test_install_from_git_url_with_version_tag() { |
| 70 | mut url := 'https://github.com/vlang/vsl' |
| 71 | mut tag := 'v0.1.50' |
| 72 | mut res := cmd_ok(@LOCATION, '${vexe} install ${url}@${tag}') |
| 73 | assert res.output.contains('Installing `vsl`'), res.output |
| 74 | assert res.output.contains('Installed `vsl`'), res.output |
| 75 | mut manifest := get_vmod('vsl') |
| 76 | assert manifest.name == 'vsl' |
| 77 | assert manifest.version == '0.1.50' |
| 78 | // Install same version without force flag. |
| 79 | res = cmd_ok(@LOCATION, '${vexe} install ${url}@${tag}') |
| 80 | assert res.output.contains('Module `vsl@${tag}` is already installed, use --force to overwrite'), res.output |
| 81 | // Install another version, add force flag to surpass confirmation. |
| 82 | tag = 'v0.1.47' |
| 83 | res = cmd_ok(@LOCATION, '${vexe} install -f ${url}@${tag}') |
| 84 | assert res.output.contains('Installed `vsl`'), res.output |
| 85 | manifest = get_vmod('vsl') |
| 86 | assert manifest.name == 'vsl' |
| 87 | assert manifest.version == '0.1.47' |
| 88 | // Install invalid version. |
| 89 | tag = 'abc' |
| 90 | res = cmd_fail(@LOCATION, '${vexe} install -f ${url}@${tag}') |
| 91 | // Install invalid version verbose. |
| 92 | res = cmd_fail(@LOCATION, '${vexe} install -f -v ${url}@${tag}') |
| 93 | not_found := res.output.contains('Could not find remote branch ${tag} to clone.') |
| 94 | || res.output.contains('Remote branch ${tag} not found') |
| 95 | assert not_found, res.output |
| 96 | // Install from GitLab. |
| 97 | url = 'https://gitlab.com/tobealive/webview' |
| 98 | tag = 'v0.6.0' |
| 99 | res = cmd_ok(@LOCATION, '${vexe} install ${url}@${tag}') |
| 100 | assert res.output.contains('Installed `webview`'), res.output |
| 101 | manifest = get_vmod('webview') |
| 102 | assert manifest.name == 'webview' |
| 103 | assert manifest.version == '0.6.0' |
| 104 | } |
| 105 | |
| 106 | fn test_install_from_hg_url_with_version_tag() ! { |
| 107 | hg_path := os.find_abs_path_of_executable('hg') or { |
| 108 | eprintln('skipping test, since `hg` is not executable.') |
| 109 | return |
| 110 | } |
| 111 | |
| 112 | hg_version := cmd_ok(@LOCATION, 'hg version -q') |
| 113 | dump(hg_version.output.trim_space()) |
| 114 | |
| 115 | test_module_path := os.join_path(os.temp_dir(), rand.ulid(), 'hg_test_module') |
| 116 | defer { |
| 117 | os.rmdir_all(test_module_path) or {} |
| 118 | } |
| 119 | mut res := cmd_ok(@LOCATION, 'hg init ${test_module_path}') |
| 120 | os.chdir(test_module_path)! |
| 121 | |
| 122 | println('> writing .hg/hgrc to the new mercurial repo ...') |
| 123 | os.mkdir_all('.hg')! |
| 124 | os.write_file('.hg/hgrc', '[ui]\nusername = v_ci <[email protected]>\nverbose = False\n')! |
| 125 | println('> writing .hg/hgrc done.') |
| 126 | |
| 127 | println('> writing v.mod file ...') |
| 128 | os.write_file('v.mod', "Module{ |
| 129 | name: 'my_awesome_v_module' |
| 130 | version: '0.1.0' |
| 131 | }")! |
| 132 | println('> writing v.mod file done.') |
| 133 | |
| 134 | cmd_ok(@LOCATION, 'hg add') |
| 135 | cmd_ok(@LOCATION, 'hg commit -m "initial commit"') |
| 136 | println('> writing README.md file ...') |
| 137 | os.write_file('README.md', 'Hello World!')! |
| 138 | println('> writing README.md file done.') |
| 139 | cmd_ok(@LOCATION, 'hg add') |
| 140 | cmd_ok(@LOCATION, 'hg commit -m "add readme"') |
| 141 | cmd_ok(@LOCATION, 'hg tag v0.1.0') |
| 142 | |
| 143 | println('> rewriting v.mod ...') |
| 144 | os.write_file('v.mod', "Module{ |
| 145 | name: 'my_awesome_v_module' |
| 146 | version: '0.2.0' |
| 147 | }")! |
| 148 | println('> rewriting v.mod done.') |
| 149 | |
| 150 | cmd_ok(@LOCATION, 'hg add') |
| 151 | cmd_ok(@LOCATION, 'hg commit -m "bump version to v0.2.0"') |
| 152 | |
| 153 | mut p, port := test_utils.hg_serve(hg_path, test_module_path, 4000) |
| 154 | res = os.execute('${vexe} install -v --hg http://127.0.0.1:${port}@v0.1.0') |
| 155 | p.signal_kill() |
| 156 | if res.exit_code != 0 { |
| 157 | assert false, 'location: ${@LOCATION}, res:\n${res}' |
| 158 | } |
| 159 | // Get manifest from the vmodules directory. |
| 160 | manifest := get_vmod('my_awesome_v_module') |
| 161 | assert manifest.name == 'my_awesome_v_module' |
| 162 | assert manifest.version == '0.1.0' |
| 163 | } |
| 164 | |