From 027be2ecd43967c2844375fd6e84d04175ab7dd6 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 15 Jul 2021 09:52:22 +0300 Subject: [PATCH] tests: show a list of all failed commands in the summary too --- cmd/tools/modules/testing/common.v | 17 +++++++++++++++++ cmd/tools/vtest-all.v | 2 +- vlib/term/term.v | 14 ++++++++++---- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index bff44d1a32..57ff3e648e 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -33,6 +33,7 @@ pub mut: nmessages chan LogMessage // many publishers, single consumer/printer nmessage_idx int // currently printed message index nprint_ended chan int // read to block till printing ends, 1:1 + failed_cmds shared []string } enum MessageKind { @@ -48,6 +49,18 @@ struct LogMessage { kind MessageKind } +pub fn (mut ts TestSession) add_failed_cmd(cmd string) { + lock ts.failed_cmds { + ts.failed_cmds << cmd + } +} + +pub fn (mut ts TestSession) show_list_of_failed_tests() { + for i, cmd in ts.failed_cmds { + eprintln(term.failed('Failed command ${i + 1}:') + ' $cmd') + } +} + pub fn (mut ts TestSession) append_message(kind MessageKind, msg string) { ts.nmessages <- LogMessage{ message: msg @@ -236,6 +249,7 @@ pub fn (mut ts TestSession) test() { os.rmdir_all(ts.vtmp_dir) or { panic(err) } } } + ts.show_list_of_failed_tests() } fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { @@ -296,6 +310,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { ts.failed = true ts.benchmark.fail() tls_bench.fail() + ts.add_failed_cmd(cmd) return pool.no_result } } else { @@ -308,6 +323,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { ts.benchmark.fail() tls_bench.fail() ts.append_message(.fail, tls_bench.step_message_fail(normalised_relative_file)) + ts.add_failed_cmd(cmd) return pool.no_result } if r.exit_code != 0 { @@ -316,6 +332,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { tls_bench.fail() ending_newline := if r.output.ends_with('\n') { '\n' } else { '' } ts.append_message(.fail, tls_bench.step_message_fail('$normalised_relative_file\n$r.output.trim_space()$ending_newline')) + ts.add_failed_cmd(cmd) } else { ts.benchmark.ok() tls_bench.ok() diff --git a/cmd/tools/vtest-all.v b/cmd/tools/vtest-all.v index 0afbb86697..aaf0164f81 100644 --- a/cmd/tools/vtest-all.v +++ b/cmd/tools/vtest-all.v @@ -33,7 +33,7 @@ fn main() { } for fcmd in fails { msg := if fcmd.errmsg != '' { fcmd.errmsg } else { fcmd.line } - println(term.colorize(term.red, '> Failed: $msg ')) + println(term.failed('> Failed:') + ' $msg') } if fails.len > 0 { exit(1) diff --git a/vlib/term/term.v b/vlib/term/term.v index d011de5213..390b3be31a 100644 --- a/vlib/term/term.v +++ b/vlib/term/term.v @@ -27,6 +27,15 @@ pub fn can_show_color_on_stderr() bool { return supports_escape_sequences(2) } +// failed returns a bold white on red version of the string `s` +// If colors are not allowed, returns the string `s` +pub fn failed(s string) string { + if can_show_color_on_stdout() { + return bg_red(bold(white(s))) + } + return s +} + // ok_message returns a colored string with green color. // If colors are not allowed, returns a given string. pub fn ok_message(s string) string { @@ -39,10 +48,7 @@ pub fn ok_message(s string) string { // fail_message returns a colored string with red color. // If colors are not allowed, returns a given string. pub fn fail_message(s string) string { - if can_show_color_on_stdout() { - return inverse(bg_white(bold(red(' $s ')))) - } - return s + return failed(' $s ') } // warn_message returns a colored string with yellow color.