mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	unittests: Use more adequate names for some functions
This commit is contained in:
		| @@ -38,13 +38,14 @@ local function only_separate(func) | |||||||
|     return func(...) |     return func(...) | ||||||
|   end |   end | ||||||
| end | end | ||||||
| local deferred_calls_init = {} | local child_calls_init = {} | ||||||
| local deferred_calls_mod = nil | local child_calls_mod = nil | ||||||
| local function deferred_call(func, ret) | local child_calls_mod_once = nil | ||||||
|  | local function child_call(func, ret) | ||||||
|   return function(...) |   return function(...) | ||||||
|     local deferred_calls = deferred_calls_mod or deferred_calls_init |     local child_calls = child_calls_mod or child_calls_init | ||||||
|     if child_pid ~= 0 then |     if child_pid ~= 0 then | ||||||
|       deferred_calls[#deferred_calls + 1] = {func=func, args={...}} |       child_calls[#child_calls + 1] = {func=func, args={...}} | ||||||
|       return ret |       return ret | ||||||
|     else |     else | ||||||
|       return func(...) |       return func(...) | ||||||
| @@ -52,15 +53,27 @@ local function deferred_call(func, ret) | |||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
| local separate_cleanups_mod = nil | -- Run some code at the start of the child process, before running the test | ||||||
| local function separate_cleanup(func) | -- itself. Is supposed to be run in `before_each`. | ||||||
|   return function(...) | local function child_call_once(func, ...) | ||||||
|     local separate_cleanups = separate_cleanups_mod |   if child_pid ~= 0 then | ||||||
|     if child_pid ~= 0 then |     child_calls_mod_once[#child_calls_mod_once + 1] = { | ||||||
|       separate_cleanups[#separate_cleanups + 1] = {args={...}} |       func=func, args={...}} | ||||||
|     else |   else | ||||||
|       func(...) |     func(...) | ||||||
|     end |   end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | local child_cleanups_mod_once = nil | ||||||
|  |  | ||||||
|  | -- Run some code at the end of the child process, before exiting. Is supposed to | ||||||
|  | -- be run in `before_each` because `after_each` is run after child has exited. | ||||||
|  | local function child_cleanup_once(func, ...) | ||||||
|  |   local child_cleanups = child_cleanups_mod_once | ||||||
|  |   if child_pid ~= 0 then | ||||||
|  |     child_cleanups[#child_cleanups + 1] = {func=func, args={...}} | ||||||
|  |   else | ||||||
|  |     func(...) | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -70,7 +83,7 @@ local lib = setmetatable({}, { | |||||||
|   __index = only_separate(function(_, idx) |   __index = only_separate(function(_, idx) | ||||||
|     return libnvim[idx] |     return libnvim[idx] | ||||||
|   end), |   end), | ||||||
|   __newindex = deferred_call(function(_, idx, val) |   __newindex = child_call(function(_, idx, val) | ||||||
|     libnvim[idx] = val |     libnvim[idx] = val | ||||||
|   end), |   end), | ||||||
| }) | }) | ||||||
| @@ -78,24 +91,31 @@ local lib = setmetatable({}, { | |||||||
| local init = only_separate(function() | local init = only_separate(function() | ||||||
|   -- load neovim shared library |   -- load neovim shared library | ||||||
|   libnvim = ffi.load(Paths.test_libnvim_path) |   libnvim = ffi.load(Paths.test_libnvim_path) | ||||||
|   for _, c in ipairs(deferred_calls_init) do |   for _, c in ipairs(child_calls_init) do | ||||||
|     c.func(unpack(c.args)) |     c.func(unpack(c.args)) | ||||||
|   end |   end | ||||||
|   libnvim.time_init() |   libnvim.time_init() | ||||||
|   libnvim.early_init() |   libnvim.early_init() | ||||||
|   libnvim.event_init() |   libnvim.event_init() | ||||||
|   if deferred_calls_mod then |   if child_calls_mod then | ||||||
|     for _, c in ipairs(deferred_calls_mod) do |     for _, c in ipairs(child_calls_mod) do | ||||||
|       c.func(unpack(c.args)) |       c.func(unpack(c.args)) | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  |   if child_calls_mod_once then | ||||||
|  |     for _, c in ipairs(child_calls_mod_once) do | ||||||
|  |       c.func(unpack(c.args)) | ||||||
|  |     end | ||||||
|  |     child_calls_mod_once = nil | ||||||
|  |   end | ||||||
| end) | end) | ||||||
|  |  | ||||||
| local deinit = only_separate(function() | local deinit = only_separate(function() | ||||||
|   if separate_cleanups_mod then |   if child_cleanups_mod_once then | ||||||
|     for _, c in ipairs(separate_cleanups_mod) do |     for _, c in ipairs(child_cleanups_mod_once) do | ||||||
|       c.func(unpack(c.args)) |       c.func(unpack(c.args)) | ||||||
|     end |     end | ||||||
|  |     child_cleanups_mod_once = nil | ||||||
|   end |   end | ||||||
| end) | end) | ||||||
|  |  | ||||||
| @@ -188,7 +208,7 @@ local cimport_immediate = function(...) | |||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
| cimportstr = deferred_call(function(preprocess_cache, path) | cimportstr = child_call(function(preprocess_cache, path) | ||||||
|   if imported:contains(path) then |   if imported:contains(path) then | ||||||
|     return lib |     return lib | ||||||
|   end |   end | ||||||
| @@ -247,7 +267,7 @@ local function alloc_log_new() | |||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|   log.save_original_functions = deferred_call(log.save_original_functions) |   log.save_original_functions = child_call(log.save_original_functions) | ||||||
|   function log:set_mocks() |   function log:set_mocks() | ||||||
|     for _, k in ipairs(allocator_functions) do |     for _, k in ipairs(allocator_functions) do | ||||||
|       do |       do | ||||||
| @@ -274,7 +294,7 @@ local function alloc_log_new() | |||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|   log.set_mocks = deferred_call(log.set_mocks) |   log.set_mocks = child_call(log.set_mocks) | ||||||
|   function log:clear() |   function log:clear() | ||||||
|     self.log = {} |     self.log = {} | ||||||
|   end |   end | ||||||
| @@ -457,8 +477,9 @@ if os.getenv('NVIM_TEST_PRINT_SYSCALLS') == '1' then | |||||||
| end | end | ||||||
|  |  | ||||||
| local function gen_itp(it) | local function gen_itp(it) | ||||||
|   deferred_calls_mod = {} |   child_calls_mod = {} | ||||||
|   separate_cleanups_mod = {} |   child_calls_mod_once = {} | ||||||
|  |   child_cleanups_mod_once = {} | ||||||
|   preprocess_cache_mod = map(function(v) return v end, preprocess_cache_init) |   preprocess_cache_mod = map(function(v) return v end, preprocess_cache_init) | ||||||
|   previous_defines_mod = previous_defines_init |   previous_defines_mod = previous_defines_init | ||||||
|   local function just_fail(_) |   local function just_fail(_) | ||||||
| @@ -551,8 +572,8 @@ local module = { | |||||||
|   alloc_log_new = alloc_log_new, |   alloc_log_new = alloc_log_new, | ||||||
|   gen_itp = gen_itp, |   gen_itp = gen_itp, | ||||||
|   only_separate = only_separate, |   only_separate = only_separate, | ||||||
|   deferred_call = deferred_call, |   child_call_once = child_call_once, | ||||||
|   separate_cleanup = separate_cleanup, |   child_cleanup_once = child_cleanup_once, | ||||||
| } | } | ||||||
| return function(after_each) | return function(after_each) | ||||||
|   if after_each then |   if after_each then | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| local helpers = require("test.unit.helpers")(after_each) | local helpers = require("test.unit.helpers")(after_each) | ||||||
| local itp = helpers.gen_itp(it) | local itp = helpers.gen_itp(it) | ||||||
|  |  | ||||||
| local deferred_call = helpers.deferred_call | local child_call_once = helpers.child_call_once | ||||||
| local cimport = helpers.cimport | local cimport = helpers.cimport | ||||||
| local ffi = helpers.ffi | local ffi = helpers.ffi | ||||||
| local eq = helpers.eq | local eq = helpers.eq | ||||||
| @@ -23,21 +23,23 @@ describe("multiqueue (multi-level event-queue)", function() | |||||||
|     multiqueue.multiqueue_free(q) |     multiqueue.multiqueue_free(q) | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   before_each(deferred_call(function() |   before_each(function() | ||||||
|     parent = multiqueue.multiqueue_new_parent(ffi.NULL, ffi.NULL) |     child_call_once(function() | ||||||
|     child1 = multiqueue.multiqueue_new_child(parent) |       parent = multiqueue.multiqueue_new_parent(ffi.NULL, ffi.NULL) | ||||||
|     child2 = multiqueue.multiqueue_new_child(parent) |       child1 = multiqueue.multiqueue_new_child(parent) | ||||||
|     child3 = multiqueue.multiqueue_new_child(parent) |       child2 = multiqueue.multiqueue_new_child(parent) | ||||||
|     put(child1, 'c1i1') |       child3 = multiqueue.multiqueue_new_child(parent) | ||||||
|     put(child1, 'c1i2') |       put(child1, 'c1i1') | ||||||
|     put(child2, 'c2i1') |       put(child1, 'c1i2') | ||||||
|     put(child1, 'c1i3') |       put(child2, 'c2i1') | ||||||
|     put(child2, 'c2i2') |       put(child1, 'c1i3') | ||||||
|     put(child2, 'c2i3') |       put(child2, 'c2i2') | ||||||
|     put(child2, 'c2i4') |       put(child2, 'c2i3') | ||||||
|     put(child3, 'c3i1') |       put(child2, 'c2i4') | ||||||
|     put(child3, 'c3i2') |       put(child3, 'c3i1') | ||||||
|   end)) |       put(child3, 'c3i2') | ||||||
|  |     end) | ||||||
|  |   end) | ||||||
|  |  | ||||||
|   itp('keeps count of added events', function() |   itp('keeps count of added events', function() | ||||||
|     eq(3, multiqueue.multiqueue_size(child1)) |     eq(3, multiqueue.multiqueue_size(child1)) | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ local eq = helpers.eq | |||||||
| local ffi = helpers.ffi | local ffi = helpers.ffi | ||||||
| local cstr = helpers.cstr | local cstr = helpers.cstr | ||||||
| local to_cstr = helpers.to_cstr | local to_cstr = helpers.to_cstr | ||||||
| local deferred_call = helpers.deferred_call | local child_call_once = helpers.child_call_once | ||||||
|  |  | ||||||
| local rbuffer = helpers.cimport("./test/unit/fixtures/rbuffer.h") | local rbuffer = helpers.cimport("./test/unit/fixtures/rbuffer.h") | ||||||
|  |  | ||||||
| @@ -32,11 +32,13 @@ describe('rbuffer functions', function() | |||||||
|     return ffi.string(rbuffer.rbuffer_get(rbuf, idx), 1) |     return ffi.string(rbuffer.rbuffer_get(rbuf, idx), 1) | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   before_each(deferred_call(function() |   before_each(function() | ||||||
|     rbuf = ffi.gc(rbuffer.rbuffer_new(capacity), rbuffer.rbuffer_free) |     child_call_once(function() | ||||||
|     -- fill the internal buffer with the character '0' to simplify inspecting |       rbuf = ffi.gc(rbuffer.rbuffer_new(capacity), rbuffer.rbuffer_free) | ||||||
|     ffi.C.memset(rbuf.start_ptr, string.byte('0'), capacity) |       -- fill the internal buffer with the character '0' to simplify inspecting | ||||||
|   end)) |       ffi.C.memset(rbuf.start_ptr, string.byte('0'), capacity) | ||||||
|  |     end) | ||||||
|  |   end) | ||||||
|  |  | ||||||
|   describe('RBUFFER_UNTIL_FULL', function() |   describe('RBUFFER_UNTIL_FULL', function() | ||||||
|     local chunks |     local chunks | ||||||
|   | |||||||
| @@ -5,17 +5,18 @@ local itp = helpers.gen_itp(it) | |||||||
| local eq = helpers.eq | local eq = helpers.eq | ||||||
| local neq = helpers.neq | local neq = helpers.neq | ||||||
| local cimport = helpers.cimport | local cimport = helpers.cimport | ||||||
| local deferred_call = helpers.deferred_call | local child_call_once = helpers.child_call_once | ||||||
| local separate_cleanup = helpers.separate_cleanup | local child_cleanup_once = helpers.child_cleanup_once | ||||||
|  |  | ||||||
| local lib = cimport('./src/nvim/os/os.h', './src/nvim/fileio.h') | local lib = cimport('./src/nvim/os/os.h', './src/nvim/fileio.h') | ||||||
|  |  | ||||||
| describe('tempfile related functions', function() | describe('tempfile related functions', function() | ||||||
|   before_each(deferred_call(function() |   before_each(function() | ||||||
|     lib.vim_deltempdir() |     local function vim_deltempdir() | ||||||
|   end)) |       lib.vim_deltempdir() | ||||||
|   separate_cleanup(function() |     end | ||||||
|     lib.vim_deltempdir() |     child_call_once(vim_deltempdir) | ||||||
|  |     child_cleanup_once(vim_deltempdir) | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
|   local vim_gettempdir = function() |   local vim_gettempdir = function() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 ZyX
					ZyX