Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vlang/v into vdoc-handle-complex-…
Browse files Browse the repository at this point in the history
…string
  • Loading branch information
nedpals committed Nov 6, 2023
2 parents 0736cfe + 1e25d45 commit 8a3970e
Show file tree
Hide file tree
Showing 29 changed files with 266 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_vinix_locally.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/freebsd_build_tcc.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/bin/bash
#!/usr/bin/env bash

## should be run in V's main repo folder!

Expand Down
5 changes: 3 additions & 2 deletions cmd/tools/vpm/common.v
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,13 @@ fn resolve_dependencies(name string, module_path string, module_names []string)
eprintln(err)
return
}
// filter out dependencies that were already specified by the user
// Filter out modules that are both contained in the input query and listed as
// dependencies in the mod file of the module that is supposed to be installed.
deps := manifest.dependencies.filter(it !in module_names)
if deps.len > 0 {
println('Resolving ${deps.len} dependencies for module "${name}" ...')
verbose_println('Found dependencies: ${deps}')
vpm_install_from_vpm(deps)
vpm_install(deps)
}
}

Expand Down
69 changes: 69 additions & 0 deletions cmd/tools/vpm/dependency_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// vtest flaky: true
// vtest retry: 3
import os
import v.vmod

const (
v = os.quoted_path(@VEXE)
test_path = os.join_path(os.vtmp_dir(), 'vpm_dependency_test')
)

fn testsuite_begin() {
os.setenv('VMODULES', test_path, true)
os.setenv('VPM_NO_INCREMENT', '1', true)
}

fn testsuite_end() {
os.rmdir_all(test_path) or {}
}

fn get_mod_name(path string) string {
mod := vmod.from_file(path) or {
eprintln(err)
return ''
}
return mod.name
}

// Case: running `v install` without specifying modules in a V project directory.
fn test_install_dependencies_in_module_dir() {
os.mkdir_all(test_path) or {}
mod := 'my_module'
mod_path := os.join_path(test_path, mod)
os.mkdir(mod_path)!
os.chdir(mod_path)!
// Create a v.mod file that lists dependencies.
vmod_path := os.join_path(mod_path, 'v.mod')
vmod_contents := "Module {
name: '${mod}'
description: ''
version: '0.0.0'
license: 'MIT'
dependencies: ['markdown', 'pcre', 'https://github.com/spytheman/vtray']
}"
os.write_file(vmod_path, vmod_contents)!
v_mod := vmod.from_file(vmod_path) or {
assert false, err.msg()
return
}
assert v_mod.dependencies == ['markdown', 'pcre', 'https://github.com/spytheman/vtray']
// Run `v install`
res := os.execute_or_exit('${v} install')
assert res.output.contains('Detected v.mod file inside the project directory. Using it...')
assert res.output.contains('Installing module "markdown"')
assert res.output.contains('Installing module "pcre"')
assert res.output.contains('Installing module "vtray"')
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'
}

fn test_resolve_external_dependencies_during_module_install() {
res := os.execute_or_exit('${v} install https://github.com/ttytm/emoji-mart-desktop')
assert res.output.contains('Resolving 2 dependencies')
assert res.output.contains('Installing module "webview"')
assert res.output.contains('Installing module "miniaudio"')
// The external dependencies should have been installed to `<vmodules_dir>/<dependency_name>`
assert get_mod_name(os.join_path(test_path, 'webview', 'v.mod')) == 'webview'
assert get_mod_name(os.join_path(test_path, 'miniaudio', 'v.mod')) == 'miniaudio'
}
5 changes: 2 additions & 3 deletions cmd/tools/vpm/install.v
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ fn install_module(vcs &VCS, name string, url string, final_module_path string) !
cmd := '${vcs.cmd} ${vcs.args.install} "${url}" "${final_module_path}"'
verbose_println(' command: ${cmd}')
println('Installing module "${name}" from "${url}" to "${final_module_path}" ...')
res := os.execute(cmd)
if res.exit_code != 0 {
verbose_println(' command output: ${res.output}')
os.execute_opt(cmd) or {
verbose_println(' command output: ${err}')
return error('Failed installing module "${name}" to "${final_module_path}" .')
}
}
Expand Down
35 changes: 15 additions & 20 deletions cmd/tools/vpm/install_test.v
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// vtest flaky: true
// vtest retry: 3
import os
import v.vmod

