Skip to content

Commit

Permalink
tests: improve the formatting of the output of coutput_test.v
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Dec 5, 2023
1 parent dbdd96f commit 21d4407
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 21 additions & 10 deletions vlib/v/gen/c/coutput_test.v
@@ -1,5 +1,6 @@
import os
import rand
import time
import term
import v.util.diff
import v.util.vtest
Expand All @@ -20,6 +21,10 @@ fn mm(s string) string {
return term.colorize(term.magenta, s)
}

fn mj(input ...string) string {
return mm(input.filter(it.len > 0).join(' '))
}

fn test_out_files() {
println(term.colorize(term.green, '> testing whether .out files match:'))
os.chdir(vroot) or {}
Expand All @@ -45,11 +50,17 @@ fn test_out_files() {
//
file_options := get_file_options(path)
alloptions := '-o ${os.quoted_path(pexe)} ${file_options.vflags}'
print(mm('v ${alloptions} run ${relpath}') + ' == ${mm(out_relpath)} ')
label := mj('v', file_options.vflags, 'run', relpath) + ' == ${mm(out_relpath)} '
//
sw_compile := time.new_stopwatch()
compilation := os.execute('${os.quoted_path(vexe)} ${alloptions} ${os.quoted_path(path)}')
compile_ms := sw_compile.elapsed().milliseconds()
ensure_compilation_succeeded(compilation)
//
sw_run := time.new_stopwatch()
res := os.execute(os.quoted_path(pexe))
run_ms := sw_run.elapsed().milliseconds()
//
if res.exit_code < 0 {
println('nope')
panic(res.output)
Expand All @@ -63,7 +74,7 @@ fn test_out_files() {
n_expected := normalize_panic_message(expected, vroot)
if found.contains('================ V panic ================') {
if n_found.starts_with(n_expected) {
println(term.green('OK (panic)'))
println('${term.green('OK (panic)')} C:${compile_ms:5}ms, R:${run_ms:2}ms ${label}')
continue
} else {
// Both have panics, but there was a difference...
Expand All @@ -75,7 +86,7 @@ fn test_out_files() {
}
}
if expected != found {
println(term.red('FAIL'))
println('${term.red('FAIL')} C:${compile_ms:5}ms, R:${run_ms:2}ms ${label}')
println(term.header('expected:', '-'))
println(expected)
println(term.header('found:', '-'))
Expand All @@ -88,14 +99,14 @@ fn test_out_files() {
}
total_errors++
} else {
println(term.green('OK'))
println('${term.green('OK ')} C:${compile_ms:5}ms, R:${run_ms:2}ms ${label}')
}
}
assert total_errors == 0
}

fn test_c_must_have_files() {
println(term.colorize(term.green, '> testing whether `.c.must_have` files match:'))
println(term.colorize(term.green, '> testing whether all line patterns in `.c.must_have` files match:'))
os.chdir(vroot) or {}
output_path := os.join_path(os.vtmp_dir(), 'coutput', 'c_must_have')
os.mkdir_all(output_path)!
Expand All @@ -118,11 +129,11 @@ fn test_c_must_have_files() {
}
file_options := get_file_options(path)
alloptions := '-o - ${file_options.vflags}'
description := mm('v ${alloptions} ${relpath}') +
' matches all line patterns in ${mm(must_have_relpath)} '
print(description)
description := mj('v', alloptions, relpath) + ' matches ${mm(must_have_relpath)} '
cmd := '${os.quoted_path(vexe)} ${alloptions} ${os.quoted_path(path)}'
sw_compile := time.new_stopwatch()
compilation := os.execute(cmd)
compile_ms := sw_compile.elapsed().milliseconds()
ensure_compilation_succeeded(compilation)
expected_lines := os.read_lines(must_have_path) or { [] }
generated_c_lines := compilation.output.split_into_lines()
Expand All @@ -134,7 +145,7 @@ fn test_c_must_have_files() {
// eprintln('> testing: $must_have_path has line: $eline')
} else {
failed_patterns << eline
println(term.red('FAIL'))
println('${term.red('FAIL')} C:${compile_ms:5}ms ${description}')
eprintln('${must_have_path}:${idx_expected_line + 1}: expected match error:')
eprintln('`${cmd}` did NOT produce expected line:')
eprintln(term.colorize(term.red, eline))
Expand All @@ -146,7 +157,7 @@ fn test_c_must_have_files() {
}
}
if nmatches == expected_lines.len {
println(term.green('OK'))
println('${term.green('OK ')} C:${compile_ms:5}ms ${description}')
} else {
if show_compilation_output {
eprintln('> ALL lines:')
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/gen/c/testdata/init_fn_with_if_attr_not_defined.vv
@@ -1,4 +1,4 @@
// vtest vflags: -d init_is_not_defined
// vtest vflags: -d not_defined

@[if init_on ?]
fn init() {
Expand Down

0 comments on commit 21d4407

Please sign in to comment.