2021-04-22 06:07:56 +02:00
|
|
|
module os
|
2020-04-04 23:37:13 +02:00
|
|
|
|
|
|
|
const (
|
|
|
|
// tfolder will contain all the temporary files/subfolders made by
|
|
|
|
// the different tests. It would be removed in testsuite_end(), so
|
|
|
|
// individual os tests do not need to clean up after themselves.
|
2021-04-22 06:07:56 +02:00
|
|
|
tfolder = join_path(temp_dir(), 'v', 'tests', 'inode_test')
|
2020-04-04 23:37:13 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
fn testsuite_begin() {
|
2021-04-22 06:07:56 +02:00
|
|
|
eprintln('testsuite_begin, tfolder = $os.tfolder')
|
|
|
|
rmdir_all(os.tfolder) or {}
|
|
|
|
assert !is_dir(os.tfolder)
|
|
|
|
mkdir_all(os.tfolder) or { panic(err) }
|
|
|
|
chdir(os.tfolder)
|
|
|
|
assert is_dir(os.tfolder)
|
2020-04-04 23:37:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn testsuite_end() {
|
2021-04-22 06:07:56 +02:00
|
|
|
chdir(wd_at_startup)
|
|
|
|
rmdir_all(os.tfolder) or { panic(err) }
|
|
|
|
assert !is_dir(os.tfolder)
|
2020-04-04 23:37:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_inode_file_type() {
|
|
|
|
filename := './test1.txt'
|
2021-04-22 06:07:56 +02:00
|
|
|
mut file := open_file(filename, 'w', 0o600) or { return }
|
2020-06-01 17:30:17 +02:00
|
|
|
file.close()
|
2021-04-22 06:07:56 +02:00
|
|
|
mode := inode(filename)
|
|
|
|
rm(filename) or { panic(err) }
|
2020-04-04 23:37:13 +02:00
|
|
|
assert mode.typ == .regular
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_inode_file_owner_permission() {
|
|
|
|
filename := './test2.txt'
|
2021-04-22 06:07:56 +02:00
|
|
|
mut file := open_file(filename, 'w', 0o600) or { return }
|
2020-06-01 17:30:17 +02:00
|
|
|
file.close()
|
2021-04-22 06:07:56 +02:00
|
|
|
mode := inode(filename)
|
|
|
|
rm(filename) or {}
|
2020-04-04 23:37:13 +02:00
|
|
|
assert mode.owner.read
|
|
|
|
assert mode.owner.write
|
|
|
|
assert !mode.owner.execute
|
|
|
|
}
|