2019-08-18 18:21:48 +03:00
|
|
|
import os
|
|
|
|
|
2019-08-26 13:51:48 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_the_v_compiler_can_be_invoked() {
|
|
|
|
vexec := 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'
|
|
|
|
r := os.exec(vcmd) or { panic(err) }
|
|
|
|
//println('"$vcmd" exit_code: $r.exit_code | output: $r.output')
|
|
|
|
assert r.exit_code == 0
|
|
|
|
|
|
|
|
vcmd_error := '$vexec nonexisting.v'
|
|
|
|
r_error := os.exec(vcmd_error) or { panic(err) }
|
|
|
|
//println('"$vcmd_error" exit_code: $r_error.exit_code | output: $r_error.output')
|
|
|
|
assert r_error.exit_code == 1
|
|
|
|
assert r_error.output == '`nonexisting.v` does not exist'
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_the_v_repl() {
|
2019-08-18 18:21:48 +03:00
|
|
|
test_files := os.walk_ext('.', '.repl')
|
2019-08-26 13:51:48 +03:00
|
|
|
wd := os.getwd() + os.PathSeparator
|
|
|
|
vexec := full_path_to_v()
|
|
|
|
|
|
|
|
for file in test_files {
|
|
|
|
fcontent := os.read_file(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) }
|
2019-09-04 11:50:44 +03:00
|
|
|
r := os.exec('$vexec runrepl < $input_temporary_filename') or {
|
2019-08-26 13:51:48 +03:00
|
|
|
assert false
|
|
|
|
break
|
|
|
|
}
|
2019-09-03 18:42:40 +03:00
|
|
|
result := r.output.replace('\r','').replace('>>> ', '').replace('>>>', '').replace('... ', '').all_after('Use Ctrl-C or `exit` to exit\n').replace(wd, '' )
|
2019-08-26 13:51:48 +03:00
|
|
|
assert result == output
|
|
|
|
if result != output {
|
|
|
|
println(file)
|
|
|
|
println('Got : |$result|')
|
|
|
|
println('Expected : |$output|')
|
|
|
|
} else {
|
|
|
|
println('Repl file $file is OK')
|
|
|
|
}
|
|
|
|
}
|
2019-08-22 14:15:11 +03:00
|
|
|
}
|