mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: treat the main module like any other v module
This commit is contained in:
@@ -3,3 +3,7 @@ module main
|
||||
// This prelude is loaded in every v program compiled with -live,
|
||||
// in both the main executable, and in the shared library.
|
||||
import live
|
||||
|
||||
const (
|
||||
no_warning_live_is_used = live.is_used
|
||||
)
|
||||
|
||||
@@ -3,3 +3,7 @@ module main
|
||||
// This prelude is loaded in every v program compiled with -live,
|
||||
// but only for the main executable.
|
||||
import live.executable
|
||||
|
||||
const (
|
||||
no_warning_live_executable_is_used = executable.is_used
|
||||
)
|
||||
|
||||
@@ -3,3 +3,7 @@ module main
|
||||
// This prelude is loaded in every v program compiled with -live,
|
||||
// but only for the shared library.
|
||||
import live.shared
|
||||
|
||||
const (
|
||||
no_warning_live_shared_is_used = shared.is_used
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
import term
|
||||
// //////////////////////////////////////////////////////////////////
|
||||
// / This file will get compiled as part of the main program,
|
||||
// / for a _test.v file.
|
||||
@@ -11,7 +12,7 @@ import os
|
||||
// //////////////////////////////////////////////////////////////////
|
||||
// TODO copy pasta builtin.v fn ___print_assert_failure
|
||||
fn cb_assertion_failed(i &VAssertMetaInfo) {
|
||||
// color_on := term.can_show_color_on_stderr()
|
||||
use_color := term.can_show_color_on_stderr()
|
||||
use_relative_paths := match os.getenv('VERROR_PATHS') {
|
||||
'absolute' {
|
||||
false
|
||||
@@ -20,18 +21,22 @@ fn cb_assertion_failed(i &VAssertMetaInfo) {
|
||||
}
|
||||
}
|
||||
final_filename := if use_relative_paths { i.fpath } else { os.real_path(i.fpath) }
|
||||
final_funcname := i.fn_name.replace('main__', '').replace('__', '.')
|
||||
final_funcname := i.fn_name.replace('main.', '').replace('__', '.')
|
||||
final_src := if use_color { term.bold(i.src) } else { i.src }
|
||||
eprintln('')
|
||||
eprintln('$final_filename:${i.line_nr+1}: failed assert in ${final_funcname}')
|
||||
eprintln('Source : ${i.src}')
|
||||
eprintln('$final_filename:${i.line_nr+1}: failed assert in function ${final_funcname}')
|
||||
eprintln('Source : `${final_src}`')
|
||||
if i.op.len > 0 && i.op != 'call' {
|
||||
eprintln(' left value: ${i.llabel} = ${i.lvalue}')
|
||||
if i.rlabel == i.rvalue {
|
||||
eprintln(' right value: $i.rlabel')
|
||||
}
|
||||
else {
|
||||
eprintln(' right value: ${i.rlabel} = ${i.rvalue}')
|
||||
mut slvalue := '${i.lvalue}'
|
||||
mut srvalue := '${i.rvalue}'
|
||||
lpostfix := if slvalue == i.llabel { '.' } else { '<= `${i.llabel}`' }
|
||||
rpostfix := if srvalue == i.rlabel { '.' } else { '<= `${i.rlabel}`' }
|
||||
if use_color {
|
||||
slvalue = term.bold(term.yellow(slvalue))
|
||||
srvalue = term.bold(term.yellow(srvalue))
|
||||
}
|
||||
eprintln(' left value: ${slvalue} ${lpostfix}')
|
||||
eprintln(' right value: ${srvalue} ${rpostfix}')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ fn start_testing(total_number_of_tests int, vfilename string) BenchedTests {
|
||||
|
||||
// Called before each test_ function, defined in file_test.v
|
||||
fn (mut b BenchedTests) testing_step_start(stepfunc string) {
|
||||
b.step_func_name = stepfunc.replace('main__', '').replace('__', '.')
|
||||
b.step_func_name = stepfunc.replace('main.', '').replace('__', '.')
|
||||
b.oks = C.g_test_oks
|
||||
b.fails = C.g_test_fails
|
||||
b.bench.step()
|
||||
|
||||
Reference in New Issue
Block a user