mirror of
https://github.com/neovim/neovim.git
synced 2025-11-08 11:35:10 +00:00
unittests: Split itp implementation into multiple functions
This commit is contained in:
@@ -511,32 +511,17 @@ if os.getenv('NVIM_TEST_PRINT_SYSCALLS') == '1' then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function gen_itp(it)
|
local function just_fail(_)
|
||||||
child_calls_mod = {}
|
|
||||||
child_calls_mod_once = {}
|
|
||||||
child_cleanups_mod_once = {}
|
|
||||||
preprocess_cache_mod = map(function(v) return v end, preprocess_cache_init)
|
|
||||||
previous_defines_mod = previous_defines_init
|
|
||||||
cdefs_mod = cdefs_init:copy()
|
|
||||||
local function just_fail(_)
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
say:set('assertion.just_fail.positive', '%s')
|
say:set('assertion.just_fail.positive', '%s')
|
||||||
say:set('assertion.just_fail.negative', '%s')
|
say:set('assertion.just_fail.negative', '%s')
|
||||||
assert:register('assertion', 'just_fail', just_fail,
|
assert:register('assertion', 'just_fail', just_fail,
|
||||||
'assertion.just_fail.positive',
|
'assertion.just_fail.positive',
|
||||||
'assertion.just_fail.negative')
|
'assertion.just_fail.negative')
|
||||||
local function itp(name, func, allow_failure)
|
|
||||||
if allow_failure and os.getenv('NVIM_TEST_RUN_FAILING_TESTS') ~= '1' then
|
local function itp_child(wr, func)
|
||||||
-- FIXME Fix tests with this true
|
|
||||||
return
|
|
||||||
end
|
|
||||||
it(name, function()
|
|
||||||
local rd, wr = sc.pipe()
|
|
||||||
child_pid = sc.fork()
|
|
||||||
if child_pid == 0 then
|
|
||||||
init()
|
init()
|
||||||
sc.close(rd)
|
|
||||||
collectgarbage('stop')
|
collectgarbage('stop')
|
||||||
local err, emsg = pcall(func)
|
local err, emsg = pcall(func)
|
||||||
collectgarbage('restart')
|
collectgarbage('restart')
|
||||||
@@ -552,9 +537,9 @@ local function gen_itp(it)
|
|||||||
sc.close(wr)
|
sc.close(wr)
|
||||||
sc.exit(0)
|
sc.exit(0)
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
sc.close(wr)
|
|
||||||
local function check()
|
local function check_child_err(rd)
|
||||||
local res = sc.read(rd, 2)
|
local res = sc.read(rd, 2)
|
||||||
eq(2, #res)
|
eq(2, #res)
|
||||||
if res == '+\n' then
|
if res == '+\n' then
|
||||||
@@ -566,19 +551,47 @@ local function gen_itp(it)
|
|||||||
neq(0, len)
|
neq(0, len)
|
||||||
local err = sc.read(rd, len + 1)
|
local err = sc.read(rd, len + 1)
|
||||||
assert.just_fail(err)
|
assert.just_fail(err)
|
||||||
end
|
end
|
||||||
local err, emsg = pcall(check)
|
|
||||||
sc.wait(child_pid)
|
local function itp_parent(rd, pid, allow_failure)
|
||||||
child_pid = nil
|
local err, emsg = pcall(check_child_err, rd)
|
||||||
|
sc.wait(pid)
|
||||||
sc.close(rd)
|
sc.close(rd)
|
||||||
if not err then
|
if not err then
|
||||||
if allow_failure then
|
if allow_failure then
|
||||||
io.stderr:write('Errorred out:\n' .. tostring(emsg) .. '\n')
|
io.stderr:write('Errorred out:\n' .. tostring(emsg) .. '\n')
|
||||||
os.execute([[sh -c "source ci/common/test.sh ; check_core_dumps --delete \"]] .. Paths.test_luajit_prg .. [[\""]])
|
os.execute([[
|
||||||
|
sh -c "source ci/common/test.sh
|
||||||
|
check_core_dumps --delete \"]] .. Paths.test_luajit_prg .. [[\""]])
|
||||||
else
|
else
|
||||||
error(emsg)
|
error(emsg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function gen_itp(it)
|
||||||
|
child_calls_mod = {}
|
||||||
|
child_calls_mod_once = {}
|
||||||
|
child_cleanups_mod_once = {}
|
||||||
|
preprocess_cache_mod = map(function(v) return v end, preprocess_cache_init)
|
||||||
|
previous_defines_mod = previous_defines_init
|
||||||
|
cdefs_mod = cdefs_init:copy()
|
||||||
|
local function itp(name, func, allow_failure)
|
||||||
|
if allow_failure and os.getenv('NVIM_TEST_RUN_FAILING_TESTS') ~= '1' then
|
||||||
|
-- FIXME Fix tests with this true
|
||||||
|
return
|
||||||
|
end
|
||||||
|
it(name, function()
|
||||||
|
local rd, wr = sc.pipe()
|
||||||
|
child_pid = sc.fork()
|
||||||
|
if child_pid == 0 then
|
||||||
|
sc.close(rd)
|
||||||
|
itp_child(wr, func)
|
||||||
|
else
|
||||||
|
sc.close(wr)
|
||||||
|
saved_child_pid = child_pid
|
||||||
|
child_pid = nil
|
||||||
|
itp_parent(rd, saved_child_pid, allow_failure)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -610,6 +623,7 @@ local module = {
|
|||||||
only_separate = only_separate,
|
only_separate = only_separate,
|
||||||
child_call_once = child_call_once,
|
child_call_once = child_call_once,
|
||||||
child_cleanup_once = child_cleanup_once,
|
child_cleanup_once = child_cleanup_once,
|
||||||
|
sc = sc,
|
||||||
}
|
}
|
||||||
return function(after_each)
|
return function(after_each)
|
||||||
if after_each then
|
if after_each then
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local helpers = require('test.unit.helpers')(after_each)
|
local helpers = require('test.unit.helpers')(after_each)
|
||||||
local assert = require('luassert')
|
local assert = require('luassert')
|
||||||
|
|
||||||
local itp = helpers.gen_itp(it)
|
local itp = helpers.gen_itp(it)
|
||||||
|
|
||||||
-- All of the below tests must fail. Check how exactly they fail.
|
-- All of the below tests must fail. Check how exactly they fail.
|
||||||
|
|||||||
Reference in New Issue
Block a user