diff options
| author | Björn Linse <bjorn.linse@gmail.com> | 2016-05-12 22:25:15 +0200 | 
|---|---|---|
| committer | Björn Linse <bjorn.linse@gmail.com> | 2016-08-20 12:55:35 +0200 | 
| commit | 2d60a15e25f487eda1ac00a9e6cdf9a6564fb416 (patch) | |
| tree | 7844b2d185b27a0303183e90792a5ef807933e88 /test | |
| parent | 215922120c43163f4e1cc00851bd1b86890d3a28 (diff) | |
| download | rneovim-2d60a15e25f487eda1ac00a9e6cdf9a6564fb416.tar.gz rneovim-2d60a15e25f487eda1ac00a9e6cdf9a6564fb416.tar.bz2 rneovim-2d60a15e25f487eda1ac00a9e6cdf9a6564fb416.zip | |
job control: reuse common job code for rpc jobs
This makes stderr and exit callbacks work for rpc jobs
Diffstat (limited to 'test')
| -rw-r--r-- | test/functional/api/rpc_fixture.lua | 38 | ||||
| -rw-r--r-- | test/functional/api/server_requests_spec.lua | 46 | ||||
| -rw-r--r-- | test/functional/core/job_spec.lua | 8 | 
3 files changed, 89 insertions, 3 deletions
| diff --git a/test/functional/api/rpc_fixture.lua b/test/functional/api/rpc_fixture.lua new file mode 100644 index 0000000000..423864740f --- /dev/null +++ b/test/functional/api/rpc_fixture.lua @@ -0,0 +1,38 @@ +local deps_prefix = './.deps/usr' +if os.getenv('DEPS_PREFIX') then +  deps_prefix = os.getenv('DEPS_PREFIX') +end + +package.path = deps_prefix .. '/share/lua/5.1/?.lua;' .. +               deps_prefix .. '/share/lua/5.1/?/init.lua;' .. +               package.path + +package.cpath = deps_prefix .. '/lib/lua/5.1/?.so;' .. +                package.cpath + +local mpack = require('mpack') +local StdioStream = require('nvim.stdio_stream') +local Session = require('nvim.session') + +local stdio_stream = StdioStream.open() +local session = Session.new(stdio_stream) + +local function on_request(method, args) +  if method == 'poll' then +    return 'ok' +  elseif method == 'write_stderr' then +    io.stderr:write(args[1]) +    return "done!" +  elseif method == "exit" then +    session:stop() +    return mpack.NIL +  end +end + +local function on_notification(event, args) +  if event == 'ping' and #args == 0 then +    session:notify("vim_eval", "rpcnotify(g:channel, 'pong')") +  end +end + +session:run(on_request, on_notification) diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index eb63834cb0..b76c3b9cd6 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -4,7 +4,9 @@  local helpers = require('test.functional.helpers')(after_each)  local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval  local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop -local nvim_prog = helpers.nvim_prog +local nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.funcs +local source, next_message = helpers.source, helpers.next_message +local meths = helpers.meths  describe('server -> client', function() @@ -144,11 +146,11 @@ describe('server -> client', function()      end      before_each(function() -      nvim('command', "let vim = rpcstart('"..nvim_prog.."', ['-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--embed'])") +      command("let vim = rpcstart('"..nvim_prog.."', ['-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--embed'])")        neq(0, eval('vim'))      end) -    after_each(function() nvim('command', 'call rpcstop(vim)') end) +    after_each(function() command('call rpcstop(vim)') end)      it('can send/recieve notifications and make requests', function()        nvim('command', "call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") @@ -181,4 +183,42 @@ describe('server -> client', function()        eq(true, string.match(err, ': (.*)') == 'Failed to evaluate expression')      end)    end) + +  describe('when using jobstart', function() +    local jobid +    before_each(function() +      local channel = nvim('get_api_info')[1] +      nvim('set_var', 'channel', channel) +      source([[ +        function! s:OnEvent(id, data, event) +          call rpcnotify(g:channel, a:event, 0, a:data) +        endfunction +        let g:job_opts = { +        \ 'on_stderr': function('s:OnEvent'), +        \ 'on_exit': function('s:OnEvent'), +        \ 'user': 0, +        \ 'rpc': v:true +        \ } +      ]]) +      local lua_prog = arg[-1] +      meths.set_var("args", {lua_prog, 'test/functional/api/rpc_fixture.lua'}) +      jobid = eval("jobstart(g:args, g:job_opts)") +      neq(0, 'jobid') +    end) + +    after_each(function() +      funcs.jobstop(jobid) +    end) + +    it('rpc and text stderr can be combined', function() +      eq("ok",funcs.rpcrequest(jobid, "poll")) +      funcs.rpcnotify(jobid, "ping") +      eq({'notification', 'pong', {}}, next_message()) +      eq("done!",funcs.rpcrequest(jobid, "write_stderr", "fluff\n")) +      eq({'notification', 'stderr', {0, {'fluff', ''}}}, next_message()) +      funcs.rpcrequest(jobid, "exit") +      eq({'notification', 'exit', {0, 0}}, next_message()) +    end) +  end) +  end) diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 1d11374e4d..921bf1655e 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -5,6 +5,7 @@ local clear, eq, eval, execute, feed, insert, neq, next_msg, nvim,    helpers.insert, helpers.neq, helpers.next_message, helpers.nvim,    helpers.nvim_dir, helpers.ok, helpers.source,    helpers.write_file, helpers.mkdir, helpers.rmdir +local command = helpers.command  local Screen = require('test.functional.ui.screen') @@ -429,6 +430,13 @@ describe('jobs', function()      eq({'notification', 'j', {0, {jobid, 'exit'}}}, next_msg())    end) +  it('cannot have both rpc and pty options', function() +    command("let g:job_opts.pty = v:true") +    command("let g:job_opts.rpc = v:true") +    local _, err = pcall(command, "let j = jobstart(['cat', '-'], g:job_opts)") +    ok(string.find(err, "E475: Invalid argument: job cannot have both 'pty' and 'rpc' options set") ~= nil) +  end) +    describe('running tty-test program', function()      local function next_chunk()        local rv | 
