repl: add some timing statistics when running REPL test files

This commit is contained in:
Delyan Angelov 2019-09-15 18:08:16 +03:00 committed by Alexander Medvednikov
parent d4a30d022b
commit 35f927e64e
5 changed files with 118 additions and 45 deletions

View file

@ -1,24 +1,9 @@
import os
fn full_path_to_v() string {
vname := if os.user_os() == 'windows' { 'v.exe' } else { 'v' }
vexec := os.dir(os.dir(os.dir(os.dir( os.executable() )))) + os.PathSeparator + vname
return vexec
}
import compiler.tests.repl.runner
fn test_the_v_compiler_can_be_invoked() {
vexec := full_path_to_v()
vexec := runner.full_path_to_v()
println('vexecutable: $vexec')
/*
args := os.args
vreal := os.realpath('v')
myself := os.realpath( os.executable() )
wd := os.getwd() + os.PathSeparator
println('args are: $args')
println('vreal : $vreal')
println('myself : $myself')
println('wd : $wd')
*/
assert vexec != ''
vcmd := '$vexec --version'
@ -33,35 +18,19 @@ fn test_the_v_compiler_can_be_invoked() {
assert r_error.output == '`nonexisting.v` does not exist'
}
fn test_the_v_repl() {
test_files := os.walk_ext('.', '.repl')
wd := os.getwd() + os.PathSeparator
vexec := full_path_to_v()
for file in test_files {
fcontent := os.read_file(file) or {
fn test_all_v_repl_files() {
options := runner.new_options()
global_start_time := runner.now()
for file in options.files {
sticks := runner.now()
fres := runner.run_repl_file(options.wd, options.vexec, file) or {
assert false
break
}
content := fcontent.replace('\r', '')
input := content.all_before('===output===\n')
output := content.all_after('===output===\n')
input_temporary_filename := 'input_temporary_filename.txt'
os.write_file(input_temporary_filename, input)
defer { os.rm(input_temporary_filename) }
r := os.exec('$vexec runrepl < $input_temporary_filename') or {
assert false
break
}
result := r.output.replace('\r','').replace('>>> ', '').replace('>>>', '').replace('... ', '').all_after('Use Ctrl-C or `exit` to exit\n').replace(wd, '' )
assert result == output
if result != output {
println(file)
println('Got : |$result|')
println('Expected : |$output|')
} else {
println('Repl file $file is OK')
eprintln( runner.tdiff_in_ms(err, sticks) )
continue
}
assert true
println( runner.tdiff_in_ms(fres, sticks) )
}
println( runner.tdiff_in_ms('<=== total time spent running REPL files', global_start_time) )
}