io.write returns number of written bytes on error
This commit is contained in:
@@ -696,6 +696,37 @@ do
|
||||
end
|
||||
|
||||
|
||||
if T and T.nonblock then
|
||||
print("testing failed write")
|
||||
|
||||
-- unable to write anything to /dev/full
|
||||
local f = io.open("/dev/full", "w")
|
||||
assert(f:setvbuf("no"))
|
||||
local _, _, err, count = f:write("abcd")
|
||||
assert(err > 0 and count == 0)
|
||||
assert(f:close())
|
||||
|
||||
-- receiver will read a "few" bytes (enough to empty a large buffer)
|
||||
local receiver = [[
|
||||
lua -e 'assert(io.stdin:setvbuf("no")); assert(#io.read(1e4) == 1e4)' ]]
|
||||
|
||||
local f = io.popen(receiver, "w")
|
||||
assert(f:setvbuf("no"))
|
||||
T.nonblock(f)
|
||||
|
||||
-- able to write a few bytes
|
||||
assert(f:write(string.rep("a", 1e2)))
|
||||
|
||||
-- Unable to write more bytes than the pipe buffer supports.
|
||||
-- (In Linux, the pipe buffer size is 64K (2^16). Posix requires at
|
||||
-- least 512 bytes.)
|
||||
local _, _, err, count = f:write("abcd", string.rep("a", 2^17))
|
||||
assert(err > 0 and count >= 512 and count < 2^17)
|
||||
|
||||
assert(f:close())
|
||||
end
|
||||
|
||||
|
||||
if not _soft then
|
||||
print("testing large files (> BUFSIZ)")
|
||||
io.output(file)
|
||||
|
||||
Reference in New Issue
Block a user