summaryrefslogtreecommitdiff
path: root/tests/test-access.lua
blob: 0e6ab69addc68670e52ce33b49710059a662dbb7 (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
local l = require "luxio"
local sio = require "luxio.simple"

local path = "ENOENTpath"

local r, errno = l.access(path, l.F_OK)
if r == -1 then
	io.stderr:write(("%s does not exist (PASS)\n"):format(path))
end

path = "luxio-test-access-test-file"

local r, errno = l.open(path, l.O_CREAT, sio.tomode("-rw-r--r--"))
if r == -1 then
	io.stderr:write(("open: %s (FAIL)\n"):format(l.strerror(errno)))
	os.exit(l.EXIT_FAILURE)
end

local r, errno = l.access(path, l.bit.bor(l.R_OK, l.W_OK))

if r == -1 then
	io.stderr:write(("access: %s (FAIL)\n"):format(l.strerror(errno)))
	os.exit(l.EXIT_FAILURE)
end

print(("Running user has read and write access to %s (PASS)"):format(path))

local r, errno = l.access(path, l.bit.bor(l.X_OK))
if r == 0 then
	io.stderr:write("Running user should not have execute perms")
	os.exit(l.EXIT_FAILURE)
end

print(("Running does not have execute access to %s (PASS)"):format(path))

-- Ignore errors here, but try and clean up
l.unlink(path)