2019-10-30 12:15:33 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import os
|
2019-12-22 02:22:32 +03: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-01 14:43:31 +03:00
|
|
|
fn cb_assertion_failed(i &VAssertMetaInfo) {
|
2020-04-22 02:52:56 +03:00
|
|
|
// color_on := term.can_show_color_on_stderr()
|
2019-10-30 12:15:33 +03:00
|
|
|
use_relative_paths := match os.getenv('VERROR_PATHS') {
|
2020-06-01 14:43:31 +03:00
|
|
|
'absolute' {
|
2019-12-22 02:22:32 +03:00
|
|
|
false
|
2020-06-01 14:43:31 +03:00
|
|
|
} else {
|
|
|
|
true
|
2019-12-22 02:22:32 +03:00
|
|
|
}
|
2019-12-30 07:23:54 +03:00
|
|
|
}
|
2020-06-01 14:43:31 +03: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 17:20:45 +03:00
|
|
|
eprintln('')
|
2020-06-01 14:43:31 +03:00
|
|
|
eprintln('$final_filename:${i.line_nr+1}: failed assert in ${final_funcname}')
|
|
|
|
eprintln('Source : ${i.src}')
|
2020-06-13 17:20:45 +03:00
|
|
|
if i.op.len > 0 && i.op != 'call' {
|
2020-06-01 14:43:31 +03:00
|
|
|
eprintln(' left value: ${i.llabel} = ${i.lvalue}')
|
|
|
|
eprintln(' right value: ${i.rlabel} = ${i.rvalue}')
|
|
|
|
}
|
2019-10-30 12:15:33 +03:00
|
|
|
}
|
|
|
|
|
2020-06-01 14:43:31 +03:00
|
|
|
fn cb_assertion_ok(i &VAssertMetaInfo) {
|
2019-12-22 02:22:32 +03:00
|
|
|
// do nothing for now on an OK assertion
|
2020-06-01 14:43:31 +03:00
|
|
|
// println('OK ${(i.line_nr+1):5d}|${i.src}')
|
|
|
|
}
|