fix(unittest): delete unused duplicated code

YAGNI. These were disabled 5 years ago in lint commit 29ed5b3a39
This commit is contained in:
bfredl
2023-01-18 12:12:13 +01:00
parent 9fdb586592
commit 847a1507aa

View File

@@ -7,9 +7,6 @@ local global_helpers = require('test.helpers')
local assert = require('luassert') local assert = require('luassert')
local say = require('say') local say = require('say')
local posix = nil
local syscall = nil
local check_cores = global_helpers.check_cores local check_cores = global_helpers.check_cores
local dedent = global_helpers.dedent local dedent = global_helpers.dedent
local neq = global_helpers.neq local neq = global_helpers.neq
@@ -373,124 +370,91 @@ local function to_cstr(string)
return cstr(#string + 1, string) return cstr(#string + 1, string)
end end
local sc cimport_immediate('./test/unit/fixtures/posix.h')
local sc = {
if posix ~= nil then fork = function()
sc = { return tonumber(ffi.C.fork())
fork = posix.fork, end,
pipe = posix.pipe, pipe = function()
read = posix.read, local ret = ffi.new('int[2]', {-1, -1})
write = posix.write, ffi.errno(0)
close = posix.close, local res = ffi.C.pipe(ret)
wait = posix.wait, if (res ~= 0) then
exit = posix._exit, local err = ffi.errno(0)
} assert(res == 0, ("pipe() error: %u: %s"):format(
elseif syscall ~= nil then err, ffi.string(ffi.C.strerror(err))))
sc = { end
fork = syscall.fork, assert(ret[0] ~= -1 and ret[1] ~= -1)
pipe = function() return ret[0], ret[1]
local ret = {syscall.pipe()} end,
return ret[3], ret[4] read = function(rd, len)
end, local ret = ffi.new('char[?]', len, {0})
read = function(rd, len) local total_bytes_read = 0
return rd:read(nil, len) ffi.errno(0)
end, while total_bytes_read < len do
write = function(wr, s) local bytes_read = tonumber(ffi.C.read(
return wr:write(s) rd,
end, ffi.cast('void*', ret + total_bytes_read),
close = function(p) len - total_bytes_read))
return p:close() if bytes_read == -1 then
end,
wait = syscall.wait,
exit = syscall.exit,
}
else
cimport_immediate('./test/unit/fixtures/posix.h')
sc = {
fork = function()
return tonumber(ffi.C.fork())
end,
pipe = function()
local ret = ffi.new('int[2]', {-1, -1})
ffi.errno(0)
local res = ffi.C.pipe(ret)
if (res ~= 0) then
local err = ffi.errno(0) local err = ffi.errno(0)
assert(res == 0, ("pipe() error: %u: %s"):format( if err ~= ffi.C.kPOSIXErrnoEINTR then
err, ffi.string(ffi.C.strerror(err)))) assert(false, ("read() error: %u: %s"):format(
err, ffi.string(ffi.C.strerror(err))))
end
elseif bytes_read == 0 then
break
else
total_bytes_read = total_bytes_read + bytes_read
end end
assert(ret[0] ~= -1 and ret[1] ~= -1) end
return ret[0], ret[1] return ffi.string(ret, total_bytes_read)
end, end,
read = function(rd, len) write = function(wr, s)
local ret = ffi.new('char[?]', len, {0}) local wbuf = to_cstr(s)
local total_bytes_read = 0 local total_bytes_written = 0
ffi.errno(0) ffi.errno(0)
while total_bytes_read < len do while total_bytes_written < #s do
local bytes_read = tonumber(ffi.C.read( local bytes_written = tonumber(ffi.C.write(
rd, wr,
ffi.cast('void*', ret + total_bytes_read), ffi.cast('void*', wbuf + total_bytes_written),
len - total_bytes_read)) #s - total_bytes_written))
if bytes_read == -1 then if bytes_written == -1 then
local err = ffi.errno(0) local err = ffi.errno(0)
if err ~= ffi.C.kPOSIXErrnoEINTR then if err ~= ffi.C.kPOSIXErrnoEINTR then
assert(false, ("read() error: %u: %s"):format( assert(false, ("write() error: %u: %s ('%s')"):format(
err, ffi.string(ffi.C.strerror(err)))) err, ffi.string(ffi.C.strerror(err)), s))
end end
elseif bytes_read == 0 then elseif bytes_written == 0 then
break
else
total_bytes_written = total_bytes_written + bytes_written
end
end
return total_bytes_written
end,
close = ffi.C.close,
wait = function(pid)
ffi.errno(0)
local stat_loc = ffi.new('int[1]', {0})
while true do
local r = ffi.C.waitpid(pid, stat_loc, ffi.C.kPOSIXWaitWUNTRACED)
if r == -1 then
local err = ffi.errno(0)
if err == ffi.C.kPOSIXErrnoECHILD then
break break
else elseif err ~= ffi.C.kPOSIXErrnoEINTR then
total_bytes_read = total_bytes_read + bytes_read assert(false, ("waitpid() error: %u: %s"):format(
err, ffi.string(ffi.C.strerror(err))))
end end
else
assert(r == pid)
end end
return ffi.string(ret, total_bytes_read) end
end, return stat_loc[0]
write = function(wr, s) end,
local wbuf = to_cstr(s) exit = ffi.C._exit,
local total_bytes_written = 0 }
ffi.errno(0)
while total_bytes_written < #s do
local bytes_written = tonumber(ffi.C.write(
wr,
ffi.cast('void*', wbuf + total_bytes_written),
#s - total_bytes_written))
if bytes_written == -1 then
local err = ffi.errno(0)
if err ~= ffi.C.kPOSIXErrnoEINTR then
assert(false, ("write() error: %u: %s ('%s')"):format(
err, ffi.string(ffi.C.strerror(err)), s))
end
elseif bytes_written == 0 then
break
else
total_bytes_written = total_bytes_written + bytes_written
end
end
return total_bytes_written
end,
close = ffi.C.close,
wait = function(pid)
ffi.errno(0)
local stat_loc = ffi.new('int[1]', {0})
while true do
local r = ffi.C.waitpid(pid, stat_loc, ffi.C.kPOSIXWaitWUNTRACED)
if r == -1 then
local err = ffi.errno(0)
if err == ffi.C.kPOSIXErrnoECHILD then
break
elseif err ~= ffi.C.kPOSIXErrnoEINTR then
assert(false, ("waitpid() error: %u: %s"):format(
err, ffi.string(ffi.C.strerror(err))))
end
else
assert(r == pid)
end
end
return stat_loc[0]
end,
exit = ffi.C._exit,
}
end
local function format_list(lst) local function format_list(lst)
local ret = '' local ret = ''