1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

testing: fix count of succeeded tests

This commit is contained in:
Kris Cherven 2020-04-17 22:49:03 -04:00 committed by GitHub
parent 5374899f29
commit eb923b4995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 12 deletions

View File

@ -8,6 +8,13 @@ import (
v.pref
)
pub struct TestMessageHandler {
pub mut:
messages []string
message_idx int
mtx &sync.Mutex
}
pub struct TestSession {
pub mut:
files []string
@ -18,10 +25,11 @@ pub mut:
failed bool
benchmark benchmark.Benchmark
show_ok_tests bool
message_handler &TestMessageHandler
}
pub fn new_test_session(_vargs string) TestSession {
mut skip_files := []string
mut skip_files := []string
skip_files << '_non_existing_'
$if solaris {
skip_files << "examples/gg/gg2.v"
@ -41,7 +49,7 @@ pub fn new_test_session(_vargs string) TestSession {
}
pub fn (ts mut TestSession) init() {
ts.benchmark = benchmark.new_benchmark()
ts.benchmark = benchmark.new_benchmark_no_cstep()
}
pub fn (ts mut TestSession) test() {
@ -79,6 +87,10 @@ pub fn (ts mut TestSession) test() {
mut pool_of_test_runners := sync.new_pool_processor(sync.PoolProcessorConfig{
callback: worker_trunner
})
// for handling messages across threads
ts.message_handler = &TestMessageHandler{
mtx: sync.new_mutex()
}
pool_of_test_runners.set_shared_context(ts)
$if msvc {
// NB: MSVC can not be launched in parallel, without giving it
@ -93,8 +105,25 @@ pub fn (ts mut TestSession) test() {
eprintln(term.h_divider('-'))
}
fn next_message(m mut TestMessageHandler) {
m.mtx.lock()
defer {
m.messages.clear()
m.mtx.unlock()
}
for msg in m.messages {
m.message_idx++
eprintln(msg.
replace("TMP1", "${m.message_idx:1d}").
replace("TMP2", "${m.message_idx:2d}").
replace("TMP3", "${m.message_idx:3d}")
)
}
}
fn worker_trunner(p mut sync.PoolProcessor, idx int, thread_id int) voidptr {
mut ts := &TestSession(p.get_shared_context())
defer { next_message(ts.message_handler) }
tmpd := os.temp_dir()
show_stats := '-stats' in ts.vargs.split(' ')
// tls_bench is used to format the step messages/timings
@ -104,7 +133,7 @@ fn worker_trunner(p mut sync.PoolProcessor, idx int, thread_id int) voidptr {
tls_bench.set_total_expected_steps(ts.benchmark.nexpected_steps)
p.set_thread_context(idx, tls_bench)
}
tls_bench.cstep = idx
tls_bench.no_cstep = true
dot_relative_file := p.get_string_item(idx)
relative_file := dot_relative_file.replace(ts.vroot + os.path_separator, '').replace('./', '')
file := os.real_path(relative_file)
@ -127,11 +156,11 @@ fn worker_trunner(p mut sync.PoolProcessor, idx int, thread_id int) voidptr {
if relative_file.replace('\\', '/') in ts.skip_files {
ts.benchmark.skip()
tls_bench.skip()
eprintln(tls_bench.step_message_skip(relative_file))
ts.message_handler.messages << tls_bench.step_message_skip(relative_file)
return sync.no_result
}
if show_stats {
eprintln(term.h_divider('-'))
ts.message_handler.messages << term.h_divider('-')
status := os.system(cmd)
if status == 0 {
ts.benchmark.ok()
@ -149,20 +178,20 @@ fn worker_trunner(p mut sync.PoolProcessor, idx int, thread_id int) voidptr {
ts.failed = true
ts.benchmark.fail()
tls_bench.fail()
eprintln(tls_bench.step_message_fail(relative_file))
ts.message_handler.messages << tls_bench.step_message_fail(relative_file)
return sync.no_result
}
if r.exit_code != 0 {
ts.failed = true
ts.benchmark.fail()
tls_bench.fail()
eprintln(tls_bench.step_message_fail('${relative_file}\n$r.output\n'))
ts.message_handler.messages << tls_bench.step_message_fail('${relative_file}\n$r.output\n')
}
else {
ts.benchmark.ok()
tls_bench.ok()
if ts.show_ok_tests {
eprintln(tls_bench.step_message_ok(relative_file))
ts.message_handler.messages << tls_bench.step_message_ok(relative_file)
}
}
}

View File

@ -65,6 +65,7 @@ pub mut:
verbose bool
nexpected_steps int
cstep int
no_cstep bool
bok string
bfail string
}
@ -76,6 +77,14 @@ pub fn new_benchmark() Benchmark {
}
}
pub fn new_benchmark_no_cstep() Benchmark {
return Benchmark{
bench_start_time: benchmark.now()
verbose: true
no_cstep: true
}
}
pub fn new_benchmark_pointer() &Benchmark {
return &Benchmark{
bench_start_time: benchmark.now()
@ -93,7 +102,9 @@ pub fn (b mut Benchmark) stop() {
pub fn (b mut Benchmark) step() {
b.step_start_time = benchmark.now()
b.cstep++
if !b.no_cstep {
b.cstep++
}
}
pub fn (b mut Benchmark) fail() {
@ -149,13 +160,19 @@ pub fn (b &Benchmark) step_message_with_label(label string, msg string) string {
if b.nexpected_steps > 0 {
mut sprogress := ''
if b.nexpected_steps < 10 {
sprogress = '${b.cstep:1d}/${b.nexpected_steps:1d}'
sprogress = if b.no_cstep { 'TMP1/${b.nexpected_steps:1d}' } else {
'${b.cstep:1d}/${b.nexpected_steps:1d}'
}
}
if b.nexpected_steps >= 10 && b.nexpected_steps < 100 {
sprogress = '${b.cstep:2d}/${b.nexpected_steps:2d}'
sprogress = if b.no_cstep { 'TMP2/${b.nexpected_steps:2d}' } else {
'${b.cstep:2d}/${b.nexpected_steps:2d}'
}
}
if b.nexpected_steps >= 100 && b.nexpected_steps < 1000 {
sprogress = '${b.cstep:3d}/${b.nexpected_steps:3d}'
sprogress = if b.no_cstep { 'TMP3/${b.nexpected_steps:3d}' } else {
'${b.cstep:3d}/${b.nexpected_steps:3d}'
}
}
timed_line = b.tdiff_in_ms('[${sprogress}] $msg', b.step_start_time, b.step_end_time)
}