diff options
Diffstat (limited to 'test/functional')
-rw-r--r-- | test/functional/core/job_spec.lua | 46 | ||||
-rw-r--r-- | test/functional/helpers.lua | 2 | ||||
-rw-r--r-- | test/functional/provider/nodejs_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/provider/perl_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/ui/screen.lua | 16 | ||||
-rw-r--r-- | test/functional/vimscript/server_spec.lua | 20 |
6 files changed, 57 insertions, 35 deletions
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 94a50b9a41..cf24e570cb 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -16,6 +16,7 @@ local poke_eventloop = helpers.poke_eventloop local iswin = helpers.iswin local get_pathsep = helpers.get_pathsep local pathroot = helpers.pathroot +local exec_lua = helpers.exec_lua local nvim_set = helpers.nvim_set local expect_twostreams = helpers.expect_twostreams local expect_msg_seq = helpers.expect_msg_seq @@ -208,7 +209,7 @@ describe('jobs', function() ok(string.find(err, "E475: Invalid argument: expected valid directory$") ~= nil) end) - it('produces error when using non-executable `cwd`', function() + it('error on non-executable `cwd`', function() if iswin() then return end -- N/A for Windows local dir = 'Xtest_not_executable_dir' @@ -249,7 +250,7 @@ describe('jobs', function() eq({'notification', 'exit', {0, 0}}, next_msg()) end) - it('allows interactive commands', function() + it('interactive commands', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") neq(0, eval('j')) nvim('command', 'call jobsend(j, "abc\\n")') @@ -295,7 +296,7 @@ describe('jobs', function() nvim('command', "call jobstop(j)") end) - it("will not buffer data if it doesn't end in newlines", function() + it("emits partial lines (does NOT buffer data lacking newlines)", function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobsend(j, "abc\\nxyz")') eq({'notification', 'stdout', {0, {'abc', 'xyz'}}}, next_msg()) @@ -378,7 +379,7 @@ describe('jobs', function() eq(NIL, meths.get_proc(pid)) end) - it("do not survive the exit of nvim", function() + it("disposed on Nvim exit", function() -- use sleep, which doesn't die on stdin close nvim('command', "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)") local pid = eval('jobpid(g:j)') @@ -646,6 +647,43 @@ describe('jobs', function() ) end) + it('jobstart() environment: $NVIM, $NVIM_LISTEN_ADDRESS #11009', function() + local function get_env_in_child_job(envname, env) + return exec_lua([[ + local envname, env = ... + local join = function(s) return vim.fn.join(s, '') end + local stdout = {} + local stderr = {} + local opt = { + env = env, + stdout_buffered = true, + stderr_buffered = true, + on_stderr = function(chan, data, name) stderr = data end, + on_stdout = function(chan, data, name) stdout = data end, + } + local j1 = vim.fn.jobstart({ vim.v.progpath, '-es', '-V1',( '+echo "%s="..getenv("%s")'):format(envname, envname), '+qa!' }, opt) + vim.fn.jobwait({ j1 }, 10000) + return join({ join(stdout), join(stderr) }) + ]], + envname, + env) + end + + local addr = eval('v:servername') + ok((addr):len() > 0) + -- $NVIM is _not_ defined in the top-level Nvim process. + eq('', eval('$NVIM')) + -- jobstart() shares its v:servername with the child via $NVIM. + eq('NVIM='..addr, get_env_in_child_job('NVIM')) + -- $NVIM_LISTEN_ADDRESS is unset by server_init in the child. + eq('NVIM_LISTEN_ADDRESS=null', get_env_in_child_job('NVIM_LISTEN_ADDRESS')) + eq('NVIM_LISTEN_ADDRESS=null', get_env_in_child_job('NVIM_LISTEN_ADDRESS', + { NVIM_LISTEN_ADDRESS='Xtest_jobstart_env' })) + -- User can explicitly set $NVIM_LOG_FILE, $VIM, $VIMRUNTIME. + eq('NVIM_LOG_FILE=Xtest_jobstart_env', + get_env_in_child_job('NVIM_LOG_FILE', { NVIM_LOG_FILE='Xtest_jobstart_env' })) + end) + describe('jobwait', function() before_each(function() if iswin() then diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index b0b2dac9fd..e9c3d4bd92 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -782,7 +782,7 @@ function module.pathroot() return iswin() and (module.nvim_dir:sub(1,2)..pathsep) or '/' end --- Returns a valid, platform-independent $NVIM_LISTEN_ADDRESS. +-- Returns a valid, platform-independent Nvim listen address. -- Useful for communicating with child instances. function module.new_pipename() -- HACK: Start a server temporarily, get the name, then stop it. diff --git a/test/functional/provider/nodejs_spec.lua b/test/functional/provider/nodejs_spec.lua index 661a6f4f94..187f1c0412 100644 --- a/test/functional/provider/nodejs_spec.lua +++ b/test/functional/provider/nodejs_spec.lua @@ -29,7 +29,7 @@ describe('nodejs host', function() local fname = 'Xtest-nodejs-hello.js' write_file(fname, [[ const neovim = require('neovim'); - const nvim = neovim.attach({socket: process.env.NVIM_LISTEN_ADDRESS}); + const nvim = neovim.attach({socket: process.env.NVIM}); nvim.command('let g:job_out = "hello"'); ]]) command('let g:job_id = jobstart(["node", "'..fname..'"])') @@ -39,7 +39,7 @@ describe('nodejs host', function() local fname = 'Xtest-nodejs-hello-plugin.js' write_file(fname, [[ const neovim = require('neovim'); - const nvim = neovim.attach({socket: process.env.NVIM_LISTEN_ADDRESS}); + const nvim = neovim.attach({socket: process.env.NVIM}); class TestPlugin { hello() { diff --git a/test/functional/provider/perl_spec.lua b/test/functional/provider/perl_spec.lua index 125674660b..aff5e36e24 100644 --- a/test/functional/provider/perl_spec.lua +++ b/test/functional/provider/perl_spec.lua @@ -83,7 +83,7 @@ describe('perl provider', function() use Neovim::Ext; use Neovim::Ext::MsgPack::RPC; - my $session = Neovim::Ext::MsgPack::RPC::socket_session($ENV{NVIM_LISTEN_ADDRESS}); + my $session = Neovim::Ext::MsgPack::RPC::socket_session($ENV{NVIM}); my $nvim = Neovim::Ext::from_session($session); $nvim->command('let g:job_out = "hello"'); 1; @@ -116,7 +116,7 @@ describe('perl provider', function() use Neovim::Ext; use Neovim::Ext::MsgPack::RPC; - my $session = Neovim::Ext::MsgPack::RPC::socket_session($ENV{NVIM_LISTEN_ADDRESS}); + my $session = Neovim::Ext::MsgPack::RPC::socket_session($ENV{NVIM}); my $nvim = Neovim::Ext::from_session($session); my $plugin = TestPlugin->new($nvim); $plugin->test_command(); diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index e8a39ab6f8..80dba70b33 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -75,7 +75,7 @@ local busted = require('busted') local deepcopy = helpers.deepcopy local shallowcopy = helpers.shallowcopy local concat_tables = helpers.concat_tables -local request, run_session = helpers.request, helpers.run_session +local run_session = helpers.run_session local eq = helpers.eq local dedent = helpers.dedent local get_session = helpers.get_session @@ -90,8 +90,6 @@ end local Screen = {} Screen.__index = Screen -local debug_screen - local default_timeout_factor = 1 if os.getenv('VALGRIND') then default_timeout_factor = default_timeout_factor * 3 @@ -123,18 +121,6 @@ do Screen.colornames = colornames end -function Screen.debug(command) - if not command then - command = 'pynvim -n -c ' - end - command = command .. request('vim_eval', '$NVIM_LISTEN_ADDRESS') - if debug_screen then - debug_screen:close() - end - debug_screen = io.popen(command, 'r') - debug_screen:read() -end - function Screen.new(width, height) if not width then width = 53 diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua index 238d1aeb0f..de64a77b4d 100644 --- a/test/functional/vimscript/server_spec.lua +++ b/test/functional/vimscript/server_spec.lua @@ -1,6 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval -local command = helpers.command local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths local iswin = helpers.iswin local ok = helpers.ok @@ -16,27 +15,25 @@ end describe('server', function() before_each(clear) - it('serverstart() sets $NVIM_LISTEN_ADDRESS on first invocation', function() - -- Unset $NVIM_LISTEN_ADDRESS - command('let $NVIM_LISTEN_ADDRESS = ""') - + it('serverstart(), serverstop() does not set $NVIM', function() local s = eval('serverstart()') assert(s ~= nil and s:len() > 0, "serverstart() returned empty") - eq(s, eval('$NVIM_LISTEN_ADDRESS')) + eq('', eval('$NVIM')) + eq('', eval('$NVIM_LISTEN_ADDRESS')) eq(1, eval("serverstop('"..s.."')")) eq('', eval('$NVIM_LISTEN_ADDRESS')) end) it('sets new v:servername if $NVIM_LISTEN_ADDRESS is invalid', function() clear({env={NVIM_LISTEN_ADDRESS='.'}}) - eq('.', eval('$NVIM_LISTEN_ADDRESS')) + -- Cleared on startup. + eq('', eval('$NVIM_LISTEN_ADDRESS')) local servers = funcs.serverlist() eq(1, #servers) ok(string.len(servers[1]) > 4) -- Like /tmp/nvim…/… or \\.\pipe\… end) - it('sets v:servername at startup or if all servers were stopped', - function() + it('sets v:servername at startup or if all servers were stopped', function() local initial_server = meths.get_vvar('servername') assert(initial_server ~= nil and initial_server:len() > 0, 'v:servername was not initialized') @@ -55,11 +52,13 @@ describe('server', function() eq(1, funcs.serverstop(funcs.serverlist()[1])) eq('', meths.get_vvar('servername')) - -- v:servername will take the next available server. + -- v:servername and $NVIM take the next available server. local servername = (iswin() and [[\\.\pipe\Xtest-functional-server-pipe]] or 'Xtest-functional-server-socket') funcs.serverstart(servername) eq(servername, meths.get_vvar('servername')) + -- Not set in the current process, only in children. + eq('', eval('$NVIM')) end) it('serverstop() returns false for invalid input', function() @@ -136,7 +135,6 @@ end) describe('startup --listen', function() it('validates', function() clear() - local cmd = { unpack(helpers.nvim_argv) } table.insert(cmd, '--listen') matches('nvim.*: Argument missing after: "%-%-listen"', funcs.system(cmd)) |