mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: fix v -cflags "-Werror" test vlib/os/
This commit is contained in:
parent
7222ee476b
commit
b7a5fa7fbe
@ -315,7 +315,10 @@ pub fn (mut f File) write_str(s string) ? {
|
||||
if !f.is_opened {
|
||||
return error('file is closed')
|
||||
}
|
||||
f.write(s.bytes()) ?
|
||||
written := int(C.fwrite(voidptr(s.str), s.len, 1, f.cfile))
|
||||
if written == 0 && s.len != 0 {
|
||||
return error('0 bytes written')
|
||||
}
|
||||
}
|
||||
|
||||
// read_struct reads a single struct of type `T`
|
||||
|
@ -333,7 +333,7 @@ pub fn home_dir() string {
|
||||
// write_file writes `text` data to a file in `path`.
|
||||
pub fn write_file(path string, text string) ? {
|
||||
mut f := create(path) ?
|
||||
f.write(text.bytes()) ?
|
||||
f.write_str(text) ?
|
||||
f.close()
|
||||
}
|
||||
|
||||
|
@ -228,26 +228,32 @@ fn test_mv() {
|
||||
// Move file with no extension to dir
|
||||
os.mv(tfile1, tdir1) or { panic(err) }
|
||||
mut expected := os.join_path(tdir1, 'file')
|
||||
assert os.exists(expected) && !is_dir(expected) == true
|
||||
assert os.exists(expected)
|
||||
assert !is_dir(expected)
|
||||
// Move dir with contents to other dir
|
||||
os.mv(tdir1, tdir2) or { panic(err) }
|
||||
expected = os.join_path(tdir2, 'dir')
|
||||
assert os.exists(expected) && is_dir(expected) == true
|
||||
assert os.exists(expected)
|
||||
assert is_dir(expected)
|
||||
expected = os.join_path(tdir2, 'dir', 'file')
|
||||
assert os.exists(expected) && !is_dir(expected) == true
|
||||
assert os.exists(expected)
|
||||
assert !is_dir(expected)
|
||||
// Move dir with contents to other dir (by renaming)
|
||||
os.mv(os.join_path(tdir2, 'dir'), tdir3) or { panic(err) }
|
||||
expected = tdir3
|
||||
assert os.exists(expected) && is_dir(expected) == true
|
||||
assert os.is_dir_empty(tdir2) == true
|
||||
assert os.exists(expected)
|
||||
assert is_dir(expected)
|
||||
assert os.is_dir_empty(tdir2)
|
||||
// Move file with extension to dir
|
||||
os.mv(tfile2, tdir2) or { panic(err) }
|
||||
expected = os.join_path(tdir2, 'file.test')
|
||||
assert os.exists(expected) && !is_dir(expected) == true
|
||||
assert os.exists(expected)
|
||||
assert !is_dir(expected)
|
||||
// Move file to dir (by renaming)
|
||||
os.mv(os.join_path(tdir2, 'file.test'), tfile3) or { panic(err) }
|
||||
expected = tfile3
|
||||
assert os.exists(expected) && !is_dir(expected) == true
|
||||
assert os.exists(expected)
|
||||
assert !is_dir(expected)
|
||||
}
|
||||
|
||||
fn test_cp_all() {
|
||||
@ -313,7 +319,7 @@ fn test_make_symlink_check_is_link_and_remove_symlink() {
|
||||
folder_contents := os.ls(folder) or { panic(err) }
|
||||
assert folder_contents.len == 0
|
||||
os.system('ln -s $folder $symlink')
|
||||
assert os.is_link(symlink) == true
|
||||
assert os.is_link(symlink)
|
||||
os.rm(symlink) or { panic(err) }
|
||||
os.rm(folder) or { panic(err) }
|
||||
folder_exists := os.is_dir(folder)
|
||||
@ -384,10 +390,10 @@ fn test_ext() {
|
||||
}
|
||||
|
||||
fn test_is_abs() {
|
||||
assert os.is_abs_path('/home/user') == true
|
||||
assert os.is_abs_path('/home/user')
|
||||
assert os.is_abs_path('v/vlib') == false
|
||||
$if windows {
|
||||
assert os.is_abs_path('C:\\Windows\\') == true
|
||||
assert os.is_abs_path('C:\\Windows\\')
|
||||
}
|
||||
}
|
||||
|
||||
@ -562,8 +568,8 @@ fn test_posix_set_bit() {
|
||||
fn test_exists_in_system_path() {
|
||||
assert os.exists_in_system_path('') == false
|
||||
$if windows {
|
||||
assert os.exists_in_system_path('cmd.exe') == true
|
||||
assert os.exists_in_system_path('cmd.exe')
|
||||
return
|
||||
}
|
||||
assert os.exists_in_system_path('ls') == true
|
||||
assert os.exists_in_system_path('ls')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user