mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
repl: execute REPL tests ~1.5x to 2x faster
This commit is contained in:

committed by
Alexander Medvednikov

parent
64a9f43405
commit
d92291dd76
@ -46,17 +46,18 @@ fn find_working_diff_command() ?string {
|
||||
|
||||
fn diff_files( file_result, file_expected string ) string {
|
||||
diffcmd := find_working_diff_command() or { return err }
|
||||
diff := os.exec('$diffcmd --minimal --text --unified=2 $file_result $file_expected') or { return 'found diff command "$diffcmd" does not work' }
|
||||
diff := os.exec('$diffcmd --minimal --text --unified=2 ${file_result} ${file_expected}') or { return 'found diff command "$diffcmd" does not work' }
|
||||
return diff.output
|
||||
}
|
||||
|
||||
pub fn run_repl_file(wd string, vexec string, file string) ?string {
|
||||
fcontent := os.read_file(file) or { return error('Could not read file $file') }
|
||||
fcontent := os.read_file(file) or { return error('Could not read file ${file}') }
|
||||
content := fcontent.replace('\r', '')
|
||||
input := content.all_before('===output===\n')
|
||||
output := content.all_after('===output===\n')
|
||||
|
||||
fname := filepath.filename( file )
|
||||
|
||||
input_temporary_filename := os.realpath(filepath.join( wd, 'input_temporary_filename.txt'))
|
||||
os.write_file(input_temporary_filename, input)
|
||||
os.write_file( os.realpath(filepath.join( wd, 'original.txt' ) ), fcontent )
|
||||
@ -80,7 +81,7 @@ pub fn run_repl_file(wd string, vexec string, file string) ?string {
|
||||
os.write_file( file_result, result )
|
||||
os.write_file( file_expected, output )
|
||||
diff := diff_files( file_result, file_expected )
|
||||
return error('Difference found in REPL file: $file
|
||||
return error('Difference found in REPL file: ${file}
|
||||
====> Got :
|
||||
|$result|
|
||||
====> Expected :
|
||||
@ -89,16 +90,16 @@ pub fn run_repl_file(wd string, vexec string, file string) ?string {
|
||||
$diff
|
||||
')
|
||||
} else {
|
||||
return 'Repl file $file is OK'
|
||||
return 'Repl file ${file} is OK'
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_prod_file(wd string, vexec string, file string) ?string {
|
||||
file_expected := '${file}.expected.txt'
|
||||
f_expected_content := os.read_file(file_expected) or { return error('Could not read file $file') }
|
||||
f_expected_content := os.read_file(file_expected) or { return error('Could not read file ${file}') }
|
||||
expected_content := f_expected_content.replace('\r', '')
|
||||
|
||||
cmd := '"$vexec" -prod run "$file"'
|
||||
cmd := '"$vexec" -prod run "${file}"'
|
||||
r := os.exec(cmd) or {
|
||||
return error('Could not execute: $cmd')
|
||||
}
|
||||
@ -113,7 +114,7 @@ pub fn run_prod_file(wd string, vexec string, file string) ?string {
|
||||
file_result := '${file}.result.txt'
|
||||
os.write_file( file_result, result )
|
||||
diff := diff_files( file_result, file_expected )
|
||||
return error('Difference found in test: $file
|
||||
return error('Difference found in test: ${file}
|
||||
====> Got :
|
||||
|$result|
|
||||
====> Expected :
|
||||
@ -122,17 +123,19 @@ pub fn run_prod_file(wd string, vexec string, file string) ?string {
|
||||
$diff
|
||||
')
|
||||
} else {
|
||||
return 'Prod file $file is OK'
|
||||
return 'Prod file ${file} is OK'
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_options() RunnerOptions {
|
||||
wd := os.getwd()
|
||||
vexec := full_path_to_v(5)
|
||||
mut wd := os.getwd()
|
||||
mut files := []string
|
||||
if os.args.len > 1 {
|
||||
files = os.args[1..]
|
||||
} else {
|
||||
os.chdir( filepath.dir(vexec) )
|
||||
wd = os.getwd()
|
||||
files = os.walk_ext('.', '.repl')
|
||||
}
|
||||
return RunnerOptions {
|
||||
|
Reference in New Issue
Block a user