mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +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
 | 
			
		||||
 | 
			
		||||
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 just_fail(_)
 | 
			
		||||
local function just_fail(_)
 | 
			
		||||
  return false
 | 
			
		||||
  end
 | 
			
		||||
  say:set('assertion.just_fail.positive', '%s')
 | 
			
		||||
  say:set('assertion.just_fail.negative', '%s')
 | 
			
		||||
  assert:register('assertion', 'just_fail', just_fail,
 | 
			
		||||
end
 | 
			
		||||
say:set('assertion.just_fail.positive', '%s')
 | 
			
		||||
say:set('assertion.just_fail.negative', '%s')
 | 
			
		||||
assert:register('assertion', 'just_fail', just_fail,
 | 
			
		||||
                'assertion.just_fail.positive',
 | 
			
		||||
                'assertion.just_fail.negative')
 | 
			
		||||
  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
 | 
			
		||||
 | 
			
		||||
local function itp_child(wr, func)
 | 
			
		||||
  init()
 | 
			
		||||
        sc.close(rd)
 | 
			
		||||
  collectgarbage('stop')
 | 
			
		||||
  local err, emsg = pcall(func)
 | 
			
		||||
  collectgarbage('restart')
 | 
			
		||||
@@ -552,9 +537,9 @@ local function gen_itp(it)
 | 
			
		||||
    sc.close(wr)
 | 
			
		||||
    sc.exit(0)
 | 
			
		||||
  end
 | 
			
		||||
      else
 | 
			
		||||
        sc.close(wr)
 | 
			
		||||
        local function check()
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function check_child_err(rd)
 | 
			
		||||
  local res = sc.read(rd, 2)
 | 
			
		||||
  eq(2, #res)
 | 
			
		||||
  if res == '+\n' then
 | 
			
		||||
@@ -566,19 +551,47 @@ local function gen_itp(it)
 | 
			
		||||
  neq(0, len)
 | 
			
		||||
  local err = sc.read(rd, len + 1)
 | 
			
		||||
  assert.just_fail(err)
 | 
			
		||||
        end
 | 
			
		||||
        local err, emsg = pcall(check)
 | 
			
		||||
        sc.wait(child_pid)
 | 
			
		||||
        child_pid = nil
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function itp_parent(rd, pid, allow_failure)
 | 
			
		||||
  local err, emsg = pcall(check_child_err, rd)
 | 
			
		||||
  sc.wait(pid)
 | 
			
		||||
  sc.close(rd)
 | 
			
		||||
  if not err then
 | 
			
		||||
    if allow_failure then
 | 
			
		||||
      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
 | 
			
		||||
      error(emsg)
 | 
			
		||||
    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
 | 
			
		||||
@@ -610,6 +623,7 @@ local module = {
 | 
			
		||||
  only_separate = only_separate,
 | 
			
		||||
  child_call_once = child_call_once,
 | 
			
		||||
  child_cleanup_once = child_cleanup_once,
 | 
			
		||||
  sc = sc,
 | 
			
		||||
}
 | 
			
		||||
return function(after_each)
 | 
			
		||||
  if after_each then
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
local helpers = require('test.unit.helpers')(after_each)
 | 
			
		||||
local assert = require('luassert')
 | 
			
		||||
 | 
			
		||||
local itp = helpers.gen_itp(it)
 | 
			
		||||
 | 
			
		||||
-- All of the below tests must fail. Check how exactly they fail.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user