v/cmd/tools/preludes/tests_assertions.v

33 lines
1.2 KiB
V
Raw Normal View History

module main
import os
import term
// //////////////////////////////////////////////////////////////////
// / 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 ...
// //////////////////////////////////////////////////////////////////
fn cb_assertion_failed(filename string, line int, sourceline string, funcname string) {
color_on := term.can_show_color_on_stderr()
use_relative_paths := match os.getenv('VERROR_PATHS') {
'absolute'{
false
}
else {
2019-12-30 05:23:54 +01:00
true}
}
2020-03-20 16:41:18 +01:00
final_filename := if use_relative_paths { filename } else { os.real_path(filename) }
final_funcname := funcname.replace('main__', '').replace('__', '.')
2020-04-03 13:39:11 +02:00
eprintln('File : $final_filename:$line')
eprintln('Function: $final_funcname')
eprintln('Source : $sourceline')
}
fn cb_assertion_ok(filename string, line int, sourceline string, funcname string) {
// do nothing for now on an OK assertion
// println('OK ${line:5d}|$sourceline ')
2019-12-30 05:23:54 +01:00
}