From 60e718e7c611978bd664cc83b7ec8b335b802f28 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 9 Apr 2022 13:03:52 +0300 Subject: [PATCH] test: save removing the nonexistent binary output for v fmt and v vet tests --- cmd/tools/modules/testing/common.v | 22 +++++++++++----------- cmd/tools/vfmt.v | 8 ++------ vlib/os/os_nix.c.v | 5 ++++- vlib/term/term.v | 4 ++-- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 90063733e7..93d90c1e4d 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -306,12 +306,14 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { mut run_js := false is_fmt := ts.vargs.contains('fmt') + is_vet := ts.vargs.contains('vet') + produces_file_output := !(is_fmt || is_vet) if relative_file.ends_with('js.v') { - if !is_fmt { + if produces_file_output { cmd_options << ' -b js' + run_js = true } - run_js = true } if relative_file.contains('global') && !is_fmt { @@ -333,13 +335,13 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { fname.replace('.v', '') } generated_binary_fpath := os.join_path_single(tmpd, generated_binary_fname) - if os.exists(generated_binary_fpath) { - if ts.rm_binaries { - os.rm(generated_binary_fpath) or {} + if produces_file_output { + if os.exists(generated_binary_fpath) { + if ts.rm_binaries { + os.rm(generated_binary_fpath) or {} + } } - } - if !ts.vargs.contains('fmt') { cmd_options << ' -o ${os.quoted_path(generated_binary_fpath)}' } cmd := '${os.quoted_path(ts.vexe)} ' + cmd_options.join(' ') + ' ${os.quoted_path(file)}' @@ -421,10 +423,8 @@ 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 {} - } + if produces_file_output && os.exists(generated_binary_fpath) && ts.rm_binaries { + os.rm(generated_binary_fpath) or {} } return pool.no_result } diff --git a/cmd/tools/vfmt.v b/cmd/tools/vfmt.v index 7412bfd21b..fbf22de893 100644 --- a/cmd/tools/vfmt.v +++ b/cmd/tools/vfmt.v @@ -247,12 +247,8 @@ fn (mut foptions FormatOptions) post_process_file(file string, formatted_file_pa if !is_formatted_different { return } - x := diff.color_compare_files(foptions.find_diff_cmd(), file, formatted_file_path) - if x.len != 0 { - println("$file is not vfmt'ed") - return error('') - } - return + println("$file is not vfmt'ed") + return error('') } if foptions.is_c { if is_formatted_different { diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index 9d855f34c6..ae8de8ddc0 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -332,7 +332,10 @@ pub fn execute(cmd string) Result { // if cmd.contains(';') || cmd.contains('&&') || cmd.contains('||') || cmd.contains('\n') { // return Result{ exit_code: -1, output: ';, &&, || and \\n are not allowed in shell commands' } // } - pcmd := if cmd.contains('2>') { cmd } else { '$cmd 2>&1' } + pcmd := if cmd.contains('2>') { cmd.clone() } else { '$cmd 2>&1' } + defer { + unsafe { pcmd.free() } + } f := vpopen(pcmd) if isnil(f) { return Result{ diff --git a/vlib/term/term.v b/vlib/term/term.v index 3cf60fef26..646e559775 100644 --- a/vlib/term/term.v +++ b/vlib/term/term.v @@ -142,11 +142,11 @@ pub fn h_divider(divider string) string { // ==== TITLE ========================= pub fn header_left(text string, divider string) string { plain_text := strip_ansi(text) - xcols, _ := get_terminal_size() + xcols, _ := get_terminal_size() // can get 0 in lldb/gdb cols := imax(1, xcols) relement := if divider.len > 0 { divider } else { ' ' } hstart := relement.repeat(4)[0..4] - remaining_cols := (cols - (hstart.len + 1 + plain_text.len + 1)) + remaining_cols := imax(0, (cols - (hstart.len + 1 + plain_text.len + 1))) hend := relement.repeat((remaining_cols + 1) / relement.len)[0..remaining_cols] return '$hstart $text $hend' }