aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/os/inode_test.v
blob: f716bc276511a8dcbace2a447d8e44a650901491 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module 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 = join_path(temp_dir(), 'v', 'tests', 'inode_test')
)

fn testsuite_begin() {
	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) or {}
	assert is_dir(os.tfolder)
}

fn testsuite_end() {
	chdir(wd_at_startup) or {}
	rmdir_all(os.tfolder) or { panic(err) }
	assert !is_dir(os.tfolder)
}

fn test_inode_file_type() {
	filename := './test1.txt'
	mut file := open_file(filename, 'w', 0o600) or { return }
	file.close()
	mode := inode(filename)
	rm(filename) or { panic(err) }
	assert mode.typ == .regular
}

fn test_inode_file_owner_permission() {
	filename := './test2.txt'
	mut file := open_file(filename, 'w', 0o600) or { return }
	file.close()
	mode := inode(filename)
	rm(filename) or {}
	assert mode.owner.read
	assert mode.owner.write
	assert !mode.owner.execute
}