1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: fix exec() and get_raw_line(); fix Windows tests and examples

This commit is contained in:
Delyan Angelov
2019-08-26 13:51:48 +03:00
committed by Alexander Medvednikov
parent fe50aeb130
commit aa438c7c3f
10 changed files with 106 additions and 54 deletions

View File

@ -76,6 +76,7 @@ fn test_mut_array() {
mut nums := [1, 2, 3]
modify_array(mut nums)
//assert nums.len == 4
println(nums)
assert nums[0] == 20
assert nums[1] == 4
assert nums[2] == 6

2
compiler/tests/repl/.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
*.repl text=auto eol=lf

View File

@ -1,30 +1,67 @@
import os
fn test_repl() {
test_files := os.walk_ext('.', '.repl')
wd := os.getwd() + '/'
for file in test_files {
content := os.read_file(file) or {
assert false
break
}
input_temporary_filename := 'input_temporary_filename.txt'
input := content.all_before('===output===\n')
output := content.all_after('===output===\n')
os.write_file(input_temporary_filename, input)
defer {
os.rm(input_temporary_filename)
}
r := os.exec('./v < $input_temporary_filename') or {
assert false
break
}
result := r.output.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')
}
}
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() {
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 {
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 < $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')
}
}
}