1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: bring back panic(err.msg) -> panic(err) (#9022)

This commit is contained in:
spaceface 2021-03-01 00:18:14 +01:00 committed by GitHub
parent ce115dcbe0
commit b712af56fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
110 changed files with 383 additions and 387 deletions

View File

@ -50,7 +50,7 @@ fn main() {
date := time.unix(commit_date.int())
mut out := os.create('table.html') ?
// Place the new row on top
table =
table =
'<tr>
<td>$date.format()</td>
<td><a target=_blank href="https://github.com/vlang/v/commit/$commit">$commit</a></td>
@ -81,7 +81,7 @@ fn main() {
}
fn exec(s string) string {
e := os.exec(s) or { panic(err.msg) }
e := os.exec(s) or { panic(err) }
return e.output.trim_right('\r\n')
}
@ -111,7 +111,7 @@ fn measure(cmd string, description string) int {
}
fn measure_steps(vdir string) (int, int, int) {
resp := os.exec('$vdir/vprod -o v.c -show-timings $vdir/cmd/v') or { panic(err.msg) }
resp := os.exec('$vdir/vprod -o v.c -show-timings $vdir/cmd/v') or { panic(err) }
lines := resp.output.split_into_lines()
if lines.len != 3 {
return 0, 0, 0

View File

@ -210,7 +210,7 @@ fn (mut gen_vc GenVC) generate() {
// check if gen_vc dir exists
if !os.is_dir(gen_vc.options.work_dir) {
// try create
os.mkdir(gen_vc.options.work_dir) or { panic(err.msg) }
os.mkdir(gen_vc.options.work_dir) or { panic(err) }
// still dosen't exist... we have a problem
if !os.is_dir(gen_vc.options.work_dir) {
gen_vc.logger.error('error creating directory: $gen_vc.options.work_dir')
@ -246,8 +246,8 @@ fn (mut gen_vc GenVC) generate() {
ts_v := git_log_v.find_between('Date:', '\n').trim_space()
ts_vc := git_log_vc.find_between('Date:', '\n').trim_space()
// parse time as string to time.Time
last_commit_time_v := time.parse(ts_v) or { panic(err.msg) }
last_commit_time_vc := time.parse(ts_vc) or { panic(err.msg) }
last_commit_time_v := time.parse(ts_v) or { panic(err) }
last_commit_time_vc := time.parse(ts_vc) or { panic(err) }
// git dates are in users local timezone and v time.parse does not parse
// timezones at the moment, so for now get unix timestamp from output also
t_unix_v := git_log_v.find_between('Date Unix:', '\n').trim_space().int()

View File

@ -55,7 +55,7 @@ fn report_undocumented_functions_in_path(opt Options, path string) {
}
fn report_undocumented_functions_in_file(opt Options, file string) {
contents := os.read_file(file) or { panic(err.msg) }
contents := os.read_file(file) or { panic(err) }
lines := contents.split('\n')
mut info := []UndocumentedFN{}
for i, line in lines {

View File

@ -53,9 +53,9 @@ pub fn rmrf(path string) {
verbose_trace(@FN, 'rm -rf $path')
if os.exists(path) {
if os.is_dir(path) {
os.rmdir_all(path) or { panic(err.msg) }
os.rmdir_all(path) or { panic(err) }
} else {
os.rm(path) or { panic(err.msg) }
os.rm(path) or { panic(err) }
}
}
}

View File

@ -221,7 +221,7 @@ pub fn (mut ts TestSession) test() {
// cleanup generated .tmp.c files after successfull tests:
if ts.benchmark.nfail == 0 {
if ts.rm_binaries {
os.rmdir_all(ts.vtmp_dir) or { panic(err.msg) }
os.rmdir_all(ts.vtmp_dir) or { panic(err) }
}
}
}
@ -255,7 +255,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
generated_binary_fpath := os.join_path(tmpd, generated_binary_fname)
if os.exists(generated_binary_fpath) {
if ts.rm_binaries {
os.rm(generated_binary_fpath) or { panic(err.msg) }
os.rm(generated_binary_fpath) or { panic(err) }
}
}
mut cmd_options := [ts.vargs]
@ -308,7 +308,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
}
if os.exists(generated_binary_fpath) {
if ts.rm_binaries {
os.rm(generated_binary_fpath) or { panic(err.msg) }
os.rm(generated_binary_fpath) or { panic(err) }
}
}
return pool.no_result
@ -358,7 +358,7 @@ pub fn prepare_test_session(zargs string, folder string, oskipped []string, main
continue
}
}
c := os.read_file(f) or { panic(err.msg) }
c := os.read_file(f) or { panic(err) }
maxc := if c.len > 300 { 300 } else { c.len }
start := c[0..maxc]
if start.contains('module ') && !start.contains('module main') {
@ -436,7 +436,7 @@ pub fn header(msg string) {
pub fn setup_new_vtmp_folder() string {
now := time.sys_mono_now()
new_vtmp_dir := os.join_path(os.temp_dir(), 'v', 'test_session_$now')
os.mkdir_all(new_vtmp_dir) or { panic(err.msg) }
os.mkdir_all(new_vtmp_dir) or { panic(err) }
os.setenv('VTMP', new_vtmp_dir, true)
return new_vtmp_dir
}

View File

@ -101,7 +101,7 @@ fn main() {
scripting.cprintln('# checkout folder: $context.path_v')
if context.cmd_to_run.len > 0 {
cmdres := os.exec(context.cmd_to_run) or {
panic(err.msg)
panic(err)
}
scripting.cprintln('# command: ${context.cmd_to_run:-34s} exit code: ${cmdres.exit_code:-4d} result:')
println(cmdres.output)

View File

@ -28,16 +28,16 @@ fn get_vexe_path() string {
fn new_tdir() string {
tdir_ := os.join_path(os.temp_dir(), rand.ulid())
if os.exists(tdir_) {
os.rmdir(tdir_) or { panic(err.msg) }
os.rmdir(tdir_) or { panic(err) }
}
os.mkdir(tdir_) or { panic(err.msg) }
os.mkdir(tdir_) or { panic(err) }
C.atexit(cleanup_tdir)
return tdir_
}
fn cleanup_tdir() {
println('... removing tdir: $tdir')
os.rmdir_all(tdir) or { panic(err.msg) }
os.rmdir_all(tdir) or { panic(err) }
}
fn main() {
@ -55,7 +55,7 @@ fn main() {
fn check_ok(cmd string) string {
println('> check_ok cmd: $cmd')
res := os.exec(cmd) or { panic(err.msg) }
res := os.exec(cmd) or { panic(err) }
if res.exit_code != 0 {
eprintln('> check_ok failed.\n$res.output')
exit(1)
@ -65,7 +65,7 @@ fn check_ok(cmd string) string {
fn check_fail(cmd string) string {
println('> check_fail cmd: $cmd')
res := os.exec(cmd) or { panic(err.msg) }
res := os.exec(cmd) or { panic(err) }
if res.exit_code == 0 {
eprintln('> check_fail succeeded, but it should have failed.\n$res.output')
exit(1)

View File

@ -55,7 +55,7 @@ fn main() {
//
tpath := os.join_path(session.vtmp_dir, texe)
if tname in tools_in_subfolders {
os.mv_by_cp(tpath, os.join_path(tfolder, tname, texe)) or { panic(err.msg) }
os.mv_by_cp(tpath, os.join_path(tfolder, tname, texe)) or { panic(err) }
continue
}
os.mv_by_cp(tpath, os.join_path(tfolder, texe)) or {

View File

@ -244,7 +244,7 @@ fn (mut f MDFile) check_examples() (int, int) {
mut should_cleanup_vfile := true
// eprintln('>>> checking example $vfile ...')
vcontent := e.text.join('\n') + '\n'
os.write_file(vfile, vcontent) or { panic(err.msg) }
os.write_file(vfile, vcontent) or { panic(err) }
mut acommands := e.command.split(' ')
nofmt := 'nofmt' in acommands
for command in acommands {
@ -331,7 +331,7 @@ fn (mut f MDFile) check_examples() (int, int) {
}
}
if should_cleanup_vfile {
os.rm(vfile) or { panic(err.msg) }
os.rm(vfile) or { panic(err) }
}
}
return errors, oks

View File

@ -58,7 +58,7 @@ fn (c &Create) write_vmod(new bool) {
cerror(err.msg)
exit(1)
}
vmod.write_str(vmod_content(c.name, c.description)) or { panic(err.msg) }
vmod.write_str(vmod_content(c.name, c.description)) or { panic(err) }
vmod.close()
}
@ -71,7 +71,7 @@ fn (c &Create) write_main(new bool) {
cerror(err.msg)
exit(2)
}
mainfile.write_str(main_content()) or { panic(err.msg) }
mainfile.write_str(main_content()) or { panic(err) }
mainfile.close()
}
@ -87,7 +87,7 @@ fn (c &Create) create_git_repo(dir string) {
// We don't really need a .gitignore, it's just a nice-to-have
return
}
fl.write_str(gen_gitignore(c.name)) or { panic(err.msg) }
fl.write_str(gen_gitignore(c.name)) or { panic(err) }
fl.close()
}
}
@ -110,7 +110,7 @@ fn create() {
}
c.description = os.input('Input your project description: ')
println('Initialising ...')
os.mkdir(c.name) or { panic(err.msg) }
os.mkdir(c.name) or { panic(err) }
c.write_vmod(true)
c.write_main(true)
c.create_git_repo(c.name)

View File

@ -126,7 +126,7 @@ fn (vd VDoc) render_search_index(out Output) {
js_search_index.writeln('];')
js_search_data.writeln('];')
out_file_path := os.join_path(out.path, 'search_index.js')
os.write_file(out_file_path, js_search_index.str() + js_search_data.str()) or { panic(err.msg) }
os.write_file(out_file_path, js_search_index.str() + js_search_data.str()) or { panic(err) }
}
fn (mut vd VDoc) render_static_html(out Output) {
@ -162,7 +162,7 @@ fn (vd VDoc) get_resource(name string, out Output) string {
output_path := os.join_path(out.path, name)
if !os.exists(output_path) {
println('Generating $out.typ in "$output_path"')
os.write_file(output_path, res) or { panic(err.msg) }
os.write_file(output_path, res) or { panic(err) }
}
return name
}

View File

@ -162,7 +162,7 @@ fn (vd VDoc) work_processor(mut work sync.Channel, mut wg sync.WaitGroup) {
file_name, content := vd.render_doc(pdoc.d, pdoc.out)
output_path := os.join_path(pdoc.out.path, file_name)
println('Generating $pdoc.out.typ in "$output_path"')
os.write_file(output_path, content) or { panic(err.msg) }
os.write_file(output_path, content) or { panic(err) }
}
wg.done()
}
@ -350,15 +350,15 @@ fn (mut vd VDoc) generate_docs_from_file() {
out.path = os.real_path('.')
}
if !os.exists(out.path) {
os.mkdir(out.path) or { panic(err.msg) }
os.mkdir(out.path) or { panic(err) }
}
if cfg.is_multi {
out.path = os.join_path(out.path, '_docs')
if !os.exists(out.path) {
os.mkdir(out.path) or { panic(err.msg) }
os.mkdir(out.path) or { panic(err) }
} else {
for fname in css_js_assets {
os.rm(os.join_path(out.path, fname)) or { panic(err.msg) }
os.rm(os.join_path(out.path, fname)) or { panic(err) }
}
}
}
@ -372,11 +372,11 @@ fn (mut vd VDoc) generate_docs_from_file() {
vd.render_search_index(out)
// move favicons to target directory
println('Copying favicons...')
favicons := os.ls(favicons_path) or { panic(err.msg) }
favicons := os.ls(favicons_path) or { panic(err) }
for favicon in favicons {
favicon_path := os.join_path(favicons_path, favicon)
destination_path := os.join_path(out.path, favicon)
os.cp(favicon_path, destination_path) or { panic(err.msg) }
os.cp(favicon_path, destination_path) or { panic(err) }
}
}
}

View File

@ -175,7 +175,7 @@ fn (foptions &FormatOptions) format_file(file string) {
file_name := os.file_name(file)
ulid := rand.ulid()
vfmt_output_path := os.join_path(vtmp_folder, 'vfmt_${ulid}_$file_name')
os.write_file(vfmt_output_path, formatted_content) or { panic(err.msg) }
os.write_file(vfmt_output_path, formatted_content) or { panic(err) }
if foptions.is_verbose {
eprintln('fmt.fmt worked and $formatted_content.len bytes were written to $vfmt_output_path .')
}
@ -266,7 +266,7 @@ fn (foptions &FormatOptions) post_process_file(file string, formatted_file_path
}
if foptions.is_w {
if is_formatted_different {
os.mv_by_cp(formatted_file_path, file) or { panic(err.msg) }
os.mv_by_cp(formatted_file_path, file) or { panic(err) }
eprintln('Reformatted file: $file')
} else {
eprintln('Already formatted file: $file')
@ -277,7 +277,7 @@ fn (foptions &FormatOptions) post_process_file(file string, formatted_file_path
}
fn (f FormatOptions) str() string {
return
return
'FormatOptions{ is_l: $f.is_l, is_w: $f.is_w, is_diff: $f.is_diff, is_verbose: $f.is_verbose,' +
' is_all: $f.is_all, is_worker: $f.is_worker, is_debug: $f.is_debug, is_noerror: $f.is_noerror,' +
' is_verify: $f.is_verify" }'
@ -312,7 +312,7 @@ fn get_compile_name_of_potential_v_project(file string) string {
pfolder := os.real_path(os.dir(file))
// a .v project has many 'module main' files in one folder
// if there is only one .v file, then it must be a standalone
all_files_in_pfolder := os.ls(pfolder) or { panic(err.msg) }
all_files_in_pfolder := os.ls(pfolder) or { panic(err) }
mut vfiles := []string{}
for f in all_files_in_pfolder {
vf := os.join_path(pfolder, f)
@ -332,7 +332,7 @@ fn get_compile_name_of_potential_v_project(file string) string {
// a project folder, that should be compiled with `v pfolder`.
mut main_fns := 0
for f in vfiles {
slines := read_source_lines(f) or { panic(err.msg) }
slines := read_source_lines(f) or { panic(err) }
for line in slines {
if line.contains('fn main()') {
main_fns++

View File

@ -71,7 +71,7 @@ fn main() {
'install' {
if module_names.len == 0 && os.exists('./v.mod') {
println('Detected v.mod file inside the project directory. Using it...')
manifest := vmod.from_file('./v.mod') or { panic(err.msg) }
manifest := vmod.from_file('./v.mod') or { panic(err) }
module_names = manifest.dependencies
}
vpm_install(module_names)
@ -331,13 +331,13 @@ fn vpm_remove(module_names []string) {
final_module_path := valid_final_path_of_existing_module(name) or { continue }
println('Removing module "$name"...')
verbose_println('removing folder $final_module_path')
os.rmdir_all(final_module_path) or { panic(err.msg) }
os.rmdir_all(final_module_path) or { panic(err) }
// delete author directory if it is empty
author := name.split('.')[0]
author_dir := os.real_path(os.join_path(settings.vmodules_path, author))
if os.is_dir_empty(author_dir) {
verbose_println('removing author folder $author_dir')
os.rmdir(author_dir) or { panic(err.msg) }
os.rmdir(author_dir) or { panic(err) }
}
}
}
@ -364,7 +364,7 @@ fn valid_final_path_of_existing_module(name string) ?string {
fn ensure_vmodules_dir_exist() {
if !os.is_dir(settings.vmodules_path) {
println('Creating $settings.vmodules_path/ ...')
os.mkdir(settings.vmodules_path) or { panic(err.msg) }
os.mkdir(settings.vmodules_path) or { panic(err) }
}
}
@ -411,7 +411,7 @@ fn get_installed_modules() []string {
fn get_all_modules() []string {
url := get_working_server_url()
r := http.get(url) or { panic(err.msg) }
r := http.get(url) or { panic(err) }
if r.status_code != 200 {
println('Failed to search vpm.vlang.io. Status code: $r.status_code')
exit(1)

View File

@ -184,7 +184,7 @@ fn run_repl(workdir string, vrepl_prefix string) {
}
if r.line.starts_with('print') {
source_code := r.current_source_code(false) + '\n$r.line\n'
os.write_file(file, source_code) or { panic(err.msg) }
os.write_file(file, source_code) or { panic(err) }
s := repl_run_vfile(file) or { return }
print_output(s)
} else {
@ -251,7 +251,7 @@ fn run_repl(workdir string, vrepl_prefix string) {
}
temp_source_code = r.current_source_code(true) + '\n$temp_line\n'
}
os.write_file(temp_file, temp_source_code) or { panic(err.msg) }
os.write_file(temp_file, temp_source_code) or { panic(err) }
s := repl_run_vfile(temp_file) or { return }
if !func_call && s.exit_code == 0 && !temp_flag {
for r.temp_lines.len > 0 {

View File

@ -27,12 +27,12 @@ fn main() {
// The user just wants an independent copy of v, and so we are done.
return
}
backup_old_version_and_rename_newer() or { panic(err.msg) }
backup_old_version_and_rename_newer() or { panic(err) }
println('V built successfully!')
}
fn compile(vroot string, cmd string) {
result := os.exec(cmd) or { panic(err.msg) }
result := os.exec(cmd) or { panic(err) }
if result.exit_code != 0 {
eprintln('cannot compile to `$vroot`: \n$result.output')
exit(1)
@ -76,7 +76,7 @@ fn backup_old_version_and_rename_newer() ?bool {
os.rm(v_file) or { }
list_folder('', 'moving $v2_file to $v_file ...')
os.mv_by_cp(v2_file, v_file) or { panic(err.msg) }
os.mv_by_cp(v2_file, v_file) or { panic(err) }
list_folder('after:', '')

View File

@ -12,7 +12,7 @@ fn main() {
println('Thirdparty "freetype" is already installed.')
} else {
s := os.exec('git clone --depth=1 https://github.com/ubawurinna/freetype-windows-binaries ./thirdparty/freetype/') or {
panic(err.msg)
panic(err)
}
println(s.output)
println('Thirdparty "freetype" installed successfully.')

View File

@ -27,11 +27,11 @@ fn setup_symlink_unix(vexe string) {
if os.system("uname -o | grep -q '[A/a]ndroid'") == 1 {
link_dir := '/usr/local/bin'
if !os.exists(link_dir) {
os.mkdir_all(link_dir) or { panic(err.msg) }
os.mkdir_all(link_dir) or { panic(err) }
}
link_path = link_dir + '/v'
}
ret := os.exec('ln -sf $vexe $link_path') or { panic(err.msg) }
ret := os.exec('ln -sf $vexe $link_path') or { panic(err) }
if ret.exit_code == 0 {
println('Symlink "$link_path" has been created')
} else {
@ -49,14 +49,14 @@ fn setup_symlink_windows(vexe string) {
mut vsymlink := os.join_path(vsymlinkdir, 'v.exe')
// Remove old symlink first (v could have been moved, symlink rerun)
if !os.exists(vsymlinkdir) {
os.mkdir(vsymlinkdir) or { panic(err.msg) }
os.mkdir(vsymlinkdir) or { panic(err) }
} else {
if os.exists(vsymlink) {
os.rm(vsymlink) or { panic(err.msg) }
os.rm(vsymlink) or { panic(err) }
} else {
vsymlink = os.join_path(vsymlinkdir, 'v.bat')
if os.exists(vsymlink) {
os.rm(vsymlink) or { panic(err.msg) }
os.rm(vsymlink) or { panic(err) }
}
vsymlink = os.join_path(vsymlinkdir, 'v.exe')
}
@ -69,9 +69,9 @@ fn setup_symlink_windows(vexe string) {
eprintln('Creating a batch file instead...')
vsymlink = os.join_path(vsymlinkdir, 'v.bat')
if os.exists(vsymlink) {
os.rm(vsymlink) or { panic(err.msg) }
os.rm(vsymlink) or { panic(err) }
}
os.write_file(vsymlink, '@echo off\n$vexe %*') or { panic(err.msg) }
os.write_file(vsymlink, '@echo off\n$vexe %*') or { panic(err) }
eprintln('$vsymlink file written.')
}
if !os.exists(vsymlink) {

View File

@ -41,7 +41,7 @@ fn main() {
app.backup('cmd/tools/vup.exe')
}
app.recompile_v()
os.exec('"$app.vexe" cmd/tools/vup.v') or { panic(err.msg) }
os.exec('"$app.vexe" cmd/tools/vup.v') or { panic(err) }
app.show_current_v_version()
}
@ -88,7 +88,7 @@ fn (app App) make(vself string) {
$if windows {
make = 'make.bat'
}
make_result := os.exec(make) or { panic(err.msg) }
make_result := os.exec(make) or { panic(err) }
app.vprintln(make_result.output)
}
@ -121,7 +121,7 @@ fn (app App) git_command(command string) {
git_result := os.exec('git $command') or {
app.get_git()
// Try it again with (maybe) git installed
os.exec('git $command') or { panic(err.msg) }
os.exec('git $command') or { panic(err) }
}
if git_result.exit_code != 0 {
eprintln(git_result.output)
@ -136,11 +136,11 @@ fn (app App) get_git() {
// We'll use 32 bit because maybe someone out there is using 32-bit windows
os.exec('bitsadmin.exe /transfer "vgit" https://github.com/git-for-windows/git/releases/download/v2.30.0.windows.2/Git-2.30.0.2-32-bit.exe "$os.getwd()/git32.exe"') or {
eprintln('Unable to install git automatically: please install git manually')
panic(err.msg)
panic(err)
}
os.exec('$os.getwd()/git32.exe') or {
eprintln('Unable to install git automatically: please install git manually')
panic(err.msg)
panic(err)
}
} $else { // Probably some kind of *nix, usually need to get using a package manager.
eprintln("error: Install `git` using your system's package manager")

View File

@ -21,7 +21,7 @@ fn test_vet() {
}
fn get_tests_in_dir(dir string) []string {
files := os.ls(dir) or { panic(err.msg) }
files := os.ls(dir) or { panic(err) }
mut tests := files.filter(it.ends_with('.vv'))
tests.sort()
return tests
@ -34,8 +34,8 @@ fn check_path(vexe string, dir string, tests []string) int {
program := path
print(path + ' ')
// -force is needed so that `v vet` would not skip the regression files
res := os.exec('$vexe vet -force $program') or { panic(err.msg) }
mut expected := os.read_file(program.replace('.vv', '') + '.out') or { panic(err.msg) }
res := os.exec('$vexe vet -force $program') or { panic(err) }
mut expected := os.read_file(program.replace('.vv', '') + '.out') or { panic(err) }
expected = clean_line_endings(expected)
found := clean_line_endings(res.output)
if expected != found {

View File

@ -16,7 +16,7 @@ struct User {
}
fn main() {
db := sqlite.connect(':memory:') or { panic(err.msg) }
db := sqlite.connect(':memory:') or { panic(err) }
db.exec('drop table if exists User')
db.exec("create table Module (id integer primary key, name text default '', nr_downloads int default 0, creator int default 0);")
db.exec("create table User (id integer primary key, age int default 0, name text default '', is_customer int default 0);")
@ -33,12 +33,12 @@ fn main() {
sql db {
insert mod into Module
}
modul := sql db {
select from Module where id == 1
}
println(modul.name)
println(modul.creator.name)
}

View File

@ -41,7 +41,7 @@ fn main() {
// by adding `limit 1` we tell V that there will be only one object
println(dash)
existing := db.select from Customer where id == 1 limit 1 or { panic(err.msg) }
existing := db.select from Customer where id == 1 limit 1 or { panic(err) }
println('Existing customer name: $existing.name')
println('Existing customer full information:')
println(existing)

View File

@ -212,13 +212,13 @@ fn (mut app App) run() {
fn init_images(mut app App) {
$if android {
background := os.read_apk_asset('img/background.png') or { panic(err.msg) }
background := os.read_apk_asset('img/background.png') or { panic(err) }
app.background = app.gg.create_image_from_byte_array(background)
bird := os.read_apk_asset('img/bird.png') or { panic(err.msg) }
bird := os.read_apk_asset('img/bird.png') or { panic(err) }
app.bird = app.gg.create_image_from_byte_array(bird)
pipetop := os.read_apk_asset('img/pipetop.png') or { panic(err.msg) }
pipetop := os.read_apk_asset('img/pipetop.png') or { panic(err) }
app.pipetop = app.gg.create_image_from_byte_array(pipetop)
pipebottom := os.read_apk_asset('img/pipebottom.png') or { panic(err.msg) }
pipebottom := os.read_apk_asset('img/pipebottom.png') or { panic(err) }
app.pipebottom = app.gg.create_image_from_byte_array(pipebottom)
} $else {
app.background = app.gg.create_image(os.resource_abs_path('assets/img/background.png'))

View File

@ -98,15 +98,15 @@ fn new_image(w int, h int) Image {
// write out a .ppm file
fn (image Image) save_as_ppm(file_name string) {
npixels := image.width * image.height
mut f_out := os.create(file_name) or { panic(err.msg) }
f_out.writeln('P3') or { panic(err.msg) }
f_out.writeln('$image.width $image.height') or { panic(err.msg) }
f_out.writeln('255') or { panic(err.msg) }
mut f_out := os.create(file_name) or { panic(err) }
f_out.writeln('P3') or { panic(err) }
f_out.writeln('$image.width $image.height') or { panic(err) }
f_out.writeln('255') or { panic(err) }
for i in 0 .. npixels {
c_r := to_int(unsafe { image.data[i] }.x)
c_g := to_int(unsafe { image.data[i] }.y)
c_b := to_int(unsafe { image.data[i] }.z)
f_out.write_str('$c_r $c_g $c_b ') or { panic(err.msg) }
f_out.write_str('$c_r $c_g $c_b ') or { panic(err) }
}
f_out.close()
}

View File

@ -10,7 +10,7 @@ fn exec(path string) string {
mut cmd := os.Command{
path: path
}
cmd.start() or { panic(err.msg) }
cmd.start() or { panic(err) }
for {
line = cmd.read_line()

View File

@ -5,7 +5,7 @@ import os
fn exec(args []string) {
os.execve('/bin/bash', args, []) or {
// eprintln(err)
panic(err.msg)
panic(err)
}
}

View File

@ -47,7 +47,7 @@ echo redirect 1 to 2 1>&2
echo line 3
'
os.write_file('/tmp/test.sh', script) or { panic(err.msg) }
os.write_file('/tmp/test.sh', script) or { panic(err) }
// os.chmod("/tmp/test.sh",0o700) //make executable
// this will work because stderr/stdout are smaller than 4096 chars, once larger there can be deadlocks

View File

@ -25,7 +25,7 @@ fn convert_html_rgb(in_col string) u32 {
query := '#([a-fA-F0-9]{$n_digit})([a-fA-F0-9]{$n_digit})([a-fA-F0-9]{$n_digit})'
mut re := regex.regex_opt(query) or { panic(err.msg) }
mut re := regex.regex_opt(query) or { panic(err) }
start, end := re.match_string(in_col)
println('start: $start, end: $end')
mut res := u32(0)
@ -49,7 +49,7 @@ fn convert_html_rgb_n(in_col string) u32 {
query := '#(?P<red>[a-fA-F0-9]{$n_digit})(?P<green>[a-fA-F0-9]{$n_digit})(?P<blue>[a-fA-F0-9]{$n_digit})'
mut re := regex.regex_opt(query) or { panic(err.msg) }
mut re := regex.regex_opt(query) or { panic(err) }
start, end := re.match_string(in_col)
println('start: $start, end: $end')
mut res := u32(0)

View File

@ -171,12 +171,12 @@ fn data_get() []SiteConfig {
fn data_dump(data []SiteConfig) {
a := json.encode_pretty(data)
os.write_file(os.resource_abs_path('data.json'), a) or { panic(err.msg) }
os.write_file(os.resource_abs_path('data.json'), a) or { panic(err) }
}
fn data_load() []SiteConfig {
data := os.read_file(os.resource_abs_path('data.json')) or { panic(err.msg) }
a := json.decode([]SiteConfig, data) or { panic(err.msg) }
data := os.read_file(os.resource_abs_path('data.json')) or { panic(err) }
a := json.decode([]SiteConfig, data) or { panic(err) }
return a
}
@ -192,5 +192,5 @@ fn main() {
// data_dump(data)
b := filled_in_template()
println(b)
os.write_file('result.md', b) or { panic(err.msg) }
os.write_file('result.md', b) or { panic(err) }
}

View File

@ -44,7 +44,7 @@ fn (mut a App) set_status(msg string, duration_ms int) {
fn (mut a App) save() {
if a.cfile().len > 0 {
b := a.ed
os.write_file(a.cfile(), b.raw()) or { panic(err.msg) }
os.write_file(a.cfile(), b.raw()) or { panic(err) }
a.set_status('Saved', 2000)
} else {
a.set_status('No file loaded', 4000)
@ -456,7 +456,7 @@ fn (mut a App) init_file() {
// 'vico: ' +
a.tui.set_window_title(a.files[a.current_file])
mut b := a.ed
content := os.read_file(a.files[a.current_file]) or { panic(err.msg) }
content := os.read_file(a.files[a.current_file]) or { panic(err) }
b.put(content)
a.ed.cursor.pos_x = init_x
a.ed.cursor.pos_y = init_y

View File

@ -135,7 +135,7 @@ fn main() {
// load TTF fonts
for font_path in font_paths {
mut tf := ttf.TTF_File{}
tf.buf = os.read_bytes(font_path) or { panic(err.msg) }
tf.buf = os.read_bytes(font_path) or { panic(err) }
println('TrueTypeFont file [$font_path] len: $tf.buf.len')
tf.init()
println('Unit per EM: $tf.units_per_em')

View File

@ -28,7 +28,7 @@ fn start_server() ? {
for i, _ in m.clients {
mut c := m.clients[i]
if c.client.state == .open && c.client.id != ws.id {
c.client.write(msg.payload, websocket.OPCode.text_frame) or { panic(err.msg) }
c.client.write(msg.payload, websocket.OPCode.text_frame) or { panic(err) }
}
}
}, s)

View File

@ -25,7 +25,7 @@ fn start_server() ? {
return true
}) ?
s.on_message(fn (mut ws websocket.Client, msg &websocket.Message) ? {
ws.write(msg.payload, msg.opcode) or { panic(err.msg) }
ws.write(msg.payload, msg.opcode) or { panic(err) }
})
s.on_close(fn (mut ws websocket.Client, code int, reason string) ? {
// println('client ($ws.id) closed connection')

View File

@ -32,7 +32,7 @@ pub fn (app &App) index() vweb.Result {
}
pub fn (mut app App) init_once() {
app.db = sqlite.connect('blog.db') or { panic(err.msg) }
app.db = sqlite.connect('blog.db') or { panic(err) }
app.db.exec('create table if not exists article (' + 'id integer primary key, ' + "title text default ''," +
"text text default ''" + ');')
}

View File

@ -13,7 +13,7 @@ fn test_syscallwrappers() {
os.chdir(dot_checks)
checks_v := "checks.v"
assert os.exists(checks_v)
rc := os.exec("v run $checks_v") or { panic(err.msg) }
rc := os.exec("v run $checks_v") or { panic(err) }
assert !rc.output.contains("V panic: An assertion failed.")
assert !rc.output.contains("failed")
assert rc.exit_code == 0

View File

@ -259,7 +259,7 @@ fn (cmd Command) check_version_flag() {
version_flag := cmd.flags.get_bool('version') or { return } // ignore error and handle command normally
if version_flag {
version_cmd := cmd.commands.get('version') or { return } // ignore error and handle command normally
version_cmd.execute(version_cmd) or { panic(err.msg) }
version_cmd.execute(version_cmd) or { panic(err) }
exit(0)
}
}
@ -280,7 +280,7 @@ fn (cmd Command) check_required_flags() {
pub fn (cmd Command) execute_help() {
if cmd.commands.contains('help') {
help_cmd := cmd.commands.get('help') or { return } // ignore error and handle command normally
help_cmd.execute(help_cmd) or { panic(err.msg) }
help_cmd.execute(help_cmd) or { panic(err) }
} else {
print(cmd.help_message())
}

View File

@ -135,7 +135,7 @@ fn test_if_required_flags_get_set() {
}
fn flag_is_set_in_subcommand(cmd cli.Command) ? {
flag := cmd.flags.get_string('flag') or { panic(err.msg) }
flag := cmd.flags.get_string('flag') or { panic(err) }
assert flag == 'value'
}

View File

@ -5,16 +5,16 @@ fn test_if_string_flag_parses() {
flag: .string
name: 'flag'
}
flag.parse(['-flag', 'value1'], false) or { panic(err.msg) }
mut value := flag.get_string() or { panic(err.msg) }
flag.parse(['-flag', 'value1'], false) or { panic(err) }
mut value := flag.get_string() or { panic(err) }
assert value == 'value1'
flag = cli.Flag{
flag: .string
name: 'flag'
}
flag.parse(['-flag=value2'], false) or { panic(err.msg) }
value = flag.get_string() or { panic(err.msg) }
flag.parse(['-flag=value2'], false) or { panic(err) }
value = flag.get_string() or { panic(err) }
assert value == 'value2'
flag = cli.Flag{
@ -22,9 +22,9 @@ fn test_if_string_flag_parses() {
name: 'flag'
multiple: true
}
flag.parse(['-flag=value1'], false) or { panic(err.msg) }
flag.parse(['-flag=value2'], false) or { panic(err.msg) }
mut values := flag.get_strings() or { panic(err.msg) }
flag.parse(['-flag=value1'], false) or { panic(err) }
flag.parse(['-flag=value2'], false) or { panic(err) }
mut values := flag.get_strings() or { panic(err) }
assert values == ['value1', 'value2']
flags := [
@ -40,7 +40,7 @@ fn test_if_string_flag_parses() {
},
]
values = flags.get_strings('flag') or { panic(err.msg) }
values = flags.get_strings('flag') or { panic(err) }
assert values == ['a', 'b', 'c']
}
@ -50,20 +50,20 @@ fn test_if_bool_flag_parses() {
name: 'flag'
}
mut value := false
flag.parse(['-flag'], false) or { panic(err.msg) }
value = flag.get_bool() or { panic(err.msg) }
flag.parse(['-flag'], false) or { panic(err) }
value = flag.get_bool() or { panic(err) }
assert value == true
flag.parse(['-flag', 'false'], false) or { panic(err.msg) }
value = flag.get_bool() or { panic(err.msg) }
flag.parse(['-flag', 'false'], false) or { panic(err) }
value = flag.get_bool() or { panic(err) }
assert value == false
flag.parse(['-flag', 'true'], false) or { panic(err.msg) }
value = flag.get_bool() or { panic(err.msg) }
flag.parse(['-flag', 'true'], false) or { panic(err) }
value = flag.get_bool() or { panic(err) }
assert value == true
flag.parse(['-flag=false'], false) or { panic(err.msg) }
value = flag.get_bool() or { panic(err.msg) }
flag.parse(['-flag=false'], false) or { panic(err) }
value = flag.get_bool() or { panic(err) }
assert value == false
flag.parse(['-flag=true'], false) or { panic(err.msg) }
value = flag.get_bool() or { panic(err.msg) }
flag.parse(['-flag=true'], false) or { panic(err) }
value = flag.get_bool() or { panic(err) }
assert value == true
}
@ -74,8 +74,8 @@ fn test_if_int_flag_parses() {
}
mut value := 0
flag.parse(['-flag', '42'], false) or { panic(err.msg) }
value = flag.get_int() or { panic(err.msg) }
flag.parse(['-flag', '42'], false) or { panic(err) }
value = flag.get_int() or { panic(err) }
assert value == 42
flag = cli.Flag{
@ -83,8 +83,8 @@ fn test_if_int_flag_parses() {
name: 'flag'
}
flag.parse(['-flag=45'], false) or { panic(err.msg) }
value = flag.get_int() or { panic(err.msg) }
flag.parse(['-flag=45'], false) or { panic(err) }
value = flag.get_int() or { panic(err) }
assert value == 45
flag = cli.Flag{
@ -93,9 +93,9 @@ fn test_if_int_flag_parses() {
multiple: true
}
flag.parse(['-flag=42'], false) or { panic(err.msg) }
flag.parse(['-flag=45'], false) or { panic(err.msg) }
mut values := flag.get_ints() or { panic(err.msg) }
flag.parse(['-flag=42'], false) or { panic(err) }
flag.parse(['-flag=45'], false) or { panic(err) }
mut values := flag.get_ints() or { panic(err) }
assert values == [42, 45]
flags := [
@ -111,7 +111,7 @@ fn test_if_int_flag_parses() {
},
]
values = flags.get_ints('flag') or { panic(err.msg) }
values = flags.get_ints('flag') or { panic(err) }
assert values == [1, 2, 3]
}
@ -121,8 +121,8 @@ fn test_if_float_flag_parses() {
name: 'flag'
}
mut value := f64(0)
flag.parse(['-flag', '3.14158'], false) or { panic(err.msg) }
value = flag.get_float() or { panic(err.msg) }
flag.parse(['-flag', '3.14158'], false) or { panic(err) }
value = flag.get_float() or { panic(err) }
assert value == 3.14158
flag = cli.Flag{
@ -130,9 +130,9 @@ fn test_if_float_flag_parses() {
name: 'flag'
}
flag.parse(['-flag=3.14159'], false) or { panic(err.msg) }
flag.parse(['-flag=3.14159'], false) or { panic(err) }
assert flag.value[0].f64() == 3.14159
value = flag.get_float() or { panic(err.msg) }
value = flag.get_float() or { panic(err) }
assert value == 3.14159
flag = cli.Flag{
@ -141,9 +141,9 @@ fn test_if_float_flag_parses() {
multiple: true
}
flag.parse(['-flag=3.1'], false) or { panic(err.msg) }
flag.parse(['-flag=1.3'], false) or { panic(err.msg) }
mut values := flag.get_floats() or { panic(err.msg) }
flag.parse(['-flag=3.1'], false) or { panic(err) }
flag.parse(['-flag=1.3'], false) or { panic(err) }
mut values := flag.get_floats() or { panic(err) }
assert values == [3.1, 1.3]
flags := [
@ -159,7 +159,7 @@ fn test_if_float_flag_parses() {
},
]
values = flags.get_floats('flag') or { panic(err.msg) }
values = flags.get_floats('flag') or { panic(err) }
assert values == [1.1, 2.2, 3.3]
}
@ -170,8 +170,8 @@ fn test_if_flag_parses_with_abbrev() {
abbrev: 'f'
}
mut value := false
flag.parse(['--flag'], true) or { panic(err.msg) }
value = flag.get_bool() or { panic(err.msg) }
flag.parse(['--flag'], true) or { panic(err) }
value = flag.get_bool() or { panic(err) }
assert value == true
value = false
@ -180,8 +180,8 @@ fn test_if_flag_parses_with_abbrev() {
name: 'flag'
abbrev: 'f'
}
flag.parse(['-f'], true) or { panic(err.msg) }
value = flag.get_bool() or { panic(err.msg) }
flag.parse(['-f'], true) or { panic(err) }
value = flag.get_bool() or { panic(err) }
assert value == true
}
@ -191,7 +191,7 @@ fn test_if_multiple_value_on_single_value() {
name: 'flag'
}
flag.parse(['-flag', '3.14158'], false) or { panic(err.msg) }
flag.parse(['-flag', '3.14158'], false) or { panic(err) }
if _ := flag.parse(['-flag', '3.222'], false) {
panic("No multiple value flag don't raise an error!")

View File

@ -110,7 +110,7 @@ pub fn (mut d Digest) checksum() []byte {
tmp[0] = 0x80
pad := ((55 - d.len) % 64) // calculate number of padding bytes
binary.little_endian_put_u64(mut tmp[1 + pad..], d.len << 3) // append length in bits
d.write(tmp[..1 + pad + 8]) or { panic(err.msg) }
d.write(tmp[..1 + pad + 8]) or { panic(err) }
// The previous write ensures that a whole number of
// blocks (i.e. a multiple of 64 bytes) have been hashed.
if d.nx != 0 {
@ -127,7 +127,7 @@ pub fn (mut d Digest) checksum() []byte {
// sum returns the MD5 checksum of the data.
pub fn sum(data []byte) []byte {
mut d := new()
d.write(data) or { panic(err.msg) }
d.write(data) or { panic(err) }
return d.checksum()
}

View File

@ -109,14 +109,14 @@ fn (mut d Digest) checksum() []byte {
mut tmp := []byte{len: (64)}
tmp[0] = 0x80
if int(len) % 64 < 56 {
d.write(tmp[..56 - int(len) % 64]) or { panic(err.msg) }
d.write(tmp[..56 - int(len) % 64]) or { panic(err) }
} else {
d.write(tmp[..64 + 56 - int(len) % 64]) or { panic(err.msg) }
d.write(tmp[..64 + 56 - int(len) % 64]) or { panic(err) }
}
// Length in bits.
len <<= 3
binary.big_endian_put_u64(mut tmp, len)
d.write(tmp[..8]) or { panic(err.msg) }
d.write(tmp[..8]) or { panic(err) }
mut digest := []byte{len: (size)}
binary.big_endian_put_u32(mut digest, d.h[0])
binary.big_endian_put_u32(mut digest[4..], d.h[1])
@ -129,7 +129,7 @@ fn (mut d Digest) checksum() []byte {
// sum returns the SHA-1 checksum of the bytes passed in `data`.
pub fn sum(data []byte) []byte {
mut d := new()
d.write(data) or { panic(err.msg) }
d.write(data) or { panic(err) }
return d.checksum()
}

View File

@ -147,14 +147,14 @@ fn (mut d Digest) checksum() []byte {
mut tmp := []byte{len: (64)}
tmp[0] = 0x80
if int(len) % 64 < 56 {
d.write(tmp[..56 - int(len) % 64]) or { panic(err.msg) }
d.write(tmp[..56 - int(len) % 64]) or { panic(err) }
} else {
d.write(tmp[..64 + 56 - int(len) % 64]) or { panic(err.msg) }
d.write(tmp[..64 + 56 - int(len) % 64]) or { panic(err) }
}
// Length in bits.
len <<= u64(3)
binary.big_endian_put_u64(mut tmp, len)
d.write(tmp[..8]) or { panic(err.msg) }
d.write(tmp[..8]) or { panic(err) }
if d.nx != 0 {
panic('d.nx != 0')
}
@ -181,14 +181,14 @@ pub fn sum(data []byte) []byte {
// sum256 returns the SHA256 checksum of the data.
pub fn sum256(data []byte) []byte {
mut d := new()
d.write(data) or { panic(err.msg) }
d.write(data) or { panic(err) }
return d.checksum()
}
// sum224 returns the SHA224 checksum of the data.
pub fn sum224(data []byte) []byte {
mut d := new224()
d.write(data) or { panic(err.msg) }
d.write(data) or { panic(err) }
sum := d.checksum()
sum224 := []byte{len: (size224)}
copy(sum224, sum[..size224])

View File

@ -219,15 +219,15 @@ fn (mut d Digest) checksum() []byte {
mut tmp := []byte{len: (128)}
tmp[0] = 0x80
if int(len) % 128 < 112 {
d.write(tmp[..112 - int(len) % 128]) or { panic(err.msg) }
d.write(tmp[..112 - int(len) % 128]) or { panic(err) }
} else {
d.write(tmp[..128 + 112 - int(len) % 128]) or { panic(err.msg) }
d.write(tmp[..128 + 112 - int(len) % 128]) or { panic(err) }
}
// Length in bits.
len <<= u64(3)
binary.big_endian_put_u64(mut tmp, u64(0)) // upper 64 bits are always zero, because len variable has type u64
binary.big_endian_put_u64(mut tmp[8..], len)
d.write(tmp[..16]) or { panic(err.msg) }
d.write(tmp[..16]) or { panic(err) }
if d.nx != 0 {
panic('d.nx != 0')
}
@ -248,14 +248,14 @@ fn (mut d Digest) checksum() []byte {
// sum512 returns the SHA512 checksum of the data.
pub fn sum512(data []byte) []byte {
mut d := new_digest(.sha512)
d.write(data) or { panic(err.msg) }
d.write(data) or { panic(err) }
return d.checksum()
}
// sum384 returns the SHA384 checksum of the data.
pub fn sum384(data []byte) []byte {
mut d := new_digest(.sha384)
d.write(data) or { panic(err.msg) }
d.write(data) or { panic(err) }
sum := d.checksum()
sum384 := []byte{len: (size384)}
copy(sum384, sum[..size384])
@ -265,7 +265,7 @@ pub fn sum384(data []byte) []byte {
// sum512_224 returns the Sum512/224 checksum of the data.
pub fn sum512_224(data []byte) []byte {
mut d := new_digest(.sha512_224)
d.write(data) or { panic(err.msg) }
d.write(data) or { panic(err) }
sum := d.checksum()
sum224 := []byte{len: (size224)}
copy(sum224, sum[..size224])
@ -275,7 +275,7 @@ pub fn sum512_224(data []byte) []byte {
// sum512_256 returns the Sum512/256 checksum of the data.
pub fn sum512_256(data []byte) []byte {
mut d := new_digest(.sha512_256)
d.write(data) or { panic(err.msg) }
d.write(data) or { panic(err) }
sum := d.checksum()
sum256 := []byte{len: (size256)}
copy(sum256, sum[..size256])

View File

@ -40,7 +40,7 @@ fn test_can_compile_main_program() {
fn v_compile(vopts string) os.Result {
cmd := '"$vexe" -showcc $vopts'
eprintln('>>> v_compile cmd: $cmd')
res := os.exec(cmd) or { panic(err.msg) }
res := os.exec(cmd) or { panic(err) }
eprintln('>>> v_compile res: $res')
// assert res.exit_code == 0
$if !windows {

View File

@ -162,7 +162,7 @@ fn gg_init_sokol_window(user_data voidptr) {
font_path: g.config.font_path
custom_bold_font_path: g.config.custom_bold_font_path
scale: dpi_scale()
) or { panic(err.msg) }
) or { panic(err) }
// println('FT took ${time.ticks()-t} ms')
g.font_inited = true
} else {
@ -174,7 +174,7 @@ fn gg_init_sokol_window(user_data voidptr) {
bytes_mono: g.config.font_bytes_mono
bytes_italic: g.config.font_bytes_italic
scale: sapp.dpi_scale()
) or { panic(err.msg) }
) or { panic(err) }
g.font_inited = true
} else {
sfont := system_font_path()
@ -183,7 +183,7 @@ fn gg_init_sokol_window(user_data voidptr) {
font_path: sfont
custom_bold_font_path: g.config.custom_bold_font_path
scale: sapp.dpi_scale()
) or { panic(err.msg) }
) or { panic(err) }
g.font_inited = true
}
}

View File

@ -3,7 +3,7 @@ import io
fn read_file(file string, cap int) []string {
mut lines := []string{}
mut f := os.open(file) or { panic(err.msg) }
mut f := os.open(file) or { panic(err) }
defer {
f.close()
}

View File

@ -12,7 +12,7 @@ fn testsuite_begin() {
eprintln('testsuite_begin, tfolder = $tfolder')
os.rmdir_all(tfolder) or { }
assert !os.is_dir(tfolder)
os.mkdir_all(tfolder) or { panic(err.msg) }
os.mkdir_all(tfolder) or { panic(err) }
os.chdir(tfolder)
assert os.is_dir(tfolder)
}

View File

@ -370,7 +370,7 @@ struct Info {
}
fn test_decode_null_object() {
info := json.decode(Info, '{"id": 22, "items": null, "maps": null}') or { panic(err.msg) }
info := json.decode(Info, '{"id": 22, "items": null, "maps": null}') or { panic(err) }
assert info.id == 22
assert '$info.items' == '[]'
assert '$info.maps' == '{}'

View File

@ -106,7 +106,7 @@ pub fn (mut l Log) close() {
fn (mut l Log) log_file(s string, level Level) {
timestamp := time.now().format_ss()
e := tag_to_file(level)
l.ofile.writeln('$timestamp [$e] $s') or { panic(err.msg) }
l.ofile.writeln('$timestamp [$e] $s') or { panic(err) }
}
// log_cli writes log line `s` with `level` to stdout.

View File

@ -56,7 +56,7 @@ fn (mut dtp DTP) read() ?[]byte {
}
fn (mut dtp DTP) close() {
dtp.conn.close() or { panic(err.msg) }
dtp.conn.close() or { panic(err) }
}
struct FTP {

View File

@ -8,14 +8,14 @@ fn test_ftp_cleint() {
// that is why it is not a very good idea to run it in CI.
// If you want to run it manually, use:
// `v -d network vlib/net/ftp/ftp_test.v`
ftp_client_test_inside() or { panic(err.msg) }
ftp_client_test_inside() or { panic(err) }
}
fn ftp_client_test_inside() ? {
mut zftp := ftp.new()
// eprintln(zftp)
defer {
zftp.close() or { panic(err.msg) }
zftp.close() or { panic(err) }
}
connect_result := zftp.connect('ftp.redhat.com') ?
assert connect_result

View File

@ -25,7 +25,7 @@ mut:
fn (mut dom DocumentObjectModel) print_debug(data string) {
$if debug {
if data.len > 0 {
dom.debug_file.writeln(data) or { panic(err.msg) }
dom.debug_file.writeln(data) or { panic(err) }
}
}
}

View File

@ -53,7 +53,7 @@ fn (parser Parser) builder_str() string {
fn (mut parser Parser) print_debug(data string) {
$if debug {
if data.len > 0 {
parser.debug_file.writeln(data) or { panic(err.msg) }
parser.debug_file.writeln(data) or { panic(err) }
}
}
}

View File

@ -34,7 +34,7 @@ fn http_fetch_mock(_methods []string, _config FetchConfig) ?[]Response {
fn test_http_fetch_bare() {
$if !network ? { return }
responses := http_fetch_mock([], FetchConfig{}) or {
panic(err.msg)
panic(err)
}
for response in responses {
assert response.status_code == 200
@ -46,11 +46,11 @@ fn test_http_fetch_with_data() {
responses := http_fetch_mock(['POST', 'PUT', 'PATCH', 'DELETE'], {
data: 'hello world'
}) or {
panic(err.msg)
panic(err)
}
for response in responses {
payload := json.decode(HttpbinResponseBody,response.text) or {
panic(err.msg)
panic(err)
}
assert payload.data == 'hello world'
}
@ -64,11 +64,11 @@ fn test_http_fetch_with_params() {
'c': 'd'
}
}) or {
panic(err.msg)
panic(err)
}
for response in responses {
// payload := json.decode(HttpbinResponseBody,response.text) or {
// panic(err.msg)
// panic(err)
// }
assert response.status_code == 200
// TODO
@ -84,11 +84,11 @@ fn test_http_fetch_with_headers() {
'Test-Header': 'hello world'
}
}) or {
panic(err.msg)
panic(err)
}
for response in responses {
// payload := json.decode(HttpbinResponseBody,response.text) or {
// panic(err.msg)
// panic(err)
// }
assert response.status_code == 200
// TODO

View File

@ -16,7 +16,7 @@ fn test_http_get_from_vlang_utc_now() {
for url in urls {
println('Test getting current time from $url by http.get')
res := http.get(url) or {
panic(err.msg)
panic(err)
}
assert 200 == res.status_code
assert res.text.len > 0
@ -40,7 +40,7 @@ fn test_public_servers() {
for url in urls {
println('Testing http.get on public url: $url ')
res := http.get(url) or {
panic(err.msg)
panic(err)
}
assert 200 == res.status_code
assert res.text.len > 0
@ -54,7 +54,7 @@ fn test_relative_redirects() {
return
} // tempfix periodic: httpbin relative redirects are broken
res := http.get('https://httpbin.org/relative-redirect/3?abc=xyz') or {
panic(err.msg)
panic(err)
}
assert 200 == res.status_code
assert res.text.len > 0

View File

@ -7,9 +7,9 @@ const (
)
fn setup() (&net.TcpListener, &net.TcpConn, &net.TcpConn) {
mut server := net.listen_tcp(server_port) or { panic(err.msg) }
mut client := net.dial_tcp('127.0.0.1:$server_port') or { panic(err.msg) }
mut socket := server.accept() or { panic(err.msg) }
mut server := net.listen_tcp(server_port) or { panic(err) }
mut client := net.dial_tcp('127.0.0.1:$server_port') or { panic(err) }
mut socket := server.accept() or { panic(err) }
$if debug_peer_ip ? {
ip := con.peer_ip() or { '$err' }
eprintln('connection peer_ip: $ip')

View File

@ -44,8 +44,8 @@ fn echo() ? {
}
fn test_tcp() {
mut l := net.listen_tcp(test_port) or { panic(err.msg) }
mut l := net.listen_tcp(test_port) or { panic(err) }
go echo_server(mut l)
echo() or { panic(err.msg) }
echo() or { panic(err) }
l.close() or { }
}

View File

@ -51,8 +51,8 @@ fn echo() ? {
}
fn test_tcp() {
mut l := unix.listen_stream(test_port) or { panic(err.msg) }
mut l := unix.listen_stream(test_port) or { panic(err) }
go echo_server(mut l)
echo() or { panic(err.msg) }
echo() or { panic(err) }
l.close() or { }
}

View File

@ -22,7 +22,7 @@ struct Foo {
}
fn test_orm_sqlite() {
db := sqlite.connect(':memory:') or { panic(err.msg) }
db := sqlite.connect(':memory:') or { panic(err) }
db.exec('drop table if exists User')
db.exec("create table User (id integer primary key, age int default 0, name text default '', is_customer int default 0);")
name := 'Peter'
@ -230,7 +230,7 @@ fn test_orm_pg() {
eprintln(term.red('NB: this test requires VDB_NAME and VDB_USER env variables to be set'))
return
}
db := pg.connect(dbname: dbname, user: dbuser) or { panic(err.msg) }
db := pg.connect(dbname: dbname, user: dbuser) or { panic(err) }
_ = db
nr_modules := db.select count from modules
//nr_modules := db.select count from Modules where id == 1

View File

@ -11,14 +11,14 @@ fn testsuite_begin() {
eprintln('testsuite_begin, tfolder = $tfolder')
os.rmdir_all(tfolder) or { }
assert !os.is_dir(tfolder)
os.mkdir_all(tfolder) or { panic(err.msg) }
os.mkdir_all(tfolder) or { panic(err) }
os.chdir(tfolder)
assert os.is_dir(tfolder)
}
fn testsuite_end() {
os.chdir(os.wd_at_startup)
os.rmdir_all(tfolder) or { panic(err.msg) }
os.rmdir_all(tfolder) or { panic(err) }
assert !os.is_dir(tfolder)
}
@ -27,7 +27,7 @@ fn test_inode_file_type() {
mut file := os.open_file(filename, 'w', 0o600) or { return }
file.close()
mode := os.inode(filename)
os.rm(filename) or { panic(err.msg) }
os.rm(filename) or { panic(err) }
assert mode.typ == .regular
}

View File

@ -507,7 +507,7 @@ pub fn cache_dir() string {
}
cdir := join_path(home_dir(), '.cache')
if !is_dir(cdir) && !is_link(cdir) {
mkdir(cdir) or { panic(err.msg) }
mkdir(cdir) or { panic(err) }
}
return cdir
}

View File

@ -15,7 +15,7 @@ fn testsuite_begin() {
eprintln('testsuite_begin, tfolder = $tfolder')
os.rmdir_all(tfolder) or { }
assert !os.is_dir(tfolder)
os.mkdir_all(tfolder) or { panic(err.msg) }
os.mkdir_all(tfolder) or { panic(err) }
os.chdir(tfolder)
assert os.is_dir(tfolder)
// println('args_at_start: $args_at_start')
@ -37,13 +37,13 @@ fn test_open_file() {
assert err.msg == 'No such file or directory'
os.File{}
}
mut file := os.open_file(filename, 'w+', 0o666) or { panic(err.msg) }
file.write_str(hello) or { panic(err.msg) }
mut file := os.open_file(filename, 'w+', 0o666) or { panic(err) }
file.write_str(hello) or { panic(err) }
file.close()
assert hello.len == os.file_size(filename)
read_hello := os.read_file(filename) or { panic('error reading file $filename') }
assert hello == read_hello
os.rm(filename) or { panic(err.msg) }
os.rm(filename) or { panic(err) }
}
fn test_open_file_binary() {
@ -53,14 +53,14 @@ fn test_open_file_binary() {
assert err.msg == 'No such file or directory'
os.File{}
}
mut file := os.open_file(filename, 'wb+', 0o666) or { panic(err.msg) }
mut file := os.open_file(filename, 'wb+', 0o666) or { panic(err) }
bytes := hello.bytes()
file.write_bytes(bytes.data, bytes.len)
file.close()
assert hello.len == os.file_size(filename)
read_hello := os.read_bytes(filename) or { panic('error reading file $filename') }
assert bytes == read_hello
os.rm(filename) or { panic(err.msg) }
os.rm(filename) or { panic(err) }
}
// fn test_file_get_line() {
@ -86,24 +86,24 @@ fn test_open_file_binary() {
fn test_create_file() {
filename := './test1.txt'
hello := 'hello world!'
mut f := os.create(filename) or { panic(err.msg) }
f.write_str(hello) or { panic(err.msg) }
mut f := os.create(filename) or { panic(err) }
f.write_str(hello) or { panic(err) }
f.close()
assert hello.len == os.file_size(filename)
os.rm(filename) or { panic(err.msg) }
os.rm(filename) or { panic(err) }
}
fn test_is_file() {
// Setup
work_dir := os.join_path(os.getwd(), 'is_file_test')
os.mkdir_all(work_dir) or { panic(err.msg) }
os.mkdir_all(work_dir) or { panic(err) }
tfile := os.join_path(work_dir, 'tmp_file')
// Test things that shouldn't be a file
assert os.is_file(work_dir) == false
assert os.is_file('non-existent_file.tmp') == false
// Test file
tfile_content := 'temporary file'
os.write_file(tfile, tfile_content) or { panic(err.msg) }
os.write_file(tfile, tfile_content) or { panic(err) }
assert os.is_file(tfile)
// Test dir symlinks
$if windows {
@ -126,11 +126,11 @@ fn test_is_file() {
fn test_write_and_read_string_to_file() {
filename := './test1.txt'
hello := 'hello world!'
os.write_file(filename, hello) or { panic(err.msg) }
os.write_file(filename, hello) or { panic(err) }
assert hello.len == os.file_size(filename)
read_hello := os.read_file(filename) or { panic('error reading file $filename') }
assert hello == read_hello
os.rm(filename) or { panic(err.msg) }
os.rm(filename) or { panic(err) }
}
// test_write_and_read_bytes checks for regressions made in the functions
@ -166,16 +166,16 @@ fn test_write_and_read_bytes() {
assert nread == 0
file_read.close()
// We finally delete the test file.
os.rm(file_name) or { panic(err.msg) }
os.rm(file_name) or { panic(err) }
}
fn test_create_and_delete_folder() {
folder := './test1'
os.mkdir(folder) or { panic(err.msg) }
os.mkdir(folder) or { panic(err) }
assert os.is_dir(folder)
folder_contents := os.ls(folder) or { panic(err.msg) }
folder_contents := os.ls(folder) or { panic(err) }
assert folder_contents.len == 0
os.rmdir(folder) or { panic(err.msg) }
os.rmdir(folder) or { panic(err) }
folder_exists := os.is_dir(folder)
assert folder_exists == false
}
@ -189,63 +189,63 @@ fn walk_callback(file string) {
fn test_walk() {
folder := 'test_walk'
os.mkdir(folder) or { panic(err.msg) }
os.mkdir(folder) or { panic(err) }
file1 := folder + os.path_separator + 'test1'
os.write_file(file1, 'test-1') or { panic(err.msg) }
os.write_file(file1, 'test-1') or { panic(err) }
os.walk(folder, walk_callback)
os.rm(file1) or { panic(err.msg) }
os.rmdir(folder) or { panic(err.msg) }
os.rm(file1) or { panic(err) }
os.rmdir(folder) or { panic(err) }
}
fn test_cp() {
old_file_name := 'cp_example.txt'
new_file_name := 'cp_new_example.txt'
os.write_file(old_file_name, 'Test data 1 2 3, V is awesome #$%^[]!~') or { panic(err.msg) }
os.write_file(old_file_name, 'Test data 1 2 3, V is awesome #$%^[]!~') or { panic(err) }
os.cp(old_file_name, new_file_name) or { panic('$err') }
old_file := os.read_file(old_file_name) or { panic(err.msg) }
new_file := os.read_file(new_file_name) or { panic(err.msg) }
old_file := os.read_file(old_file_name) or { panic(err) }
new_file := os.read_file(new_file_name) or { panic(err) }
assert old_file == new_file
os.rm(old_file_name) or { panic(err.msg) }
os.rm(new_file_name) or { panic(err.msg) }
os.rm(old_file_name) or { panic(err) }
os.rm(new_file_name) or { panic(err) }
}
fn test_mv() {
work_dir := os.join_path(os.getwd(), 'mv_test')
os.mkdir_all(work_dir) or { panic(err.msg) }
os.mkdir_all(work_dir) or { panic(err) }
// Setup test files
tfile1 := os.join_path(work_dir, 'file')
tfile2 := os.join_path(work_dir, 'file.test')
tfile3 := os.join_path(work_dir, 'file.3')
tfile_content := 'temporary file'
os.write_file(tfile1, tfile_content) or { panic(err.msg) }
os.write_file(tfile2, tfile_content) or { panic(err.msg) }
os.write_file(tfile1, tfile_content) or { panic(err) }
os.write_file(tfile2, tfile_content) or { panic(err) }
// Setup test dirs
tdir1 := os.join_path(work_dir, 'dir')
tdir2 := os.join_path(work_dir, 'dir2')
tdir3 := os.join_path(work_dir, 'dir3')
os.mkdir(tdir1) or { panic(err.msg) }
os.mkdir(tdir2) or { panic(err.msg) }
os.mkdir(tdir1) or { panic(err) }
os.mkdir(tdir2) or { panic(err) }
// Move file with no extension to dir
os.mv(tfile1, tdir1) or { panic(err.msg) }
os.mv(tfile1, tdir1) or { panic(err) }
mut expected := os.join_path(tdir1, 'file')
assert os.exists(expected) && !is_dir(expected) == true
// Move dir with contents to other dir
os.mv(tdir1, tdir2) or { panic(err.msg) }
os.mv(tdir1, tdir2) or { panic(err) }
expected = os.join_path(tdir2, 'dir')
assert os.exists(expected) && is_dir(expected) == true
expected = os.join_path(tdir2, 'dir', 'file')
assert os.exists(expected) && !is_dir(expected) == true
// Move dir with contents to other dir (by renaming)
os.mv(os.join_path(tdir2, 'dir'), tdir3) or { panic(err.msg) }
os.mv(os.join_path(tdir2, 'dir'), tdir3) or { panic(err) }
expected = tdir3
assert os.exists(expected) && is_dir(expected) == true
assert os.is_dir_empty(tdir2) == true
// Move file with extension to dir
os.mv(tfile2, tdir2) or { panic(err.msg) }
os.mv(tfile2, tdir2) or { panic(err) }
expected = os.join_path(tdir2, 'file.test')
assert os.exists(expected) && !is_dir(expected) == true
// Move file to dir (by renaming)
os.mv(os.join_path(tdir2, 'file.test'), tfile3) or { panic(err.msg) }
os.mv(os.join_path(tdir2, 'file.test'), tfile3) or { panic(err) }
expected = tfile3
assert os.exists(expected) && !is_dir(expected) == true
}
@ -253,22 +253,22 @@ fn test_mv() {
fn test_cp_all() {
// fileX -> dir/fileX
// NB: clean up of the files happens inside the cleanup_leftovers function
os.write_file('ex1.txt', 'wow!') or { panic(err.msg) }
os.mkdir('ex') or { panic(err.msg) }
os.cp_all('ex1.txt', 'ex', false) or { panic(err.msg) }
old := os.read_file('ex1.txt') or { panic(err.msg) }
new := os.read_file('ex/ex1.txt') or { panic(err.msg) }
os.write_file('ex1.txt', 'wow!') or { panic(err) }
os.mkdir('ex') or { panic(err) }
os.cp_all('ex1.txt', 'ex', false) or { panic(err) }
old := os.read_file('ex1.txt') or { panic(err) }
new := os.read_file('ex/ex1.txt') or { panic(err) }
assert old == new
os.mkdir('ex/ex2') or { panic(err.msg) }
os.write_file('ex2.txt', 'great!') or { panic(err.msg) }
os.cp_all('ex2.txt', 'ex/ex2', false) or { panic(err.msg) }
old2 := os.read_file('ex2.txt') or { panic(err.msg) }
new2 := os.read_file('ex/ex2/ex2.txt') or { panic(err.msg) }
os.mkdir('ex/ex2') or { panic(err) }
os.write_file('ex2.txt', 'great!') or { panic(err) }
os.cp_all('ex2.txt', 'ex/ex2', false) or { panic(err) }
old2 := os.read_file('ex2.txt') or { panic(err) }
new2 := os.read_file('ex/ex2/ex2.txt') or { panic(err) }
assert old2 == new2
// recurring on dir -> local dir
os.cp_all('ex', './', true) or { panic(err.msg) }
os.cp_all('ex', './', true) or { panic(err) }
// regression test for executive runs with overwrite := true
os.cp_all('ex', './', true) or { panic(err.msg) }
os.cp_all('ex', './', true) or { panic(err) }
}
fn test_realpath() {
@ -282,10 +282,10 @@ fn test_tmpdir() {
tfile := t + os.path_separator + 'tmpfile.txt'
os.rm(tfile) or { } // just in case
tfile_content := 'this is a temporary file'
os.write_file(tfile, tfile_content) or { panic(err.msg) }
tfile_content_read := os.read_file(tfile) or { panic(err.msg) }
os.write_file(tfile, tfile_content) or { panic(err) }
tfile_content_read := os.read_file(tfile) or { panic(err) }
assert tfile_content_read == tfile_content
os.rm(tfile) or { panic(err.msg) }
os.rm(tfile) or { panic(err) }
}
fn test_is_writable_folder() {
@ -307,13 +307,13 @@ fn test_make_symlink_check_is_link_and_remove_symlink() {
symlink := 'tsymlink'
os.rm(symlink) or { }
os.rm(folder) or { }
os.mkdir(folder) or { panic(err.msg) }
folder_contents := os.ls(folder) or { panic(err.msg) }
os.mkdir(folder) or { panic(err) }
folder_contents := os.ls(folder) or { panic(err) }
assert folder_contents.len == 0
os.system('ln -s $folder $symlink')
assert os.is_link(symlink) == true
os.rm(symlink) or { panic(err.msg) }
os.rm(folder) or { panic(err.msg) }
os.rm(symlink) or { panic(err) }
os.rm(folder) or { panic(err) }
folder_exists := os.is_dir(folder)
assert folder_exists == false
symlink_exists := os.is_link(symlink)
@ -345,12 +345,12 @@ fn test_symlink() {
$if windows {
return
}
os.mkdir('symlink') or { panic(err.msg) }
os.symlink('symlink', 'symlink2') or { panic(err.msg) }
os.mkdir('symlink') or { panic(err) }
os.symlink('symlink', 'symlink2') or { panic(err) }
assert os.exists('symlink2')
// cleanup
os.rm('symlink') or { panic(err.msg) }
os.rm('symlink2') or { panic(err.msg) }
os.rm('symlink') or { panic(err) }
os.rm('symlink2') or { panic(err) }
}
fn test_is_executable_writable_readable() {
@ -373,7 +373,7 @@ fn test_is_executable_writable_readable() {
assert os.is_executable(file_name)
}
// We finally delete the test file.
os.rm(file_name) or { panic(err.msg) }
os.rm(file_name) or { panic(err) }
}
fn test_ext() {
@ -457,8 +457,8 @@ fn test_write_file_array_bytes() {
for i in 0 .. maxn {
arr[i] = 65 + byte(i)
}
os.write_file_array(fpath, arr) or { panic(err.msg) }
rarr := os.read_bytes(fpath) or { panic(err.msg) }
os.write_file_array(fpath, arr) or { panic(err) }
rarr := os.read_bytes(fpath) or { panic(err) }
assert arr == rarr
// eprintln(arr.str())
// eprintln(rarr.str())
@ -470,7 +470,7 @@ fn test_write_file_array_structs() {
for i in 0 .. maxn {
arr[i] = IntPoint{65 + i, 65 + i + 10}
}
os.write_file_array(fpath, arr) or { panic(err.msg) }
os.write_file_array(fpath, arr) or { panic(err) }
rarr := os.read_file_array<IntPoint>(fpath)
assert rarr == arr
assert rarr.len == maxn

View File

@ -7,7 +7,7 @@ fn no_lines(s string) string {
fn test_struct_readline() {
// mut rl := Readline{}
// eprintln('rl: $rl')
// line := rl.read_line('Please, enter your name: ') or { panic(err.msg) }
// line := rl.read_line('Please, enter your name: ') or { panic(err) }
// eprintln('line: $line')
mut methods := []string{}
$for method in Readline.methods {

View File

@ -5,7 +5,7 @@ fn test_sqlite() {
return
}
mut db := sqlite.connect(':memory:') or {
panic(err.msg)
panic(err)
}
assert db.is_open
db.exec('drop table if exists users')
@ -23,11 +23,11 @@ fn test_sqlite() {
code = db.exec_none('vacuum')
assert code == 101
user := db.exec_one('select * from users where id = 3') or {
panic(err.msg)
panic(err)
}
assert user.vals.len == 2
db.close() or {
panic(err.msg)
panic(err)
}
assert !db.is_open
}

View File

@ -125,7 +125,7 @@ fn (mut ctx Context) termios_setup() ? {
os.signal(C.SIGCONT, fn () {
mut c := ctx_ptr
if c != 0 {
c.termios_setup() or { panic(err.msg) }
c.termios_setup() or { panic(err) }
c.window_height, c.window_width = get_terminal_size()
mut event := &Event{
typ: .resized

View File

@ -205,7 +205,7 @@ pub fn (b Builder) v_files_from_dir(dir string) []string {
} else if !os.is_dir(dir) {
verror("$dir isn't a directory!")
}
mut files := os.ls(dir) or { panic(err.msg) }
mut files := os.ls(dir) or { panic(err) }
if b.pref.is_verbose {
println('v_files_from_dir ("$dir")')
}

View File

@ -42,8 +42,8 @@ pub fn (mut b Builder) build_c(v_files []string, out_file string) {
b.pref.out_name_c = os.real_path(out_file)
b.info('build_c($out_file)')
output2 := b.gen_c(v_files)
mut f := os.create(out_file) or { panic(err.msg) }
f.writeln(output2) or { panic(err.msg) }
mut f := os.create(out_file) or { panic(err) }
f.writeln(output2) or { panic(err) }
f.close()
if b.pref.is_stats {
println('generated C source code size: ${util.bold((output2.count('\n') + 1).str())} lines, ${util.bold(output2.len.str())} bytes')
@ -86,9 +86,9 @@ pub fn (mut b Builder) compile_c() {
bundle_name := b.pref.out_name.split('/').last()
bundle_id := if b.pref.bundle_id != '' { b.pref.bundle_id } else { 'app.vlang.$bundle_name' }
display_name := if b.pref.display_name != '' { b.pref.display_name } else { bundle_name }
os.mkdir('${display_name}.app') or { panic(err.msg) }
os.mkdir('${display_name}.app') or { panic(err) }
os.write_file('${display_name}.app/Info.plist', make_ios_plist(display_name, bundle_id,
bundle_name, 1)) or { panic(err.msg) }
bundle_name, 1)) or { panic(err) }
}
b.cc()
}

View File

@ -90,7 +90,7 @@ fn (mut v Builder) post_process_c_compiler_output(res os.Result) {
if v.pref.is_verbose {
eprintln('>> remove tmp file: $tmpfile')
}
os.rm(tmpfile) or { panic(err.msg) }
os.rm(tmpfile) or { panic(err) }
}
}
return
@ -418,7 +418,7 @@ fn (mut v Builder) setup_output_name() {
println('Building $v.pref.path to $v.pref.out_name ...')
}
v.pref.cache_manager.save('.description.txt', v.pref.path, '${v.pref.path:-30} @ $v.pref.cache_manager.vopts\n') or {
panic(err.msg)
panic(err)
}
// println('v.table.imports:')
// println(v.table.imports)
@ -469,7 +469,7 @@ fn (mut v Builder) vjs_cc() bool {
}
}
// v.out_name_c may be on a different partition than v.out_name
os.mv_by_cp(v.out_name_c, v.pref.out_name) or { panic(err.msg) }
os.mv_by_cp(v.out_name_c, v.pref.out_name) or { panic(err) }
return true
}
return false
@ -481,7 +481,7 @@ fn (mut v Builder) dump_c_options(all_args []string) {
if v.pref.dump_c_flags == '-' {
print(non_empty_args)
} else {
os.write_file(v.pref.dump_c_flags, non_empty_args) or { panic(err.msg) }
os.write_file(v.pref.dump_c_flags, non_empty_args) or { panic(err) }
}
}
}
@ -759,7 +759,7 @@ fn (mut b Builder) cc_linux_cross() {
b.setup_output_name()
parent_dir := os.vmodules_dir()
if !os.exists(parent_dir) {
os.mkdir(parent_dir) or { panic(err.msg) }
os.mkdir(parent_dir) or { panic(err) }
}
sysroot := os.join_path(os.vmodules_dir(), 'linuxroot')
if !os.is_dir(sysroot) {
@ -963,7 +963,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
// for example thirdparty\tcc\lib\openlibm.o
// the best we can do for them is just copy them,
// and hope that they work with any compiler...
os.cp(obj_path, opath) or { panic(err.msg) }
os.cp(obj_path, opath) or { panic(err) }
return
}
println('$obj_path not found, building it in $opath ...')
@ -994,7 +994,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
return
}
v.pref.cache_manager.save('.description.txt', obj_path, '${obj_path:-30} @ $cmd\n') or {
panic(err.msg)
panic(err)
}
println(res.output)
}

View File

@ -93,12 +93,12 @@ fn (mut b Builder) run_compiled_executable_and_exit() {
}
if b.pref.os == .ios {
device := '"iPhone SE (2nd generation)"'
os.exec('xcrun simctl boot $device') or { panic(err.msg) }
os.exec('xcrun simctl boot $device') or { panic(err) }
bundle_name := b.pref.out_name.split('/').last()
display_name := if b.pref.display_name != '' { b.pref.display_name } else { bundle_name }
os.exec('xcrun simctl install $device ${display_name}.app') or { panic(err.msg) }
os.exec('xcrun simctl install $device ${display_name}.app') or { panic(err) }
bundle_id := if b.pref.bundle_id != '' { b.pref.bundle_id } else { 'app.vlang.$bundle_name' }
os.exec('xcrun simctl launch $device $bundle_id') or { panic(err.msg) }
os.exec('xcrun simctl launch $device $bundle_id') or { panic(err) }
} else {
exefile := os.real_path(b.pref.out_name)
mut cmd := '"$exefile"'
@ -133,7 +133,7 @@ fn (mut v Builder) cleanup_run_executable_after_exit(exefile string) {
}
if os.is_file(exefile) {
v.pref.vrun_elog('remove run executable: $exefile')
os.rm(exefile) or { panic(err.msg) }
os.rm(exefile) or { panic(err) }
}
}

View File

@ -34,8 +34,8 @@ pub fn (mut b Builder) build_js(v_files []string, out_file string) {
b.out_name_js = out_file
b.info('build_js($out_file)')
output := b.gen_js(v_files)
mut f := os.create(out_file) or { panic(err.msg) }
f.writeln(output) or { panic(err.msg) }
mut f := os.create(out_file) or { panic(err) }
f.writeln(output) or { panic(err) }
f.close()
}

View File

@ -329,7 +329,7 @@ pub fn (mut v Builder) cc_msvc() {
// println(res)
// println('C OUTPUT:')
// Always remove the object file - it is completely unnecessary
os.rm(out_name_obj) or { panic(err.msg) }
os.rm(out_name_obj) or { panic(err) }
}
fn (mut v Builder) build_thirdparty_obj_file_with_msvc(path string, moduleflags []cflag.CFlag) {

View File

@ -3656,7 +3656,7 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
return node.typ.to_ptr()
}
ast.Assoc {
v := node.scope.find_var(node.var_name) or { panic(err.msg) }
v := node.scope.find_var(node.var_name) or { panic(err) }
for i, _ in node.fields {
c.expr(node.exprs[i])
}

View File

@ -239,14 +239,14 @@ fn (mut task TaskDescription) execute() {
}
program := task.path
cli_cmd := '$task.vexe $task.voptions $program'
res := os.exec(cli_cmd) or { panic(err.msg) }
res := os.exec(cli_cmd) or { panic(err) }
expected_out_path := program.replace('.vv', '') + task.result_extension
task.expected_out_path = expected_out_path
task.cli_cmd = cli_cmd
if should_autofix && !os.exists(expected_out_path) {
os.write_file(expected_out_path, '') or { panic(err.msg) }
os.write_file(expected_out_path, '') or { panic(err) }
}
mut expected := os.read_file(expected_out_path) or { panic(err.msg) }
mut expected := os.read_file(expected_out_path) or { panic(err) }
task.expected = clean_line_endings(expected)
task.found___ = clean_line_endings(res.output)
$if windows {
@ -257,7 +257,7 @@ fn (mut task TaskDescription) execute() {
if task.expected != task.found___ {
task.is_error = true
if should_autofix {
os.write_file(expected_out_path, res.output) or { panic(err.msg) }
os.write_file(expected_out_path, res.output) or { panic(err) }
}
}
}
@ -279,7 +279,7 @@ fn diff_content(s1 string, s2 string) {
}
fn get_tests_in_dir(dir string, is_module bool) []string {
files := os.ls(dir) or { panic(err.msg) }
files := os.ls(dir) or { panic(err) }
mut tests := files.clone()
if !is_module {
tests = files.filter(it.ends_with('.vv'))

View File

@ -67,7 +67,7 @@ fn test_fmt() {
continue
}
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_$ifilename')
os.write_file(vfmt_result_file, result_ocontent) or { panic(err.msg) }
os.write_file(vfmt_result_file, result_ocontent) or { panic(err) }
eprintln(util.color_compare_files(diff_cmd, opath, vfmt_result_file))
continue
}

View File

@ -59,7 +59,7 @@ fn test_fmt() {
continue
}
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_$ifilename')
os.write_file(vfmt_result_file, result_ocontent) or { panic(err.msg) }
os.write_file(vfmt_result_file, result_ocontent) or { panic(err) }
eprintln(util.color_compare_files(diff_cmd, opath, vfmt_result_file))
continue
}

View File

@ -57,7 +57,7 @@ fn test_vlib_fmt() {
continue
}
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_$ifilename')
os.write_file(vfmt_result_file, result_ocontent) or { panic(err.msg) }
os.write_file(vfmt_result_file, result_ocontent) or { panic(err) }
eprintln(util.color_compare_files(diff_cmd, opath, vfmt_result_file))
continue
}

View File

@ -5590,7 +5590,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table.
}
} else if or_block.kind == .propagate {
if g.file.mod.name == 'main' && (isnil(g.fn_decl) || g.fn_decl.name == 'main.main') {
// In main(), an `opt()?` call is sugar for `opt() or { panic(err.msg) }`
// In main(), an `opt()?` call is sugar for `opt() or { panic(err) }`
if g.pref.is_debug {
paline, pafile, pamod, pafn := g.panic_debug_info(or_block.pos)
g.writeln('panic_debug($paline, tos3("$pafile"), tos3("$pamod"), tos3("$pafn"), ${cvar_name}.err.msg );')

View File

@ -18,7 +18,7 @@ fn test_c_files() {
vroot := os.dir(vexe)
for i in 1 .. (nr_tests + 1) {
path := '$vroot/vlib/v/gen/tests/${i}.vv'
ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or { panic(err.msg) }
ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or { panic(err) }
mut b := builder.new_builder(&pref.Preferences{})
b.module_search_paths = ['$vroot/vlib/v/gen/tests/']
mut res := b.gen_c([path]).after('#endbuiltin')

View File

@ -15,7 +15,7 @@ const there_is_node_available = is_nodejs_working()
fn test_example_compilation() {
vexe := os.getenv('VEXE')
os.chdir(os.dir(vexe))
os.mkdir_all(output_dir) or { panic(err.msg) }
os.mkdir_all(output_dir) or { panic(err) }
files := find_test_files()
for file in files {
path := os.join_path(test_dir, file)
@ -40,7 +40,7 @@ fn test_example_compilation() {
}
fn find_test_files() []string {
files := os.ls(test_dir) or { panic(err.msg) }
files := os.ls(test_dir) or { panic(err) }
// The life example never exits, so tests would hang with it, skip
mut tests := files.filter(it.ends_with('.v')).filter(it != 'life.v')
tests.sort()

View File

@ -99,7 +99,7 @@ pub fn (mut g Gen) generate_elf_footer() {
// -5 is for "e8 00 00 00 00"
g.write32_at(g.code_start_pos + 1, int(g.main_fn_addr - g.code_start_pos) - 5)
// Create the binary
mut f := os.create(g.out_name) or { panic(err.msg) }
mut f := os.create(g.out_name) or { panic(err) }
os.chmod(g.out_name, 0o775) // make it an executable
unsafe { f.write_bytes(g.buf.data, g.buf.len) }
f.close()

View File

@ -15,10 +15,10 @@ fn test_x64() {
vexe := os.getenv('VEXE')
vroot := os.dir(vexe)
dir := os.join_path(vroot, 'vlib/v/gen/x64/tests')
files := os.ls(dir) or { panic(err.msg) }
files := os.ls(dir) or { panic(err) }
//
wrkdir := os.join_path(os.temp_dir(), 'vtests', 'x64')
os.mkdir_all(wrkdir) or { panic(err.msg) }
os.mkdir_all(wrkdir) or { panic(err) }
os.chdir(wrkdir)
tests := files.filter(it.ends_with('.vv'))
if tests.len == 0 {
@ -46,7 +46,7 @@ fn test_x64() {
eprintln(res.output)
continue
}
mut expected := os.read_file('$dir/${test}.out') or { panic(err.msg) }
mut expected := os.read_file('$dir/${test}.out') or { panic(err) }
expected = expected.trim_right('\r\n').replace('\r\n', '\n')
mut found := res.output.trim_right('\r\n').replace('\r\n', '\n')
found = found.trim_space()

View File

@ -44,7 +44,7 @@ const (
)
fn get_source_template() string {
src := os.read_file(os.join_path(os.dir(@FILE), 'live_test_template.vv')) or { panic(err.msg) }
src := os.read_file(os.join_path(os.dir(@FILE), 'live_test_template.vv')) or { panic(err) }
return src.replace('#OUTPUT_FILE#', output_file)
}
@ -60,8 +60,8 @@ fn atomic_write_source(source string) {
// NB: here wrtiting is done in 2 steps, since os.write_file can take some time,
// during which the file will be modified, but it will still be not completely written.
// The os.mv after that, guarantees that the reloader will see a complete valid V program.
os.write_file(tmp_file, source) or { panic(err.msg) }
os.mv(tmp_file, source_file) or { panic(err.msg) }
os.write_file(tmp_file, source) or { panic(err) }
os.mv(tmp_file, source_file) or { panic(err) }
}
//

View File

@ -152,7 +152,7 @@ pub fn parse_file(path string, table &table.Table, comments_mode scanner.Comment
// for handling them, and should be removed when we do (the general solution is also needed for vfmt)
// println('parse_file("$path")')
// text := os.read_file(path) or {
// panic(err.msg)
// panic(err)
// }
mut p := Parser{
scanner: scanner.new_scanner_file(path, comments_mode, pref)

View File

@ -488,7 +488,7 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
os.rm(tmp_exe_file_path) or { }
}
res.vrun_elog('remove tmp v file: $tmp_v_file_path')
os.rm(tmp_v_file_path) or { panic(err.msg) }
os.rm(tmp_v_file_path) or { panic(err) }
exit(tmp_result)
}
must_exist(res.path)

View File

@ -1,7 +1,7 @@
type FnCb = fn (a string, b int) ?
fn test_calling_an_anon_function_returning_question() {
create_and_call_anon_function() or { panic(err.msg) }
create_and_call_anon_function() or { panic(err) }
}
fn create_and_call_anon_function() ? {

View File

@ -16,7 +16,7 @@ fn test_all() {
os.chdir(vroot)
diff_cmd := util.find_working_diff_command() or { '' }
dir := 'vlib/v/tests/inout'
files := os.ls(dir) or { panic(err.msg) }
files := os.ls(dir) or { panic(err) }
tests := files.filter(it.ends_with('.vv'))
if tests.len == 0 {
println('no compiler tests found')
@ -28,13 +28,13 @@ fn test_all() {
for path in paths {
print(path + ' ')
program := path
compilation := os.exec('$vexe -o test -cflags "-w" -cg $program') or { panic(err.msg) }
compilation := os.exec('$vexe -o test -cflags "-w" -cg $program') or { panic(err) }
if compilation.exit_code != 0 {
panic('compilation failed: $compilation.output')
}
res := os.exec('./test') or {
println('nope')
panic(err.msg)
panic(err)
}
$if windows {
os.rm('./test.exe') or { }
@ -49,7 +49,7 @@ fn test_all() {
// println(res.output)
// println('============')
mut found := res.output.trim_right('\r\n').replace('\r\n', '\n')
mut expected := os.read_file(program.replace('.vv', '') + '.out') or { panic(err.msg) }
mut expected := os.read_file(program.replace('.vv', '') + '.out') or { panic(err) }
expected = expected.trim_right('\r\n').replace('\r\n', '\n')
if expected.contains('================ V panic ================') {
// panic include backtraces and absolute file paths, so can't do char by char comparison

View File

@ -18,7 +18,7 @@ fn test_vexe_is_set() {
fn test_compiling_without_vmodules_fails() {
os.chdir(vroot)
os.setenv('VMODULES', '', true)
res := os.exec('"$vexe" run "$mainvv"') or { panic(err.msg) }
res := os.exec('"$vexe" run "$mainvv"') or { panic(err) }
assert res.exit_code == 1
assert res.output.trim_space().contains('builder error: cannot import module "yyy" (not found)')
}
@ -27,7 +27,7 @@ fn test_compiling_with_vmodules_works() {
os.chdir(vroot)
vmpaths := ['path1', 'path2', 'path3'].map(os.join_path(basepath, it))
os.setenv('VMODULES', vmpaths.join(os.path_delimiter), true)
res := os.exec('"$vexe" run "$mainvv"') or { panic(err.msg) }
res := os.exec('"$vexe" run "$mainvv"') or { panic(err) }
assert res.exit_code == 0
assert res.output.trim_space() == "['x', 'y', 'z']"
}

View File

@ -84,7 +84,7 @@ fn for_opt_default() ?string {
fn test_opt_default() {
a := for_opt_default() or {
// panic(err.msg)
// panic(err)
'default'
}
assert a == 'default'
@ -258,7 +258,7 @@ fn multi_return_opt(err bool) (string, string) {
fn test_multi_return_opt() {
a, b := multi_return_opt(false) or {
panic(err.msg)
panic(err)
}
assert a == 'hello' && b == 'v'
_, _ := multi_return_opt(true) or {

View File

@ -11,7 +11,7 @@ struct SubStruct {
}
fn test_orm_sub_structs() {
db := sqlite.connect(':memory:') or { panic(err.msg) }
db := sqlite.connect(':memory:') or { panic(err) }
db.exec('create table Upper (id integer primary key, sub int default 0)')
db.exec('create table SubStruct (id integer primary key, name string default "")')

View File

@ -12,11 +12,11 @@ fn test_the_v_compiler_can_be_invoked() {
println('vexecutable: $vexec')
assert vexec != ''
vcmd := '"$vexec" -version'
r := os.exec(vcmd) or { panic(err.msg) }
r := os.exec(vcmd) or { panic(err) }
// println('"$vcmd" exit_code: $r.exit_code | output: $r.output')
assert r.exit_code == 0
vcmd_error := '"$vexec" nonexisting.v'
r_error := os.exec(vcmd_error) or { panic(err.msg) }
r_error := os.exec(vcmd_error) or { panic(err) }
// println('"$vcmd_error" exit_code: $r_error.exit_code | output: $r_error.output')
assert r_error.exit_code == 1
actual_error := r_error.output.trim_space()
@ -36,7 +36,7 @@ fn test_all_v_repl_files() {
}
// warmup, and ensure that the vrepl is compiled in single threaded mode if it does not exist
runner.run_repl_file(os.cache_dir(), session.options.vexec, 'vlib/v/tests/repl/nothing.repl') or {
panic(err.msg)
panic(err)
}
session.bmark.set_total_expected_steps(session.options.files.len)
mut pool_repl := pool.new_pool_processor(
@ -64,23 +64,23 @@ fn worker_repl(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
tls_bench.cstep = idx
tfolder := os.join_path(cdir, 'vrepl_tests_$idx')
if os.is_dir(tfolder) {
os.rmdir_all(tfolder) or { panic(err.msg) }
os.rmdir_all(tfolder) or { panic(err) }
}
os.mkdir(tfolder) or { panic(err.msg) }
os.mkdir(tfolder) or { panic(err) }
file := p.get_item<string>(idx)
session.bmark.step()
tls_bench.step()
fres := runner.run_repl_file(tfolder, session.options.vexec, file) or {
session.bmark.fail()
tls_bench.fail()
os.rmdir_all(tfolder) or { panic(err.msg) }
os.rmdir_all(tfolder) or { panic(err) }
eprintln(tls_bench.step_message_fail(err.msg))
assert false
return pool.no_result
}
session.bmark.ok()
tls_bench.ok()
os.rmdir_all(tfolder) or { panic(err.msg) }
os.rmdir_all(tfolder) or { panic(err) }
println(tls_bench.step_message_ok(fres))
assert true
return pool.no_result

View File

@ -47,22 +47,22 @@ pub fn run_repl_file(wd string, vexec string, file string) ?string {
output := content.all_after('===output===\n').trim_right('\n\r')
fname := os.file_name(file)
input_temporary_filename := os.real_path(os.join_path(wd, 'input_temporary_filename.txt'))
os.write_file(input_temporary_filename, input) or { panic(err.msg) }
os.write_file(os.real_path(os.join_path(wd, 'original.txt')), fcontent) or { panic(err.msg) }
os.write_file(input_temporary_filename, input) or { panic(err) }
os.write_file(os.real_path(os.join_path(wd, 'original.txt')), fcontent) or { panic(err) }
rcmd := '"$vexec" repl -replfolder "$wd" -replprefix "${fname}." < $input_temporary_filename'
r := os.exec(rcmd) or {
os.rm(input_temporary_filename) or { panic(err.msg) }
os.rm(input_temporary_filename) or { panic(err) }
return error('Could not execute: $rcmd')
}
os.rm(input_temporary_filename) or { panic(err.msg) }
os.rm(input_temporary_filename) or { panic(err) }
result := r.output.replace('\r', '').replace('>>> ', '').replace('>>>', '').replace('... ',
'').replace(wd + os.path_separator, '').replace(vexec_folder, '').replace('\\',
'/').trim_right('\n\r')
if result != output {
file_result := '${file}.result.txt'
file_expected := '${file}.expected.txt'
os.write_file(file_result, result) or { panic(err.msg) }
os.write_file(file_expected, output) or { panic(err.msg) }
os.write_file(file_result, result) or { panic(err) }
os.write_file(file_expected, output) or { panic(err) }
diff := diff_files(file_expected, file_result)
return error('Difference found in REPL file: $file
====> Expected :
@ -91,7 +91,7 @@ pub fn run_prod_file(wd string, vexec string, file string) ?string {
result := r.output.replace('\r', '')
if result != expected_content {
file_result := '${file}.result.txt'
os.write_file(file_result, result) or { panic(err.msg) }
os.write_file(file_result, result) or { panic(err) }
diff := diff_files(file_result, file_expected)
return error('Difference found in test: $file
====> Got :

View File

@ -19,10 +19,10 @@ fn pipe_to_v_run() ? {
// eprintln('>> cmd: $cmd | res: $res')
assert res.exit_code == 0
assert res.output.replace('\r', '').trim_space().split('\n') == ['4', 'hello']
os.rm(tmp_v_file) or { panic(err.msg) }
os.rm(tmp_v_file) or { panic(err) }
assert !os.exists(tmp_v_file)
}
fn test_pipe_to_v_run() {
pipe_to_v_run() or { panic(err.msg) }
pipe_to_v_run() or { panic(err) }
}

View File

@ -50,10 +50,10 @@ fn test_all() {
vroot := os.dir(vexe)
valgrind_test_path := 'vlib/v/tests/valgrind'
dir := os.join_path(vroot, valgrind_test_path)
files := os.ls(dir) or { panic(err.msg) }
files := os.ls(dir) or { panic(err) }
//
wrkdir := os.join_path(os.temp_dir(), 'vtests', 'valgrind')
os.mkdir_all(wrkdir) or { panic(err.msg) }
os.mkdir_all(wrkdir) or { panic(err) }
os.chdir(wrkdir)
//
only_ordinary_v_files := files.filter(it.ends_with('.v') && !it.ends_with('_test.v'))

View File

@ -14,7 +14,7 @@ fn new(config Config, shard_count ...int) ?&Client {
fn test_can_compile_an_empty_var_arg() {
x := new(Config{
token: 'xyz'
}) or { panic(err.msg) }
}) or { panic(err) }
assert x.x == 1
assert x.y == 2
}

View File

@ -3,7 +3,7 @@ import os
fn test_from_file() {
os.chdir(os.dir(os.getenv('VEXE')))
data := vmod.from_file('./v.mod') or { panic(err.msg) }
data := vmod.from_file('./v.mod') or { panic(err) }
assert data.name == 'V'
assert data.description == 'The V programming language.'
//assert data.version == '0.2.1'

View File

@ -64,10 +64,10 @@ pub fn color_compare_strings(diff_cmd string, expected string, found string) str
ctime := time.sys_mono_now()
e_file := os.join_path(cdir, '${ctime}.expected.txt')
f_file := os.join_path(cdir, '${ctime}.found.txt')
os.write_file(e_file, expected) or { panic(err.msg) }
os.write_file(f_file, found) or { panic(err.msg) }
os.write_file(e_file, expected) or { panic(err) }
os.write_file(f_file, found) or { panic(err) }
res := color_compare_files(diff_cmd, e_file, f_file)
os.rm(e_file) or { panic(err.msg) }
os.rm(f_file) or { panic(err.msg) }
os.rm(e_file) or { panic(err) }
os.rm(f_file) or { panic(err) }
return res
}

View File

@ -214,7 +214,7 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) {
if should_compile {
emodules := util.external_module_dependencies_for_tool[tool_name]
for emodule in emodules {
check_module_is_installed(emodule, is_verbose) or { panic(err.msg) }
check_module_is_installed(emodule, is_verbose) or { panic(err) }
}
mut compilation_command := '"$vexe" '
if tool_name in ['vself', 'vup', 'vdoctor', 'vsymlink'] {
@ -229,7 +229,7 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) {
if is_verbose {
println('Compiling $tool_name with: "$compilation_command"')
}
tool_compilation := os.exec(compilation_command) or { panic(err.msg) }
tool_compilation := os.exec(compilation_command) or { panic(err) }
if tool_compilation.exit_code != 0 {
eprintln('cannot compile `$tool_source`: \n$tool_compilation.output')
exit(1)
@ -462,7 +462,7 @@ pub fn ensure_modules_for_all_tools_are_installed(is_verbose bool) {
eprintln('Installing modules for tool: $tool_name ...')
}
for emodule in tool_modules {
check_module_is_installed(emodule, is_verbose) or { panic(err.msg) }
check_module_is_installed(emodule, is_verbose) or { panic(err) }
}
}
}
@ -535,7 +535,7 @@ pub fn get_vtmp_folder() string {
}
vtmp = os.join_path(os.temp_dir(), 'v')
if !os.exists(vtmp) || !os.is_dir(vtmp) {
os.mkdir_all(vtmp) or { panic(err.msg) }
os.mkdir_all(vtmp) or { panic(err) }
}
os.setenv('VTMP', vtmp, true)
return vtmp

View File

@ -41,15 +41,13 @@ pub fn new_cache_manager(opts []string) CacheManager {
}
dlog(@FN, 'vcache_basepath: $vcache_basepath | opts:\n $opts')
if !os.is_dir(vcache_basepath) {
os.mkdir_all(vcache_basepath) or { panic(err.msg) }
os.mkdir_all(vcache_basepath) or { panic(err) }
readme_content := 'This folder contains cached build artifacts from the V build system.
|You can safely delete it, if it is getting too large.
|It will be recreated the next time you compile something with V.
|You can change its location with the VCACHE environment variable.
'.strip_margin()
os.write_file(os.join_path(vcache_basepath, 'README.md'), readme_content) or {
panic(err.msg)
}
os.write_file(os.join_path(vcache_basepath, 'README.md'), readme_content) or { panic(err) }
}
original_vopts := opts.join('|')
return CacheManager{
@ -78,7 +76,7 @@ pub fn (mut cm CacheManager) key2cpath(key string) string {
cprefix_folder := os.join_path(cm.basepath, prefix)
cpath = os.join_path(cprefix_folder, khash)
if !os.is_dir(cprefix_folder) {
os.mkdir_all(cprefix_folder) or { panic(err.msg) }
os.mkdir_all(cprefix_folder) or { panic(err) }
os.chmod(cprefix_folder, 0o777)
}
dlog(@FN, 'new hk')

View File

@ -96,10 +96,10 @@ fn (am AssetManager) combine(asset_type string, to_file bool) string {
return out
}
if !os.is_dir(am.cache_dir) {
os.mkdir(am.cache_dir) or { panic(err.msg) }
os.mkdir(am.cache_dir) or { panic(err) }
}
mut file := os.create(out_file) or { panic(err.msg) }
file.write(out.bytes()) or { panic(err.msg) }
mut file := os.create(out_file) or { panic(err) }
file.write(out.bytes()) or { panic(err) }
file.close()
return out_file
}

View File

@ -6,7 +6,7 @@ import os
// unique cache dirs are needed per test function.
fn clean_cache_dir(dir string) {
if os.is_dir(dir) {
os.rmdir_all(dir) or { panic(err.msg) }
os.rmdir_all(dir) or { panic(err) }
}
}
@ -21,10 +21,10 @@ fn cache_dir(test_name string) string {
fn get_test_file_path(file string) string {
path := os.join_path(base_cache_dir(), file)
if !os.is_dir(base_cache_dir()) {
os.mkdir_all(base_cache_dir()) or { panic(err.msg) }
os.mkdir_all(base_cache_dir()) or { panic(err) }
}
if !os.exists(path) {
os.write_file(path, get_test_file_contents(file)) or { panic(err.msg) }
os.write_file(path, get_test_file_contents(file)) or { panic(err) }
}
return path
}

View File

@ -102,14 +102,14 @@ fn assert_common_http_headers(x http.Response) {
}
fn test_http_client_index() {
x := http.get('http://127.0.0.1:$sport/') or { panic(err.msg) }
x := http.get('http://127.0.0.1:$sport/') or { panic(err) }
assert_common_http_headers(x)
assert x.headers['Content-Type'] == 'text/plain'
assert x.text == 'Welcome to VWeb'
}
fn test_http_client_chunk_transfer() {
x := http.get('http://127.0.0.1:$sport/chunk') or { panic(err.msg) }
x := http.get('http://127.0.0.1:$sport/chunk') or { panic(err) }
assert_common_http_headers(x)
assert x.headers['Transfer-Encoding'] == 'chunked'
assert x.text == 'Lorem ipsum dolor sit amet, consetetur sadipscing'
@ -122,45 +122,45 @@ fn test_http_client_404() {
'http://127.0.0.1:$sport/unknown',
]
for url in url_404_list {
res := http.get(url) or { panic(err.msg) }
res := http.get(url) or { panic(err) }
assert res.status_code == 404
}
}
fn test_http_client_simple() {
x := http.get('http://127.0.0.1:$sport/simple') or { panic(err.msg) }
x := http.get('http://127.0.0.1:$sport/simple') or { panic(err) }
assert_common_http_headers(x)
assert x.headers['Content-Type'] == 'text/plain'
assert x.text == 'A simple result'
}
fn test_http_client_html_page() {
x := http.get('http://127.0.0.1:$sport/html_page') or { panic(err.msg) }
x := http.get('http://127.0.0.1:$sport/html_page') or { panic(err) }
assert_common_http_headers(x)
assert x.headers['Content-Type'] == 'text/html'
assert x.text == '<h1>ok</h1>'
}
fn test_http_client_settings_page() {
x := http.get('http://127.0.0.1:$sport/bilbo/settings') or { panic(err.msg) }
x := http.get('http://127.0.0.1:$sport/bilbo/settings') or { panic(err) }
assert_common_http_headers(x)
assert x.text == 'username: bilbo'
//
y := http.get('http://127.0.0.1:$sport/kent/settings') or { panic(err.msg) }
y := http.get('http://127.0.0.1:$sport/kent/settings') or { panic(err) }
assert_common_http_headers(y)
assert y.text == 'username: kent'
}
fn test_http_client_user_repo_settings_page() {
x := http.get('http://127.0.0.1:$sport/bilbo/gostamp/settings') or { panic(err.msg) }
x := http.get('http://127.0.0.1:$sport/bilbo/gostamp/settings') or { panic(err) }
assert_common_http_headers(x)
assert x.text == 'username: bilbo | repository: gostamp'
//
y := http.get('http://127.0.0.1:$sport/kent/golang/settings') or { panic(err.msg) }
y := http.get('http://127.0.0.1:$sport/kent/golang/settings') or { panic(err) }
assert_common_http_headers(y)
assert y.text == 'username: kent | repository: golang'
//
z := http.get('http://127.0.0.1:$sport/missing/golang/settings') or { panic(err.msg) }
z := http.get('http://127.0.0.1:$sport/missing/golang/settings') or { panic(err) }
assert z.status_code == 404
}
@ -175,9 +175,7 @@ fn test_http_client_json_post() {
age: 123
}
json_for_ouser := json.encode(ouser)
mut x := http.post_json('http://127.0.0.1:$sport/json_echo', json_for_ouser) or {
panic(err.msg)
}
mut x := http.post_json('http://127.0.0.1:$sport/json_echo', json_for_ouser) or { panic(err) }
$if debug_net_socket_client ? {
eprintln('/json_echo endpoint response: $x')
}
@ -186,7 +184,7 @@ fn test_http_client_json_post() {
nuser := json.decode(User, x.text) or { User{} }
assert '$ouser' == '$nuser'
//
x = http.post_json('http://127.0.0.1:$sport/json', json_for_ouser) or { panic(err.msg) }
x = http.post_json('http://127.0.0.1:$sport/json', json_for_ouser) or { panic(err) }
$if debug_net_socket_client ? {
eprintln('/json endpoint response: $x')
}

Some files were not shown because too many files have changed in this diff Show More