Skip to content

Commit

Permalink
tests: make v vlib/os/os_test.c.v pass on windows, for users != adm…
Browse files Browse the repository at this point in the history
…in, skipping the os.symlink checks
  • Loading branch information
spytheman committed Jan 23, 2024
1 parent 14c2e4c commit 672fe9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion vlib/os/file_test.v
Expand Up @@ -400,7 +400,9 @@ fn test_eof() {
mut f := os.open(tfile)!
f.read_bytes(10)
assert !f.eof()
f.read_bytes(100)
x := f.read_bytes(100)
dump(x)
dump(x.len)
assert f.eof()
f.close()
}
Expand Down
18 changes: 13 additions & 5 deletions vlib/os/os_test.c.v
Expand Up @@ -465,11 +465,19 @@ fn test_realpath_does_not_absolutize_non_existing_relative_paths() {
}
}

fn test_realpath_absolutepath_symlink() {
fn handle_privilege_error(err IError) ! {
if err.msg().contains('required privilege is not held by the client') {
eprintln('skipping ${@METHOD} on windows, since the user is not administrator, err:\n ${err}')
return err
}
panic(err)
}

fn test_realpath_absolutepath_symlink() ! {
file_name := 'tolink_file.txt'
symlink_name := 'symlink.txt'
create_file(file_name)!
os.symlink(file_name, symlink_name)!
os.symlink(file_name, symlink_name) or { handle_privilege_error(err) or { return } }
rpath := os.real_path(symlink_name)
println(rpath)
assert os.is_abs_path(rpath)
Expand All @@ -491,7 +499,7 @@ fn test_make_symlink_check_is_link_and_remove_symlink() {
os.mkdir(folder) or { panic(err) }
folder_contents := os.ls(folder) or { panic(err) }
assert folder_contents.len == 0
os.symlink(folder, symlink) or { panic(err) }
os.symlink(folder, symlink) or { handle_privilege_error(err) or { return } }
assert os.is_link(symlink)
$if windows {
os.rmdir(symlink) or { panic(err) }
Expand All @@ -511,7 +519,7 @@ fn test_make_symlink_check_is_link_and_remove_symlink_with_file() {
os.rm(symlink) or {}
os.rm(file) or {}
create_file(file)!
os.symlink(file, symlink) or { panic(err) }
os.symlink(file, symlink) or { handle_privilege_error(err) or { return } }
assert os.is_link(symlink)
os.rm(symlink) or { panic(err) }
os.rm(file) or { panic(err) }
Expand Down Expand Up @@ -557,7 +565,7 @@ fn test_make_hardlink_check_is_link_and_remove_hardlink_with_file() {

fn test_symlink() {
os.mkdir('symlink') or { panic(err) }
os.symlink('symlink', 'symlink2') or { panic(err) }
os.symlink('symlink', 'symlink2') or { handle_privilege_error(err) or { return } }
assert os.exists('symlink2')
// cleanup
os.rmdir('symlink') or { panic(err) }
Expand Down

0 comments on commit 672fe9b

Please sign in to comment.