mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: print actual values on a failed assert (when possible)
This commit is contained in:
@@ -9,22 +9,26 @@ import os
|
||||
// / 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) {
|
||||
fn cb_assertion_failed(i &VAssertMetaInfo) {
|
||||
// color_on := term.can_show_color_on_stderr()
|
||||
use_relative_paths := match os.getenv('VERROR_PATHS') {
|
||||
'absolute'{
|
||||
'absolute' {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
else {
|
||||
true}
|
||||
}
|
||||
final_filename := if use_relative_paths { filename } else { os.real_path(filename) }
|
||||
final_funcname := funcname.replace('main__', '').replace('__', '.')
|
||||
eprintln('$final_filename:$line: failed assert in ${final_funcname}')
|
||||
eprintln('Source : $sourceline')
|
||||
final_filename := if use_relative_paths { i.fpath } else { os.real_path(i.fpath) }
|
||||
final_funcname := i.fn_name.replace('main__', '').replace('__', '.')
|
||||
eprintln('$final_filename:${i.line_nr+1}: failed assert in ${final_funcname}')
|
||||
eprintln('Source : ${i.src}')
|
||||
if i.op != 'call' {
|
||||
eprintln(' left value: ${i.llabel} = ${i.lvalue}')
|
||||
eprintln(' right value: ${i.rlabel} = ${i.rvalue}')
|
||||
}
|
||||
}
|
||||
|
||||
fn cb_assertion_ok(filename string, line int, sourceline string, funcname string) {
|
||||
fn cb_assertion_ok(i &VAssertMetaInfo) {
|
||||
// do nothing for now on an OK assertion
|
||||
// println('OK ${line:5d}|$sourceline ')
|
||||
}
|
||||
// println('OK ${(i.line_nr+1):5d}|${i.src}')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user