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

tests: colorize failing tests, improve layout (#8066)

This commit is contained in:
Daniel Däschle
2021-01-13 10:07:12 +01:00
committed by GitHub
parent 4cd50ed566
commit a22982d662
5 changed files with 89 additions and 39 deletions

View File

@@ -189,20 +189,20 @@ pub fn (b &Benchmark) step_message_skip(msg string) string {
// total_message returns a string with total summary of the benchmark run.
pub fn (b &Benchmark) total_message(msg string) string {
mut tmsg := '$msg\n ok, fail, skip, total = ' + term.ok_message('${b.nok:5d}') +
', ' + if b.nfail > 0 { term.red('${b.nfail:5d}') } else { '${b.nfail:5d}' } + ', ' + if b.nskip >
0 { term.bright_yellow('${b.nskip:5d}') } else { '${b.nskip:5d}' } + ', ' + '${b.ntotal:5d}'
if b.verbose {
tmsg = '<=== total time spent $tmsg'
mut tmsg := '${term.bold('Summary:')} '
if b.nfail > 0 {
tmsg += term.bold(term.red('$b.nfail failed')) + ', '
}
mut spaces := ' '
if b.nexpected_steps > 1 {
// NB: the formula below accounts for the progress bar [step/total]
str_steps := '$b.nexpected_steps'
x := 4 + str_steps.len * 2 + 5
spaces = ' '.repeat(x)
if b.nok > 0 {
tmsg += term.bold(term.green('$b.nok passed')) + ', '
}
return spaces + b.tdiff_in_ms(tmsg, b.bench_timer.elapsed().microseconds())
if b.nskip > 0 {
tmsg += term.bold(term.yellow('$b.nskip skipped')) + ', '
}
tmsg += '$b.ntotal total. ${term.bold('Runtime:')} ${b.bench_timer.elapsed().microseconds() /
1000} ms.\n'
tmsg += term.gray(msg)
return tmsg
}
// total_duration returns the duration in ms.

View File

@@ -30,7 +30,8 @@ pub fn can_show_color_on_stderr() bool {
// If colors are not allowed, returns a given string.
pub fn ok_message(s string) string {
return if can_show_color_on_stdout() {
green(s)
msg := ' $s '
green(msg)
} else {
s
}
@@ -40,7 +41,8 @@ pub fn ok_message(s string) string {
// If colors are not allowed, returns a given string.
pub fn fail_message(s string) string {
return if can_show_color_on_stdout() {
bold(bg_red(white(s)))
msg := ' $s '
inverse(bg_white(bold(red(msg))))
} else {
s
}
@@ -50,7 +52,7 @@ pub fn fail_message(s string) string {
// If colors are not allowed, returns a given string.
pub fn warn_message(s string) string {
return if can_show_color_on_stdout() {
bright_yellow(s)
bright_yellow(' $s ')
} else {
s
}