const (
v = os.quoted_path(@VEXE)
// Running tests appends a tsession path to VTMP, which is automatically cleaned up after the test.
// The following will result in e.g. `$VTMP/tsession_7fe8e93bd740_1612958707536/test-vmodules/`.
test_path = os.join_path(os.vtmp_dir(), 'test-vmodules')
test_path = os.join_path(os.vtmp_dir(), 'vpm_install_test')
)

fn testsuite_begin() {
Expand All @@ -18,47 +20,43 @@ fn testsuite_end() {
}

fn test_install_from_vpm_ident() {
res := os.execute('${v} install nedpals.args')
assert res.exit_code == 0, res.output
res := os.execute_or_exit('${v} install nedpals.args')
assert res.output.contains('Skipping download count increment for "nedpals.args".')
mod := vmod.from_file(os.join_path(test_path, 'nedpals', 'args', 'v.mod')) or {
assert false, err.str()
assert false, err.msg()
return
}
assert mod.name == 'nedpals.args'
assert mod.dependencies == []string{}
}

fn test_install_from_vpm_short_ident() {
res := os.execute('${v} install pcre')
assert res.exit_code == 0, res.output
os.execute_or_exit('${v} install pcre')
mod := vmod.from_file(os.join_path(test_path, 'pcre', 'v.mod')) or {
assert false, err.str()
assert false, err.msg()
return
}
assert mod.name == 'pcre'
assert mod.description == 'A simple regex library for V.'
}

fn test_install_from_git_url() {
res := os.execute('${v} install https://github.com/vlang/markdown')
assert res.exit_code == 0, res.output
res := os.execute_or_exit('${v} install https://github.com/vlang/markdown')
assert res.output.contains('Installing module "markdown" from "https://github.com/vlang/markdown')
assert res.output.contains('Relocating module from "vlang/markdown" to "markdown"')
mod := vmod.from_file(os.join_path(test_path, 'markdown', 'v.mod')) or {
assert false, err.str()
assert false, err.msg()
return
}
assert mod.name == 'markdown'
assert mod.dependencies == []string{}
}

fn test_install_already_existent() {
mut res := os.execute('${v} install https://github.com/vlang/markdown')
assert res.exit_code == 0, res.output
mut res := os.execute_or_exit('${v} install https://github.com/vlang/markdown')
assert res.output.contains('already exists')
mod := vmod.from_file(os.join_path(test_path, 'markdown', 'v.mod')) or {
assert false, err.str()
assert false, err.msg()
return
}
assert mod.name == 'markdown'
Expand All @@ -79,18 +77,16 @@ fn test_install_once() {
os.mkdir_all(test_path) or {}

// Install markdown module.
mut res := os.execute('${v} install markdown')
assert res.exit_code == 0, res.output
os.execute_or_exit('${v} install markdown')
// Keep track of the last modified state of the v.mod file of the installed markdown module.
md_last_modified := os.file_last_mod_unix(os.join_path(test_path, 'markdown', 'v.mod'))

install_cmd := '${@VEXE} install https://github.com/vlang/markdown https://github.com/vlang/pcre --once -v'
// Try installing two modules, one of which is already installed.
res = os.execute(install_cmd)
assert res.exit_code == 0, res.output
mut res := os.execute_or_exit(install_cmd)
assert res.output.contains("Already installed modules: ['markdown']")
mod := vmod.from_file(os.join_path(test_path, 'pcre', 'v.mod')) or {
assert false, err.str()
assert false, err.msg()
return
}
assert mod.name == 'pcre'
Expand All @@ -100,8 +96,7 @@ fn test_install_once() {
'v.mod'))

// Try installing two modules that are both already installed.
res = os.execute(install_cmd)
assert res.exit_code == 0, res.output
res = os.execute_or_exit(install_cmd)
assert res.output.contains('All modules are already installed.')
assert md_last_modified == os.file_last_mod_unix(os.join_path(test_path, 'markdown',
'v.mod'))
Expand Down
10 changes: 4 additions & 6 deletions cmd/tools/vpm/update.v
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ fn update_module(mut pp pool.PoolProcessor, idx int, wid int) &ModUpdateInfo {
}
cmd := '${vcs.cmd} ${vcs.args.path} "${result.final_path}" ${vcs.args.update}'
verbose_println(' command: ${cmd}')
res := os.execute('${cmd}')
if res.exit_code != 0 {
res := os.execute_opt('${cmd}') or {
result.has_err = true
println('Failed updating module "${zname}" in "${result.final_path}".')
verbose_println(' command output: ${res.output}')
verbose_println(' command output: ${err}')
return result
}
verbose_println(' ${res.output.trim_space()}')
Expand Down Expand Up @@ -77,11 +76,10 @@ fn vpm_update_verbose(module_names []string) {
}
cmd := '${vcs.cmd} ${vcs.args.path} "${final_module_path}" ${vcs.args.update}'
verbose_println(' command: ${cmd}')
res := os.execute('${cmd}')
if res.exit_code != 0 {
res := os.execute_opt('${cmd}') or {
errors++
println('Failed updating module "${zname}" in "${final_module_path}" .')
verbose_println(' command output: ${res.output}')
verbose_println(' command output: ${err}')
continue
}
verbose_println(' ${res.output.trim_space()}')
Expand Down
2 changes: 1 addition & 1 deletion cmd/tools/vtest-all.v
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn get_all_commands() []Command {
line: '${vexe} -o calling_c.exe run examples/call_c_from_v/main.c.v'
okmsg: 'V can run main.c.v files'
runcmd: .execute
contains: 'V can call C functions like puts too.'
contains: 'V can call C functions like `puts` too.'
}
$if linux || macos {
res << Command{
Expand Down
2 changes: 1 addition & 1 deletion doc/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6231,7 +6231,7 @@ This is an example bash script you can use to optimize your CLI V program withou
In most cases, you will need to change this script to make it suitable for your particular program.
```bash
#!/bin/bash
#!/usr/bin/env bash
# Get the full path to the current directory
CUR_DIR=$(pwd)
Expand Down
2 changes: 1 addition & 1 deletion doc/packaging_v_for_distributions.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Example `v` script for your bin folder:
--------------------------------------------------

```sh
#!/bin/bash
#!/usr/bin/env bash

export VEXE="/opt/vlang/v"
export VFLAGS="-cc /usr/bin/custom_cc"
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions vlib/encoding/base64/base64_memory_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn test_long_encoding() {
//
encoded_size := base64.encode_in_buffer(s_original, ebuffer)
mut encoded_in_buf := []u8{len: encoded_size}
unsafe { C.memcpy(encoded_in_buf.data, ebuffer, encoded_size) }
unsafe { vmemcpy(encoded_in_buf.data, ebuffer, encoded_size) }
assert input_size * 4 / 3 == encoded_size
assert encoded_in_buf[0] == `Y`
assert encoded_in_buf[1] == `W`
Expand All @@ -38,7 +38,7 @@ fn test_long_encoding() {
decoded_size := base64.decode_in_buffer(s_encoded, dbuffer)
assert decoded_size == input_size
mut decoded_in_buf := []u8{len: decoded_size}
unsafe { C.memcpy(decoded_in_buf.data, dbuffer, decoded_size) }
unsafe { vmemcpy(decoded_in_buf.data, dbuffer, decoded_size) }
assert decoded_in_buf == s_original

mut s := 0
Expand Down
Loading

0 comments on commit 8a3970e

Please sign in to comment.