From 21d44072cd210c08c7d5b8400da5a32eef85c111 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 5 Dec 2023 21:37:56 +0200 Subject: [PATCH] tests: improve the formatting of the output of coutput_test.v --- vlib/v/gen/c/coutput_test.v | 31 +++++++++++++------ .../init_fn_with_if_attr_not_defined.vv | 2 +- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/vlib/v/gen/c/coutput_test.v b/vlib/v/gen/c/coutput_test.v index 9fd277989..86e6ed20b 100644 --- a/vlib/v/gen/c/coutput_test.v +++ b/vlib/v/gen/c/coutput_test.v @@ -1,5 +1,6 @@ import os import rand +import time import term import v.util.diff import v.util.vtest @@ -20,6 +21,10 @@ fn mm(s string) string { return term.colorize(term.magenta, s) } +fn mj(input ...string) string { + return mm(input.filter(it.len > 0).join(' ')) +} + fn test_out_files() { println(term.colorize(term.green, '> testing whether .out files match:')) os.chdir(vroot) or {} @@ -45,11 +50,17 @@ fn test_out_files() { // file_options := get_file_options(path) alloptions := '-o ${os.quoted_path(pexe)} ${file_options.vflags}' - print(mm('v ${alloptions} run ${relpath}') + ' == ${mm(out_relpath)} ') + label := mj('v', file_options.vflags, 'run', relpath) + ' == ${mm(out_relpath)} ' // + sw_compile := time.new_stopwatch() compilation := os.execute('${os.quoted_path(vexe)} ${alloptions} ${os.quoted_path(path)}') + compile_ms := sw_compile.elapsed().milliseconds() ensure_compilation_succeeded(compilation) + // + sw_run := time.new_stopwatch() res := os.execute(os.quoted_path(pexe)) + run_ms := sw_run.elapsed().milliseconds() + // if res.exit_code < 0 { println('nope') panic(res.output) @@ -63,7 +74,7 @@ fn test_out_files() { n_expected := normalize_panic_message(expected, vroot) if found.contains('================ V panic ================') { if n_found.starts_with(n_expected) { - println(term.green('OK (panic)')) + println('${term.green('OK (panic)')} C:${compile_ms:5}ms, R:${run_ms:2}ms ${label}') continue } else { // Both have panics, but there was a difference... @@ -75,7 +86,7 @@ fn test_out_files() { } } if expected != found { - println(term.red('FAIL')) + println('${term.red('FAIL')} C:${compile_ms:5}ms, R:${run_ms:2}ms ${label}') println(term.header('expected:', '-')) println(expected) println(term.header('found:', '-')) @@ -88,14 +99,14 @@ fn test_out_files() { } total_errors++ } else { - println(term.green('OK')) + println('${term.green('OK ')} C:${compile_ms:5}ms, R:${run_ms:2}ms ${label}') } } assert total_errors == 0 } fn test_c_must_have_files() { - println(term.colorize(term.green, '> testing whether `.c.must_have` files match:')) + println(term.colorize(term.green, '> testing whether all line patterns in `.c.must_have` files match:')) os.chdir(vroot) or {} output_path := os.join_path(os.vtmp_dir(), 'coutput', 'c_must_have') os.mkdir_all(output_path)! @@ -118,11 +129,11 @@ fn test_c_must_have_files() { } file_options := get_file_options(path) alloptions := '-o - ${file_options.vflags}' - description := mm('v ${alloptions} ${relpath}') + - ' matches all line patterns in ${mm(must_have_relpath)} ' - print(description) + description := mj('v', alloptions, relpath) + ' matches ${mm(must_have_relpath)} ' cmd := '${os.quoted_path(vexe)} ${alloptions} ${os.quoted_path(path)}' + sw_compile := time.new_stopwatch() compilation := os.execute(cmd) + compile_ms := sw_compile.elapsed().milliseconds() ensure_compilation_succeeded(compilation) expected_lines := os.read_lines(must_have_path) or { [] } generated_c_lines := compilation.output.split_into_lines() @@ -134,7 +145,7 @@ fn test_c_must_have_files() { // eprintln('> testing: $must_have_path has line: $eline') } else { failed_patterns << eline - println(term.red('FAIL')) + println('${term.red('FAIL')} C:${compile_ms:5}ms ${description}') eprintln('${must_have_path}:${idx_expected_line + 1}: expected match error:') eprintln('`${cmd}` did NOT produce expected line:') eprintln(term.colorize(term.red, eline)) @@ -146,7 +157,7 @@ fn test_c_must_have_files() { } } if nmatches == expected_lines.len { - println(term.green('OK')) + println('${term.green('OK ')} C:${compile_ms:5}ms ${description}') } else { if show_compilation_output { eprintln('> ALL lines:') diff --git a/vlib/v/gen/c/testdata/init_fn_with_if_attr_not_defined.vv b/vlib/v/gen/c/testdata/init_fn_with_if_attr_not_defined.vv index d5fa28658..99c802c2a 100644 --- a/vlib/v/gen/c/testdata/init_fn_with_if_attr_not_defined.vv +++ b/vlib/v/gen/c/testdata/init_fn_with_if_attr_not_defined.vv @@ -1,4 +1,4 @@ -// vtest vflags: -d init_is_not_defined +// vtest vflags: -d not_defined @[if init_on ?] fn init() { -- 2.39.5