mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	test: Extend {unit,functional}.helpers with global helpers
Automatically include all "global helper" util functions in the
unit.helpers and functional.helpers and modules.  So tests don't need to
expicitly do:
    local global_helpers = require('test.helpers')
			
			
This commit is contained in:
		| @@ -1,7 +1,6 @@ | ||||
| -- Test server -> client RPC scenarios. Note: unlike `rpcnotify`, to evaluate | ||||
| -- `rpcrequest` calls we need the client event loop to be running. | ||||
| local helpers = require('test.functional.helpers')(after_each) | ||||
| local Paths = require('test.config.paths') | ||||
|  | ||||
| local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval | ||||
| local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop | ||||
| @@ -243,8 +242,8 @@ describe('server -> client', function() | ||||
|         \ 'rpc': v:true | ||||
|         \ } | ||||
|       ]]) | ||||
|       local lua_prog = Paths.test_lua_prg | ||||
|       meths.set_var("args", {lua_prog, 'test/functional/api/rpc_fixture.lua'}) | ||||
|       meths.set_var("args", {helpers.test_lua_prg, | ||||
|                              'test/functional/api/rpc_fixture.lua'}) | ||||
|       jobid = eval("jobstart(g:args, g:job_opts)") | ||||
|       neq(0, 'jobid') | ||||
|     end) | ||||
|   | ||||
| @@ -8,20 +8,12 @@ local Session = require('nvim.session') | ||||
| local TcpStream = require('nvim.tcp_stream') | ||||
| local SocketStream = require('nvim.socket_stream') | ||||
| local ChildProcessStream = require('nvim.child_process_stream') | ||||
| local Paths = require('test.config.paths') | ||||
|  | ||||
| local check_cores = global_helpers.check_cores | ||||
| local check_logs = global_helpers.check_logs | ||||
| local dedent = global_helpers.dedent | ||||
| local eq = global_helpers.eq | ||||
| local expect_err = global_helpers.expect_err | ||||
| local filter = global_helpers.filter | ||||
| local map = global_helpers.map | ||||
| local matches = global_helpers.matches | ||||
| local near = global_helpers.near | ||||
| local neq = global_helpers.neq | ||||
| local ok = global_helpers.ok | ||||
| local read_file = global_helpers.read_file | ||||
| local sleep = global_helpers.sleep | ||||
| local table_contains = global_helpers.table_contains | ||||
| local table_flatten = global_helpers.table_flatten | ||||
| @@ -32,7 +24,7 @@ local start_dir = lfs.currentdir() | ||||
| local nvim_prog = ( | ||||
|   os.getenv('NVIM_PROG') | ||||
|   or os.getenv('NVIM_PRG') | ||||
|   or Paths.test_build_dir .. '/bin/nvim' | ||||
|   or global_helpers.test_build_dir .. '/bin/nvim' | ||||
| ) | ||||
| -- Default settings for the test session. | ||||
| local nvim_set  = 'set shortmess+=I background=light noswapfile noautoindent' | ||||
| @@ -802,33 +794,25 @@ local module = { | ||||
|   curtabmeths = curtabmeths, | ||||
|   curwin = curwin, | ||||
|   curwinmeths = curwinmeths, | ||||
|   dedent = dedent, | ||||
|   eq = eq, | ||||
|   eval = nvim_eval, | ||||
|   exc_exec = exc_exec, | ||||
|   expect = expect, | ||||
|   expect_any = expect_any, | ||||
|   expect_err = expect_err, | ||||
|   expect_msg_seq = expect_msg_seq, | ||||
|   expect_twostreams = expect_twostreams, | ||||
|   feed = feed, | ||||
|   feed_command = feed_command, | ||||
|   filter = filter, | ||||
|   funcs = funcs, | ||||
|   get_pathsep = get_pathsep, | ||||
|   get_session = get_session, | ||||
|   insert = insert, | ||||
|   iswin = iswin, | ||||
|   map = map, | ||||
|   matches = matches, | ||||
|   merge_args = merge_args, | ||||
|   meth_pcall = meth_pcall, | ||||
|   meths = meths, | ||||
|   missing_provider = missing_provider, | ||||
|   mkdir = lfs.mkdir, | ||||
|   load_adjust = load_adjust, | ||||
|   near = near, | ||||
|   neq = neq, | ||||
|   new_pipename = new_pipename, | ||||
|   next_msg = next_msg, | ||||
|   nvim = nvim, | ||||
| @@ -838,13 +822,11 @@ local module = { | ||||
|   nvim_prog = nvim_prog, | ||||
|   nvim_prog_abs = nvim_prog_abs, | ||||
|   nvim_set = nvim_set, | ||||
|   ok = ok, | ||||
|   os_name = os_name, | ||||
|   pathroot = pathroot, | ||||
|   pending_win32 = pending_win32, | ||||
|   prepend_argv = prepend_argv, | ||||
|   rawfeed = rawfeed, | ||||
|   read_file = read_file, | ||||
|   redir_exec = redir_exec, | ||||
|   request = request, | ||||
|   retry = retry, | ||||
| @@ -854,20 +836,17 @@ local module = { | ||||
|   set_session = set_session, | ||||
|   set_shell_powershell = set_shell_powershell, | ||||
|   skip_fragile = skip_fragile, | ||||
|   sleep = sleep, | ||||
|   source = source, | ||||
|   spawn = spawn, | ||||
|   stop = stop, | ||||
|   table_flatten = table_flatten, | ||||
|   tabmeths = tabmeths, | ||||
|   tabpage = tabpage, | ||||
|   tmpname = tmpname, | ||||
|   uimeths = uimeths, | ||||
|   wait = wait, | ||||
|   window = window, | ||||
|   winmeths = winmeths, | ||||
|   write_file = write_file, | ||||
| } | ||||
| module = global_helpers.map_extend('error', module, global_helpers) | ||||
|  | ||||
| return function(after_each) | ||||
|   if after_each then | ||||
|   | ||||
| @@ -3,6 +3,7 @@ local assert = require('luassert') | ||||
| local luv = require('luv') | ||||
| local lfs = require('lfs') | ||||
| local relpath = require('pl.path').relpath | ||||
| local Paths = require('test.config.paths') | ||||
|  | ||||
| local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote) | ||||
| local function shell_quote(str) | ||||
| @@ -420,6 +421,7 @@ local function updated(d, d2) | ||||
|   return d | ||||
| end | ||||
|  | ||||
| -- Concat list-like tables. | ||||
| local function concat_tables(...) | ||||
|   local ret = {} | ||||
|   for i = 1, select('#', ...) do | ||||
| @@ -433,6 +435,34 @@ local function concat_tables(...) | ||||
|   return ret | ||||
| end | ||||
|  | ||||
| -- Concat map-like tables. | ||||
| -- | ||||
| -- behavior: Decides what to do if a key is found in more than one map: | ||||
| --           "error": raise an error | ||||
| --           "keep":  skip | ||||
| --           "force": set the item again | ||||
| local function map_extend(behavior, ...) | ||||
|   if (behavior ~= 'error' and behavior ~= 'keep' and behavior ~= 'force') then | ||||
|     error('invalid "behavior": '..tostring(behavior)) | ||||
|   end | ||||
|   local ret = {} | ||||
|   for i = 1, select('#', ...) do | ||||
|     local tbl = select(i, ...) | ||||
|     if tbl then | ||||
|       for k, v in pairs(tbl) do | ||||
|         if behavior ~= 'force' and ret[k] ~= nil then | ||||
|           if behavior == 'error' then | ||||
|             error('key found in more than one map: '..k) | ||||
|           end  -- Else behavior is "keep". | ||||
|         else | ||||
|           ret[k] = v | ||||
|         end | ||||
|       end | ||||
|     end | ||||
|   end | ||||
|   return ret | ||||
| end | ||||
|  | ||||
| local function dedent(str, leave_indent) | ||||
|   -- find minimum common indent across lines | ||||
|   local indent = nil | ||||
| @@ -771,6 +801,7 @@ local module = { | ||||
|   intchar2lua = intchar2lua, | ||||
|   isCI = isCI, | ||||
|   map = map, | ||||
|   map_extend = map_extend, | ||||
|   matches = matches, | ||||
|   mergedicts_copy = mergedicts_copy, | ||||
|   near = near, | ||||
| @@ -792,5 +823,6 @@ local module = { | ||||
|   which = which, | ||||
|   write_file = write_file, | ||||
| } | ||||
| module = map_extend('error', module, Paths) | ||||
|  | ||||
| return module | ||||
|   | ||||
| @@ -15,7 +15,6 @@ local dedent = global_helpers.dedent | ||||
| local neq = global_helpers.neq | ||||
| local map = global_helpers.map | ||||
| local eq = global_helpers.eq | ||||
| local ok = global_helpers.ok | ||||
|  | ||||
| -- C constants. | ||||
| local NULL = ffi.cast('void*', 0) | ||||
| @@ -842,9 +841,6 @@ local module = { | ||||
|   cimport = cimport, | ||||
|   cppimport = cppimport, | ||||
|   internalize = internalize, | ||||
|   ok = ok, | ||||
|   eq = eq, | ||||
|   neq = neq, | ||||
|   ffi = ffi, | ||||
|   lib = lib, | ||||
|   cstr = cstr, | ||||
| @@ -869,6 +865,7 @@ local module = { | ||||
|   ptr2key = ptr2key, | ||||
|   debug_log = debug_log, | ||||
| } | ||||
| module = global_helpers.map_extend('error', module, global_helpers) | ||||
| return function() | ||||
|   return module | ||||
| end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Justin M. Keyes
					Justin M. Keyes