ci: fix failing tests on windows too

pull/6623/head
Delyan Angelov 2020-10-15 15:54:44 +03:00
parent 5d4cce3e95
commit 50a2b033b7
2 changed files with 113 additions and 118 deletions

View File

@ -5,7 +5,6 @@ import strings
#flag -lws2_32 #flag -lws2_32
#include <winsock2.h> #include <winsock2.h>
#include <process.h> #include <process.h>
pub const ( pub const (
path_separator = '\\' path_separator = '\\'
path_delimiter = ';' path_delimiter = ';'
@ -80,7 +79,7 @@ mut:
fn init_os_args_wide(argc int, argv &byteptr) []string { fn init_os_args_wide(argc int, argv &byteptr) []string {
mut args := []string{} mut args := []string{}
for i in 0..argc { for i in 0 .. argc {
args << string_from_wide(unsafe {&u16(argv[i])}) args << string_from_wide(unsafe {&u16(argv[i])})
} }
return args return args
@ -131,12 +130,12 @@ pub fn is_dir(path string) bool {
return false return false
} }
*/ */
// mkdir creates a new directory with the specified path. // mkdir creates a new directory with the specified path.
pub fn mkdir(path string) ?bool { pub fn mkdir(path string) ?bool {
if path == '.' { return true } if path == '.' {
apath := os.real_path( path ) return true
}
apath := real_path(path)
if !C.CreateDirectory(apath.to_wide(), 0) { if !C.CreateDirectory(apath.to_wide(), 0) {
return error('mkdir failed for "$apath", because CreateDirectory returned ' + get_error_msg(int(C.GetLastError()))) return error('mkdir failed for "$apath", because CreateDirectory returned ' + get_error_msg(int(C.GetLastError())))
} }
@ -146,7 +145,9 @@ pub fn mkdir(path string) ?bool {
// Ref - https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=vs-2019 // Ref - https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=vs-2019
// get_file_handle retrieves the operating-system file handle that is associated with the specified file descriptor. // get_file_handle retrieves the operating-system file handle that is associated with the specified file descriptor.
pub fn get_file_handle(path string) HANDLE { pub fn get_file_handle(path string) HANDLE {
cfile := vfopen(path, 'rb') or { return HANDLE(invalid_handle_value) } cfile := vfopen(path, 'rb') or {
return HANDLE(invalid_handle_value)
}
handle := HANDLE(C._get_osfhandle(fileno(cfile))) // CreateFile? - hah, no -_- handle := HANDLE(C._get_osfhandle(fileno(cfile))) // CreateFile? - hah, no -_-
return handle return handle
} }
@ -204,10 +205,7 @@ fn ptr_win_get_error_msg(code u32) voidptr {
if code > u32(max_error_code) { if code > u32(max_error_code) {
return buf return buf
} }
C.FormatMessage( C.FormatMessage(format_message_allocate_buffer | format_message_from_system | format_message_ignore_inserts,
format_message_allocate_buffer
| format_message_from_system
| format_message_ignore_inserts,
0, code, C.MAKELANGID(lang_neutral, sublang_default), voidptr(&buf), 0, 0) 0, code, C.MAKELANGID(lang_neutral, sublang_default), voidptr(&buf), 0, 0)
return buf return buf
} }
@ -232,24 +230,23 @@ pub fn exec(cmd string) ?Result {
mut child_stdin := &u32(0) mut child_stdin := &u32(0)
mut child_stdout_read := &u32(0) mut child_stdout_read := &u32(0)
mut child_stdout_write := &u32(0) mut child_stdout_write := &u32(0)
mut sa := SecurityAttributes {} mut sa := SecurityAttributes{}
sa.n_length = sizeof(C.SECURITY_ATTRIBUTES) sa.n_length = sizeof(C.SECURITY_ATTRIBUTES)
sa.b_inherit_handle = true sa.b_inherit_handle = true
create_pipe_ok := C.CreatePipe(voidptr(&child_stdout_read), voidptr(&child_stdout_write),
create_pipe_ok := C.CreatePipe(voidptr(&child_stdout_read), voidptr(&sa), 0)
voidptr(&child_stdout_write), voidptr(&sa), 0)
if !create_pipe_ok { if !create_pipe_ok {
error_num := int(C.GetLastError()) error_num := int(C.GetLastError())
error_msg := get_error_msg(error_num) error_msg := get_error_msg(error_num)
return error_with_code('exec failed (CreatePipe): $error_msg', error_num) return error_with_code('exec failed (CreatePipe): $error_msg', error_num)
} }
set_handle_info_ok := C.SetHandleInformation(child_stdout_read, C.HANDLE_FLAG_INHERIT, 0) set_handle_info_ok := C.SetHandleInformation(child_stdout_read, C.HANDLE_FLAG_INHERIT,
0)
if !set_handle_info_ok { if !set_handle_info_ok {
error_num := int(C.GetLastError()) error_num := int(C.GetLastError())
error_msg := get_error_msg(error_num) error_msg := get_error_msg(error_num)
return error_with_code('exec failed (SetHandleInformation): $error_msg', error_num) return error_with_code('exec failed (SetHandleInformation): $error_msg', error_num)
} }
proc_info := ProcessInformation{} proc_info := ProcessInformation{}
start_info := StartupInfo{ start_info := StartupInfo{
lp_reserved: 0 lp_reserved: 0
@ -263,11 +260,13 @@ pub fn exec(cmd string) ?Result {
} }
command_line := [32768]u16{} command_line := [32768]u16{}
C.ExpandEnvironmentStringsW(cmd.to_wide(), voidptr(&command_line), 32768) C.ExpandEnvironmentStringsW(cmd.to_wide(), voidptr(&command_line), 32768)
create_process_ok := C.CreateProcessW(0, command_line, 0, 0, C.TRUE, 0, 0, 0, voidptr(&start_info), voidptr(&proc_info)) create_process_ok := C.CreateProcessW(0, command_line, 0, 0, C.TRUE, 0, 0, 0, voidptr(&start_info),
voidptr(&proc_info))
if !create_process_ok { if !create_process_ok {
error_num := int(C.GetLastError()) error_num := int(C.GetLastError())
error_msg := get_error_msg(error_num) error_msg := get_error_msg(error_num)
return error_with_code('exec failed (CreateProcess) with code $error_num: $error_msg cmd: $cmd', error_num) return error_with_code('exec failed (CreateProcess) with code $error_num: $error_msg cmd: $cmd',
error_num)
} }
C.CloseHandle(child_stdin) C.CloseHandle(child_stdin)
C.CloseHandle(child_stdout_write) C.CloseHandle(child_stdout_write)
@ -275,7 +274,8 @@ pub fn exec(cmd string) ?Result {
mut bytes_read := u32(0) mut bytes_read := u32(0)
mut read_data := strings.new_builder(1024) mut read_data := strings.new_builder(1024)
for { for {
readfile_result := C.ReadFile(child_stdout_read, buf, 1000, voidptr(&bytes_read), 0) readfile_result := C.ReadFile(child_stdout_read, buf, 1000, voidptr(&bytes_read),
0)
read_data.write_bytes(buf, int(bytes_read)) read_data.write_bytes(buf, int(bytes_read))
if readfile_result == false || int(bytes_read) == 0 { if readfile_result == false || int(bytes_read) == 0 {
break break
@ -288,7 +288,7 @@ pub fn exec(cmd string) ?Result {
C.GetExitCodeProcess(proc_info.h_process, voidptr(&exit_code)) C.GetExitCodeProcess(proc_info.h_process, voidptr(&exit_code))
C.CloseHandle(proc_info.h_process) C.CloseHandle(proc_info.h_process)
C.CloseHandle(proc_info.h_thread) C.CloseHandle(proc_info.h_thread)
return Result { return Result{
output: soutput output: soutput
exit_code: int(exit_code) exit_code: int(exit_code)
} }
@ -296,8 +296,8 @@ pub fn exec(cmd string) ?Result {
fn C.CreateSymbolicLinkW(&u16, &u16, u32) int fn C.CreateSymbolicLinkW(&u16, &u16, u32) int
pub fn symlink(origin, target string) ?bool { pub fn symlink(origin string, target string) ?bool {
flags := if os.is_dir(origin) { 1 } else { 0 } flags := if is_dir(origin) { 1 } else { 0 }
if C.CreateSymbolicLinkW(origin.to_wide(), target.to_wide(), u32(flags)) != 0 { if C.CreateSymbolicLinkW(origin.to_wide(), target.to_wide(), u32(flags)) != 0 {
return true return true
} }
@ -318,7 +318,6 @@ pub:
// status_ constants // status_ constants
code u32 code u32
flags u32 flags u32
record &ExceptionRecord record &ExceptionRecord
address voidptr address voidptr
param_count u32 param_count u32
@ -335,22 +334,19 @@ pub:
context_record &ContextRecord context_record &ContextRecord
} }
pub type VectoredExceptionHandler = fn (&ExceptionPointers) u32 pub type VectoredExceptionHandler = fn ( &ExceptionPointers) u32
// This is defined in builtin because we use vectored exception handling // This is defined in builtin because we use vectored exception handling
// for our unhandled exception handler on windows // for our unhandled exception handler on windows
// As a result this definition is commented out to prevent // As a result this definition is commented out to prevent
// duplicate definitions from displeasing the compiler // duplicate definitions from displeasing the compiler
// fn C.AddVectoredExceptionHandler(u32, VectoredExceptionHandler) // fn C.AddVectoredExceptionHandler(u32, VectoredExceptionHandler)
pub fn add_vectored_exception_handler(first bool, handler VectoredExceptionHandler) { pub fn add_vectored_exception_handler(first bool, handler VectoredExceptionHandler) {
C.AddVectoredExceptionHandler(u32(first), C.PVECTORED_EXCEPTION_HANDLER(handler)) C.AddVectoredExceptionHandler(u32(first), C.PVECTORED_EXCEPTION_HANDLER(handler))
} }
// this is defined in builtin_windows.c.v in builtin // this is defined in builtin_windows.c.v in builtin
// fn C.IsDebuggerPresent() bool // fn C.IsDebuggerPresent() bool
pub fn debugger_present() bool { pub fn debugger_present() bool {
return C.IsDebuggerPresent() return C.IsDebuggerPresent()
} }
@ -367,25 +363,25 @@ pub fn uname() Uname {
} }
} }
// `is_writable_folder` - `folder` exists and is writable to the process // `is_writable_folder` - `folder` exists and is writable to the process
pub fn is_writable_folder(folder string) ?bool { pub fn is_writable_folder(folder string) ?bool {
if !os.exists(folder) { if !exists(folder) {
return error('`$folder` does not exist') return error('`$folder` does not exist')
} }
if !os.is_dir(folder) { if !is_dir(folder) {
return error('`folder` is not a folder') return error('`folder` is not a folder')
} }
tmp_perm_check := os.join_path(folder, 'tmp_perm_check_pid_' + getpid().str()) tmp_perm_check := join_path(folder, 'tmp_perm_check_pid_' + getpid().str())
mut f := os.open_file(tmp_perm_check, 'w+', 0o700) or { mut f := open_file(tmp_perm_check, 'w+', 0o700) or {
return error('cannot write to folder $folder: $err') return error('cannot write to folder $folder: $err')
} }
f.close() f.close()
os.rm(tmp_perm_check) rm(tmp_perm_check)
return true return true
} }
fn C._getpid() int fn C._getpid() int
[inline] [inline]
pub fn getpid() int { pub fn getpid() int {
return C._getpid() return C._getpid()

View File

@ -9,8 +9,8 @@ import benchmark
const ( const (
skip_files = [ skip_files = [
'vlib/v/checker/tests/return_missing_comp_if.vv' 'vlib/v/checker/tests/return_missing_comp_if.vv',
'vlib/v/checker/tests/return_missing_comp_if_nested.vv' 'vlib/v/checker/tests/return_missing_comp_if_nested.vv',
] ]
) )
@ -46,7 +46,8 @@ fn test_all() {
// -prod so that warns are errors // -prod so that warns are errors
mut tasks := []TaskDescription{} mut tasks := []TaskDescription{}
tasks << new_tasks(vexe, classic_dir, '-prod', '.out', classic_tests, false) tasks << new_tasks(vexe, classic_dir, '-prod', '.out', classic_tests, false)
tasks << new_tasks(vexe, global_dir, '--enable-globals', '.out', global_tests, false) tasks <<
new_tasks(vexe, global_dir, '--enable-globals', '.out', global_tests, false)
tasks << tasks <<
new_tasks(vexe, classic_dir, '--enable-globals run', '.run.out', ['globals_error.vv'], false) new_tasks(vexe, classic_dir, '--enable-globals run', '.run.out', ['globals_error.vv'], false)
tasks << new_tasks(vexe, module_dir, '-prod run', '.out', module_tests, true) tasks << new_tasks(vexe, module_dir, '-prod run', '.out', module_tests, true)
@ -55,7 +56,7 @@ fn test_all() {
tasks.run() tasks.run()
} }
fn new_tasks(vexe, dir, voptions, result_extension string, tests []string, is_module bool) []TaskDescription { fn new_tasks(vexe string, dir string, voptions string, result_extension string, tests []string, is_module bool) []TaskDescription {
paths := vtest.filter_vtest_only(tests, { paths := vtest.filter_vtest_only(tests, {
basepath: dir basepath: dir
}) })
@ -88,9 +89,7 @@ fn (mut tasks []TaskDescription) run() {
if tasks[i].path in m_skip_files { if tasks[i].path in m_skip_files {
tasks[i].is_skipped = true tasks[i].is_skipped = true
} }
unsafe { unsafe {work.push(&tasks[i])}
work.push(&tasks[i])
}
} }
work.close() work.close()
for _ in 0 .. vjobs { for _ in 0 .. vjobs {
@ -181,7 +180,7 @@ fn clean_line_endings(s string) string {
return res return res
} }
fn diff_content(s1, s2 string) { fn diff_content(s1 string, s2 string) {
diff_cmd := util.find_working_diff_command() or { diff_cmd := util.find_working_diff_command() or {
return return
} }