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
|
|
|
|
2021-01-13 10:07:12 +01:00
|
|
|
const use_color = term.can_show_color_on_stderr()
|
|
|
|
|
|
|
|
const use_relative_paths = can_use_relative_paths()
|
|
|
|
|
|
|
|
fn can_use_relative_paths() bool {
|
|
|
|
return match os.getenv('VERROR_PATHS') {
|
|
|
|
'absolute' { false }
|
|
|
|
else { true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-01-13 10:07:12 +01:00
|
|
|
filepath := if use_relative_paths { i.fpath } else { os.real_path(i.fpath) }
|
|
|
|
mut final_filepath := filepath + ':${i.line_nr + 1}:'
|
|
|
|
if use_color {
|
|
|
|
final_filepath = term.gray(final_filepath)
|
2019-12-30 05:23:54 +01:00
|
|
|
}
|
2021-01-13 10:07:12 +01:00
|
|
|
mut final_funcname := 'fn ' + i.fn_name.replace('main.', '').replace('__', '.')
|
|
|
|
if use_color {
|
|
|
|
final_funcname = term.red('✗ ' + final_funcname)
|
|
|
|
}
|
|
|
|
final_src := if use_color { term.dim('assert ${term.bold(i.src)}') } else { 'assert ' + i.src }
|
|
|
|
eprintln('$final_filepath $final_funcname')
|
2020-06-13 16:20:45 +02:00
|
|
|
if i.op.len > 0 && i.op != 'call' {
|
2021-01-13 10:07:12 +01:00
|
|
|
mut lvtitle := ' Left value:'
|
|
|
|
mut rvtitle := ' Right value:'
|
2020-10-14 23:39:09 +02:00
|
|
|
mut slvalue := '$i.lvalue'
|
|
|
|
mut srvalue := '$i.rvalue'
|
2020-07-01 00:53:53 +02:00
|
|
|
if use_color {
|
2021-01-13 10:07:12 +01:00
|
|
|
slvalue = term.yellow(slvalue)
|
|
|
|
srvalue = term.yellow(srvalue)
|
|
|
|
lvtitle = term.gray(lvtitle)
|
|
|
|
rvtitle = term.gray(rvtitle)
|
|
|
|
}
|
|
|
|
cutoff_limit := 30
|
|
|
|
if slvalue.len > cutoff_limit || srvalue.len > cutoff_limit {
|
|
|
|
eprintln(' > $final_src')
|
|
|
|
eprintln(lvtitle)
|
|
|
|
eprintln(' $slvalue')
|
|
|
|
eprintln(rvtitle)
|
|
|
|
eprintln(' $srvalue')
|
|
|
|
} else {
|
|
|
|
eprintln(' > $final_src')
|
|
|
|
eprintln(' $lvtitle $slvalue')
|
|
|
|
eprintln('$rvtitle $srvalue')
|
2020-06-22 16:52:03 +02:00
|
|
|
}
|
2021-01-13 10:07:12 +01:00
|
|
|
} else {
|
|
|
|
eprintln(' $final_src')
|
2020-06-01 13:43:31 +02:00
|
|
|
}
|
2021-01-13 10:07:12 +01:00
|
|
|
eprintln('')
|
2019-10-30 10:15:33 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 13:43:31 +02:00
|
|
|
fn cb_assertion_ok(i &VAssertMetaInfo) {
|
2021-01-13 10:07:12 +01:00
|
|
|
// prints for every assertion instead of per test function
|
|
|
|
// TODO: needs to be changed
|
|
|
|
/*
|
|
|
|
use_color := term.can_show_color_on_stderr()
|
|
|
|
use_relative_paths := match os.getenv('VERROR_PATHS') {
|
|
|
|
'absolute' { false }
|
|
|
|
else { true }
|
|
|
|
}
|
|
|
|
filepath := if use_relative_paths { i.fpath } else { os.real_path(i.fpath) }
|
|
|
|
final_filepath := if use_color {
|
|
|
|
term.gray(filepath + ':${i.line_nr+1}')
|
|
|
|
} else {
|
|
|
|
filepath + ':${i.line_nr+1}'
|
|
|
|
}
|
|
|
|
mut final_funcname := i.fn_name.replace('main.', '').replace('__', '.')
|
|
|
|
if use_color {
|
|
|
|
final_funcname = term.green('✓ ' + final_funcname)
|
|
|
|
}
|
|
|
|
println('$final_funcname ($final_filepath)')
|
|
|
|
*/
|
2020-06-01 13:43:31 +02:00
|
|
|
}
|