2020-04-04 23:37:13 +02:00
|
|
|
import os
|
|
|
|
|
|
|
|
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.
|
|
|
|
tfolder = os.join_path(os.temp_dir(), 'v', 'tests', 'inode_test')
|
|
|
|
)
|
|
|
|
|
|
|
|
fn testsuite_begin() {
|
2021-01-25 10:26:20 +01:00
|
|
|
eprintln('testsuite_begin, tfolder = $main.tfolder')
|
|
|
|
os.rmdir_all(main.tfolder)
|
|
|
|
assert !os.is_dir(main.tfolder)
|
|
|
|
os.mkdir_all(main.tfolder)
|
|
|
|
os.chdir(main.tfolder)
|
|
|
|
assert os.is_dir(main.tfolder)
|
2020-04-04 23:37:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn testsuite_end() {
|
|
|
|
os.chdir(os.wd_at_startup)
|
2021-01-25 10:26:20 +01:00
|
|
|
os.rmdir_all(main.tfolder)
|
|
|
|
assert !os.is_dir(main.tfolder)
|
2020-04-04 23:37:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_inode_file_type() {
|
|
|
|
filename := './test1.txt'
|
2020-12-16 10:02:36 +01:00
|
|
|
mut file := os.open_file(filename, 'w', 0o600) or { return }
|
2020-06-01 17:30:17 +02:00
|
|
|
file.close()
|
2020-04-04 23:37:13 +02:00
|
|
|
mode := os.inode(filename)
|
|
|
|
os.rm(filename)
|
|
|
|
assert mode.typ == .regular
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_inode_file_owner_permission() {
|
|
|
|
filename := './test2.txt'
|
2020-12-16 10:02:36 +01:00
|
|
|
mut file := os.open_file(filename, 'w', 0o600) or { return }
|
2020-06-01 17:30:17 +02:00
|
|
|
file.close()
|
2020-04-04 23:37:13 +02:00
|
|
|
mode := os.inode(filename)
|
|
|
|
os.rm(filename)
|
|
|
|
assert mode.owner.read
|
|
|
|
assert mode.owner.write
|
|
|
|
assert !mode.owner.execute
|
|
|
|
}
|