mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
fix(unittests): do not consider process crash to be a success
unittests relied on the exact setup of coredumps on CI to detect process crashing, and otherwise completely discarded errors. Dectect child process failure reliably using process status, so that unittests actually work locally as well.
This commit is contained in:
@@ -471,8 +471,9 @@ else
|
|||||||
close = ffi.C.close,
|
close = ffi.C.close,
|
||||||
wait = function(pid)
|
wait = function(pid)
|
||||||
ffi.errno(0)
|
ffi.errno(0)
|
||||||
|
local stat_loc = ffi.new('int[1]', {0})
|
||||||
while true do
|
while true do
|
||||||
local r = ffi.C.waitpid(pid, nil, ffi.C.kPOSIXWaitWUNTRACED)
|
local r = ffi.C.waitpid(pid, stat_loc, ffi.C.kPOSIXWaitWUNTRACED)
|
||||||
if r == -1 then
|
if r == -1 then
|
||||||
local err = ffi.errno(0)
|
local err = ffi.errno(0)
|
||||||
if err == ffi.C.kPOSIXErrnoECHILD then
|
if err == ffi.C.kPOSIXErrnoECHILD then
|
||||||
@@ -485,6 +486,7 @@ else
|
|||||||
assert(r == pid)
|
assert(r == pid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return stat_loc[0]
|
||||||
end,
|
end,
|
||||||
exit = ffi.C._exit,
|
exit = ffi.C._exit,
|
||||||
}
|
}
|
||||||
@@ -730,18 +732,22 @@ local function check_child_err(rd)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function itp_parent(rd, pid, allow_failure)
|
local function itp_parent(rd, pid, allow_failure, location)
|
||||||
local err, emsg = pcall(check_child_err, rd)
|
local ok, emsg = pcall(check_child_err, rd)
|
||||||
sc.wait(pid)
|
local status = sc.wait(pid)
|
||||||
sc.close(rd)
|
sc.close(rd)
|
||||||
if not err then
|
if not ok then
|
||||||
if allow_failure then
|
if allow_failure then
|
||||||
io.stderr:write('Errorred out:\n' .. tostring(emsg) .. '\n')
|
io.stderr:write('Errorred out ('..status..'):\n' .. tostring(emsg) .. '\n')
|
||||||
os.execute([[
|
os.execute([[
|
||||||
sh -c "source ci/common/test.sh
|
sh -c "source ci/common/test.sh
|
||||||
check_core_dumps --delete \"]] .. Paths.test_luajit_prg .. [[\""]])
|
check_core_dumps --delete \"]] .. Paths.test_luajit_prg .. [[\""]])
|
||||||
else
|
else
|
||||||
error(emsg)
|
error(tostring(emsg)..'\nexit code: '..status)
|
||||||
|
end
|
||||||
|
elseif status ~= 0 then
|
||||||
|
if not allow_failure then
|
||||||
|
error("child process errored out with status "..status.."!\n\n"..location)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -758,6 +764,11 @@ local function gen_itp(it)
|
|||||||
-- FIXME Fix tests with this true
|
-- FIXME Fix tests with this true
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Pre-emptively calculating error location, wasteful, ugh!
|
||||||
|
-- But the way this code messes around with busted implies the real location is strictly
|
||||||
|
-- not available in the parent when an actual error occurs. so we have to do this here.
|
||||||
|
local location = debug.traceback()
|
||||||
it(name, function()
|
it(name, function()
|
||||||
local rd, wr = sc.pipe()
|
local rd, wr = sc.pipe()
|
||||||
child_pid = sc.fork()
|
child_pid = sc.fork()
|
||||||
@@ -768,7 +779,7 @@ local function gen_itp(it)
|
|||||||
sc.close(wr)
|
sc.close(wr)
|
||||||
local saved_child_pid = child_pid
|
local saved_child_pid = child_pid
|
||||||
child_pid = nil
|
child_pid = nil
|
||||||
itp_parent(rd, saved_child_pid, allow_failure)
|
itp_parent(rd, saved_child_pid, allow_failure, location)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user