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

os: implement os.truncate() + improve error handling (#9752)

This commit is contained in:
Bastian Buck
2021-04-16 10:53:44 +02:00
committed by GitHub
parent 8cb44ed9db
commit aa49bc2708
2 changed files with 49 additions and 7 deletions

View File

@@ -573,3 +573,16 @@ fn test_exists_in_system_path() {
}
assert os.exists_in_system_path('ls')
}
fn test_truncate() {
filename := './test_trunc.txt'
hello := 'hello world!'
mut f := os.create(filename) or { panic(err) }
f.write_string(hello) or { panic(err) }
f.close()
assert hello.len == os.file_size(filename)
newlen := u64(40000)
os.truncate(filename, newlen) or { panic(err) }
assert newlen == os.file_size(filename)
os.rm(filename) or { panic(err) }
}