tests: show a list of all failed commands in the summary too

pull/10809/head
Delyan Angelov 2021-07-15 09:52:22 +03:00
parent 7c0be629ab
commit 027be2ecd4
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 28 additions and 5 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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.