mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
add production mode tests
Due to the inability to detect warnings in REPL tests, I implemented running something very similar, but with the -prod flag enabled. (See https://github.com/vlang/v/pull/2536) There is also a minor change in os.walk_ext to not add duplicated path separators: /path//file.ext -> /path/file.ext
This commit is contained in:

committed by
Alexander Medvednikov

parent
da574640e7
commit
ab37081f02
@ -3,7 +3,7 @@ import compiler.tests.repl.runner
|
||||
import benchmark
|
||||
|
||||
fn test_the_v_compiler_can_be_invoked() {
|
||||
vexec := runner.full_path_to_v()
|
||||
vexec := runner.full_path_to_v(5)
|
||||
println('vexecutable: $vexec')
|
||||
assert vexec != ''
|
||||
|
||||
|
@ -9,9 +9,13 @@ pub:
|
||||
files []string
|
||||
}
|
||||
|
||||
pub 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.dir( os.executable() ))))) + os.path_separator + vname
|
||||
pub fn full_path_to_v(dirs_in int) string {
|
||||
vname := if os.user_os() == 'windows' { 'v.exe' } else { 'v' }
|
||||
mut path := os.executable()
|
||||
for i := 0; i < dirs_in; i++ {
|
||||
path = os.dir(path)
|
||||
}
|
||||
vexec := path + os.path_separator + vname
|
||||
/*
|
||||
args := os.args
|
||||
vreal := os.realpath('v')
|
||||
@ -75,9 +79,42 @@ $diff
|
||||
}
|
||||
}
|
||||
|
||||
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') }
|
||||
expected_content := f_expected_content.replace('\r', '')
|
||||
|
||||
cmd := '"$vexec" -prod run "$file"'
|
||||
r := os.exec(cmd) or {
|
||||
return error('Could not execute: $cmd')
|
||||
}
|
||||
|
||||
if r.exit_code != 0 {
|
||||
return error('$cmd return exit code: $r.exit_code')
|
||||
}
|
||||
|
||||
result := r.output.replace('\r','')
|
||||
|
||||
if result != expected_content {
|
||||
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
|
||||
====> Got :
|
||||
|$result|
|
||||
====> Expected :
|
||||
|$expected_content|
|
||||
====> Diff :
|
||||
$diff
|
||||
')
|
||||
} else {
|
||||
return 'Prod file $file is OK'
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_options() RunnerOptions {
|
||||
wd := os.getwd() + os.path_separator
|
||||
vexec := full_path_to_v()
|
||||
vexec := full_path_to_v(5)
|
||||
mut files := []string
|
||||
if os.args.len > 1 {
|
||||
files = os.args[1..]
|
||||
@ -91,3 +128,19 @@ pub fn new_options() RunnerOptions {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_prod_options() RunnerOptions {
|
||||
wd := os.getwd() + os.path_separator
|
||||
vexec := full_path_to_v(4)
|
||||
mut files := []string
|
||||
if os.args.len > 1 {
|
||||
files = os.args[1..]
|
||||
} else {
|
||||
files = os.walk_ext(wd, '.prod.v')
|
||||
}
|
||||
return RunnerOptions {
|
||||
wd: wd
|
||||
vexec: vexec
|
||||
files: files
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user