2019-10-30 10:15:33 +01:00
|
|
|
module main
|
|
|
|
|
|
|
|
import os
|
2020-07-01 00:53:53 +02:00
|
|
|
import term
|
2020-10-14 23:39:09 +02:00
|
|
|
|
2019-12-22 00:22:32 +01:00
|
|
|
// //////////////////////////////////////////////////////////////////
|
|
|
|
// / 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 ...
|
|
|
|
// //////////////////////////////////////////////////////////////////
|
2020-06-22 16:52:03 +02:00
|
|
|
// TODO copy pasta builtin.v fn ___print_assert_failure
|
2020-06-01 13:43:31 +02:00
|
|
|
fn cb_assertion_failed(i &VAssertMetaInfo) {
|
2020-07-01 00:53:53 +02:00
|
|
|
use_color := term.can_show_color_on_stderr()
|
2019-10-30 10:15:33 +01:00
|
|
|
use_relative_paths := match os.getenv('VERROR_PATHS') {
|
2020-10-14 23:39:09 +02:00
|
|
|
'absolute' { false }
|
|
|
|
else { true }
|
2019-12-30 05:23:54 +01:00
|
|
|
}
|
2020-06-01 13:43:31 +02:00
|
|
|
final_filename := if use_relative_paths { i.fpath } else { os.real_path(i.fpath) }
|
2020-07-01 00:53:53 +02:00
|
|
|
final_funcname := i.fn_name.replace('main.', '').replace('__', '.')
|
|
|
|
final_src := if use_color { term.bold(i.src) } else { i.src }
|
2020-06-13 16:20:45 +02:00
|
|
|
eprintln('')
|
2020-10-14 23:39:09 +02:00
|
|
|
eprintln('$final_filename:${i.line_nr+1}: failed assert in function $final_funcname')
|
|
|
|
eprintln('Source : `$final_src`')
|
2020-06-13 16:20:45 +02:00
|
|
|
if i.op.len > 0 && i.op != 'call' {
|
2020-10-14 23:39:09 +02:00
|
|
|
mut slvalue := '$i.lvalue'
|
|
|
|
mut srvalue := '$i.rvalue'
|
|
|
|
lpostfix := if slvalue == i.llabel { '.' } else { '<= `$i.llabel`' }
|
|
|
|
rpostfix := if srvalue == i.rlabel { '.' } else { '<= `$i.rlabel`' }
|
2020-07-01 00:53:53 +02:00
|
|
|
if use_color {
|
|
|
|
slvalue = term.bold(term.yellow(slvalue))
|
|
|
|
srvalue = term.bold(term.yellow(srvalue))
|
2020-06-22 16:52:03 +02:00
|
|
|
}
|
2020-10-14 23:39:09 +02:00
|
|
|
eprintln(' left value: $slvalue $lpostfix')
|
|
|
|
eprintln(' right value: $srvalue $rpostfix')
|
2020-06-01 13:43:31 +02:00
|
|
|
}
|
2019-10-30 10:15:33 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 13:43:31 +02:00
|
|
|
fn cb_assertion_ok(i &VAssertMetaInfo) {
|
2019-12-22 00:22:32 +01:00
|
|
|
// do nothing for now on an OK assertion
|
2020-06-01 13:43:31 +02:00
|
|
|
// println('OK ${(i.line_nr+1):5d}|${i.src}')
|
|
|
|
}
|