v/cmd/tools/preludes/tests_assertions.v

42 lines
1.4 KiB
V
Raw Normal View History

module main
import os
// //////////////////////////////////////////////////////////////////
// / This file will get compiled as part of the main program,
// / for a _test.v file.
// / The methods defined here are called back by the test program's
// / assert statements, on each success/fail. The goal is to make
// / customizing the look & feel of the assertions results easier,
// / since it is done in normal V code, instead of in embedded C ...
// //////////////////////////////////////////////////////////////////
// TODO copy pasta builtin.v fn ___print_assert_failure
fn cb_assertion_failed(i &VAssertMetaInfo) {
2020-04-22 01:52:56 +02:00
// color_on := term.can_show_color_on_stderr()
use_relative_paths := match os.getenv('VERROR_PATHS') {
'absolute' {
false
} else {
true
}
2019-12-30 05:23:54 +01:00
}
final_filename := if use_relative_paths { i.fpath } else { os.real_path(i.fpath) }
final_funcname := i.fn_name.replace('main__', '').replace('__', '.')
2020-06-13 16:20:45 +02:00
eprintln('')
eprintln('$final_filename:${i.line_nr+1}: failed assert in ${final_funcname}')
eprintln('Source : ${i.src}')
2020-06-13 16:20:45 +02:00
if i.op.len > 0 && i.op != 'call' {
eprintln(' left value: ${i.llabel} = ${i.lvalue}')
if i.rlabel == i.rvalue {
eprintln(' right value: $i.rlabel')
}
else {
eprintln(' right value: ${i.rlabel} = ${i.rvalue}')
}
}
}
fn cb_assertion_ok(i &VAssertMetaInfo) {
// do nothing for now on an OK assertion
// println('OK ${(i.line_nr+1):5d}|${i.src}')
}