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:
parent
fe50aeb130
commit
aa438c7c3f
@ -38,10 +38,15 @@ script:
|
|||||||
fi
|
fi
|
||||||
- |
|
- |
|
||||||
if [[ "${TRAVIS_OS_NAME}" == "windows" ]]; then
|
if [[ "${TRAVIS_OS_NAME}" == "windows" ]]; then
|
||||||
|
git clone --depth=1 https://github.com/ubawurinna/freetype-windows-binaries thirdparty/freetype/
|
||||||
|
##echo "Just running ./make.bat to produce v.exe"
|
||||||
|
##./make.bat
|
||||||
|
##echo "Running only the repl tests directly"
|
||||||
|
##./v.exe ./compiler/tests/repl/repl_test.v
|
||||||
echo "Testing msvc bootstrapping"
|
echo "Testing msvc bootstrapping"
|
||||||
#./make_msvc.bat
|
./make_msvc.bat
|
||||||
echo "Running make_tests.bat..."
|
echo "Running make_tests.bat..."
|
||||||
#./make_tests.bat
|
./make_tests.bat
|
||||||
fi
|
fi
|
||||||
- |
|
- |
|
||||||
if [[ "${TRAVIS_OS_NAME}" != "windows" ]]; then
|
if [[ "${TRAVIS_OS_NAME}" != "windows" ]]; then
|
||||||
|
@ -76,6 +76,7 @@ fn test_mut_array() {
|
|||||||
mut nums := [1, 2, 3]
|
mut nums := [1, 2, 3]
|
||||||
modify_array(mut nums)
|
modify_array(mut nums)
|
||||||
//assert nums.len == 4
|
//assert nums.len == 4
|
||||||
|
println(nums)
|
||||||
assert nums[0] == 20
|
assert nums[0] == 20
|
||||||
assert nums[1] == 4
|
assert nums[1] == 4
|
||||||
assert nums[2] == 6
|
assert nums[2] == 6
|
||||||
|
2
compiler/tests/repl/.gitattributes
vendored
Normal file
2
compiler/tests/repl/.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
*.repl text=auto eol=lf
|
@ -1,30 +1,67 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
fn test_repl() {
|
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')
|
test_files := os.walk_ext('.', '.repl')
|
||||||
wd := os.getwd() + '/'
|
wd := os.getwd() + os.PathSeparator
|
||||||
|
vexec := full_path_to_v()
|
||||||
|
|
||||||
for file in test_files {
|
for file in test_files {
|
||||||
content := os.read_file(file) or {
|
fcontent := os.read_file(file) or {
|
||||||
assert false
|
assert false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
input_temporary_filename := 'input_temporary_filename.txt'
|
content := fcontent.replace('\r', '')
|
||||||
input := content.all_before('===output===\n')
|
input := content.all_before('===output===\n')
|
||||||
output := content.all_after('===output===\n')
|
output := content.all_after('===output===\n')
|
||||||
|
|
||||||
|
input_temporary_filename := 'input_temporary_filename.txt'
|
||||||
os.write_file(input_temporary_filename, input)
|
os.write_file(input_temporary_filename, input)
|
||||||
defer {
|
defer { os.rm(input_temporary_filename) }
|
||||||
os.rm(input_temporary_filename)
|
r := os.exec('$vexec < $input_temporary_filename') or {
|
||||||
}
|
|
||||||
r := os.exec('./v < $input_temporary_filename') or {
|
|
||||||
assert false
|
assert false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
result := r.output.replace('>>> ', '').replace('>>>', '').replace('... ', '').all_after('Use Ctrl-C or `exit` to exit\n').replace( wd, '' )
|
result := r.output.replace('\r','').replace('>>> ', '').replace('>>>', '').replace('... ', '').all_after('Use Ctrl-C or `exit` to exit\n').replace( wd, '' )
|
||||||
assert result == output
|
assert result == output
|
||||||
if result != output {
|
if result != output {
|
||||||
println(file)
|
println(file)
|
||||||
println('Got : $result')
|
println('Got : |$result|')
|
||||||
println('Expected : $output')
|
println('Expected : |$output|')
|
||||||
|
} else {
|
||||||
|
println('Repl file $file is OK')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
module main
|
module main
|
||||||
|
|
||||||
import pg
|
import pg
|
||||||
@ -52,5 +54,6 @@ fn main() {
|
|||||||
db.insert(nc)
|
db.insert(nc)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
@ -38,8 +38,8 @@ del v_win.c
|
|||||||
del v2.exe
|
del v2.exe
|
||||||
|
|
||||||
echo Success
|
echo Success
|
||||||
|
goto :done
|
||||||
|
|
||||||
exit
|
|
||||||
|
|
||||||
:nomsvc
|
:nomsvc
|
||||||
echo Cannot find an msvc installation
|
echo Cannot find an msvc installation
|
||||||
@ -49,6 +49,11 @@ goto :error
|
|||||||
echo Failed to compile - Create an issue at 'https://github.com/vlang' and tag '@emily33901'!
|
echo Failed to compile - Create an issue at 'https://github.com/vlang' and tag '@emily33901'!
|
||||||
goto :error
|
goto :error
|
||||||
|
|
||||||
|
|
||||||
:error
|
:error
|
||||||
echo Exiting from error
|
echo fail
|
||||||
exit /b 1
|
exit /b 1
|
||||||
|
|
||||||
|
|
||||||
|
:done
|
||||||
|
echo pass
|
||||||
|
@ -18,18 +18,19 @@ echo build v using vc
|
|||||||
vc.exe -o v.exe compiler
|
vc.exe -o v.exe compiler
|
||||||
if %ERRORLEVEL% NEQ 0 goto :fail
|
if %ERRORLEVEL% NEQ 0 goto :fail
|
||||||
|
|
||||||
echo build vc.msvc using vc
|
|
||||||
vc.exe -os msvc -o v.msvc.exe compiler
|
|
||||||
if %ERRORLEVEL% NEQ 0 goto :fail
|
|
||||||
|
|
||||||
setlocal EnableDelayedExpansion
|
setlocal EnableDelayedExpansion
|
||||||
echo testing v
|
echo testing v
|
||||||
v test v
|
v test v
|
||||||
if %ERRORLEVEL% NEQ 0 goto :fail
|
if %ERRORLEVEL% NEQ 0 goto :fail
|
||||||
|
|
||||||
echo testing v.msvc -os msvc
|
echo skipping build vc.msvc using vc
|
||||||
v.msvc.exe -os msvc test v
|
REM vc.exe -os msvc -o v.msvc.exe compiler
|
||||||
if %ERRORLEVEL% NEQ 0 goto :fail
|
REM if %ERRORLEVEL% NEQ 0 goto :fail
|
||||||
|
|
||||||
|
echo skipping testing v.msvc -os msvc
|
||||||
|
REM v.msvc.exe -os msvc test v
|
||||||
|
REM if %ERRORLEVEL% NEQ 0 goto :fail
|
||||||
|
|
||||||
goto :done
|
goto :done
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ import (
|
|||||||
gl
|
gl
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#flag windows -I @VROOT/thirdparty/freetype/include
|
||||||
|
#flag windows -L @VROOT/thirdparty/freetype/win64
|
||||||
|
|
||||||
#flag darwin -I/usr/local/include/freetype2
|
#flag darwin -I/usr/local/include/freetype2
|
||||||
#flag darwin -I/opt/local/include/freetype2
|
#flag darwin -I/opt/local/include/freetype2
|
||||||
#flag -lfreetype
|
#flag -lfreetype
|
||||||
|
20
vlib/os/os.v
20
vlib/os/os.v
@ -325,7 +325,7 @@ fn pclose(f *FILE) int {
|
|||||||
return C._pclose(f)
|
return C._pclose(f)
|
||||||
}
|
}
|
||||||
$else {
|
$else {
|
||||||
return C.pclose(f)
|
return C.pclose(f) / 256 // WEXITSTATUS()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +349,7 @@ pub fn exec(cmd string) ?Result {
|
|||||||
res += tos(buf, strlen(buf))
|
res += tos(buf, strlen(buf))
|
||||||
}
|
}
|
||||||
res = res.trim_space()
|
res = res.trim_space()
|
||||||
exit_code := pclose(f)/256
|
exit_code := pclose(f)
|
||||||
//if exit_code != 0 {
|
//if exit_code != 0 {
|
||||||
//return error(res)
|
//return error(res)
|
||||||
//}
|
//}
|
||||||
@ -509,19 +509,13 @@ pub fn get_line() string {
|
|||||||
// get_raw_line returns a one-line string from stdin along with '\n' if there is any
|
// get_raw_line returns a one-line string from stdin along with '\n' if there is any
|
||||||
pub fn get_raw_line() string {
|
pub fn get_raw_line() string {
|
||||||
$if windows {
|
$if windows {
|
||||||
max := 512 // MAX_PATH * sizeof(wchar_t)
|
maxlinechars := 256
|
||||||
buf := &u16(malloc(max*2))
|
buf := &u16(malloc(maxlinechars*2))
|
||||||
h_input := C.GetStdHandle(STD_INPUT_HANDLE)
|
res := int( C.fgetws(buf, maxlinechars, C.stdin ) )
|
||||||
if h_input == INVALID_HANDLE_VALUE {
|
len := int( C.wcslen(buf) )
|
||||||
panic('get_raw_line() error getting input handle.')
|
if 0 != res { return string_from_wide2( buf, len ) }
|
||||||
}
|
|
||||||
mut nr_chars := 0
|
|
||||||
C.ReadConsole(h_input, buf, max, &nr_chars, 0)
|
|
||||||
if nr_chars == 0 {
|
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
return string_from_wide2(buf, nr_chars)
|
|
||||||
}
|
|
||||||
$else {
|
$else {
|
||||||
//u64 is used because C.getline needs a size_t as second argument
|
//u64 is used because C.getline needs a size_t as second argument
|
||||||
//Otherwise, it would cause a valgrind warning and may be dangerous
|
//Otherwise, it would cause a valgrind warning and may be dangerous
|
||||||
|
@ -15,7 +15,8 @@ const (
|
|||||||
|
|
||||||
$if !windows {
|
$if !windows {
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/wait.h>
|
//#include <sys/wait.h>
|
||||||
|
/// ^^^^ including this makes the windows build fail.
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Time {
|
struct Time {
|
||||||
|
Loading…
Reference in New Issue
Block a user