diff options
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 | ||||
-rw-r--r-- | test/functional/fixtures/autoload/health/broken.vim | 3 | ||||
-rw-r--r-- | test/functional/fixtures/autoload/health/success1.vim | 6 | ||||
-rw-r--r-- | test/functional/fixtures/autoload/health/success2.vim | 4 | ||||
-rw-r--r-- | test/functional/helpers.lua | 1 | ||||
-rw-r--r-- | test/functional/plugin/health_spec.lua | 81 |
8 files changed, 184 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 diff --git a/test/functional/fixtures/autoload/health/broken.vim b/test/functional/fixtures/autoload/health/broken.vim new file mode 100644 index 0000000000..a2a595b96f --- /dev/null +++ b/test/functional/fixtures/autoload/health/broken.vim @@ -0,0 +1,3 @@ +function! health#broken#check() + throw 'caused an error' +endfunction diff --git a/test/functional/fixtures/autoload/health/success1.vim b/test/functional/fixtures/autoload/health/success1.vim new file mode 100644 index 0000000000..a360347455 --- /dev/null +++ b/test/functional/fixtures/autoload/health/success1.vim @@ -0,0 +1,6 @@ +function! health#success1#check() + call health#report_start("report 1") + call health#report_ok("everything is fine") + call health#report_start("report 2") + call health#report_ok("nothing to see here") +endfunction diff --git a/test/functional/fixtures/autoload/health/success2.vim b/test/functional/fixtures/autoload/health/success2.vim new file mode 100644 index 0000000000..b742b4879d --- /dev/null +++ b/test/functional/fixtures/autoload/health/success2.vim @@ -0,0 +1,4 @@ +function! health#success2#check() + call health#report_start("another 1") + call health#report_ok("ok") +endfunction diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 6f43ec817c..2d54d23254 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -241,6 +241,7 @@ local function clear(...) 'ASAN_OPTIONS', 'LD_LIBRARY_PATH', 'PATH', 'NVIM_LOG_FILE', + 'NVIM_RPLUGIN_MANIFEST', }) do env_tbl[k] = os.getenv(k) end diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua new file mode 100644 index 0000000000..a9665cd751 --- /dev/null +++ b/test/functional/plugin/health_spec.lua @@ -0,0 +1,81 @@ +local helpers = require('test.functional.helpers')(after_each) +local plugin_helpers = require('test.functional.plugin.helpers') + +describe('health.vim', function() + before_each(function() + plugin_helpers.reset() + -- Provides functions: + -- health#broken#check() + -- health#success1#check() + -- health#success2#check() + helpers.execute("set runtimepath+=test/functional/fixtures") + end) + + it("reports", function() + helpers.source([[ + let g:health_report = execute([ + \ "call health#report_start('Check Bar')", + \ "call health#report_ok('Bar status')", + \ "call health#report_ok('Other Bar status')", + \ "call health#report_warn('Zub')", + \ "call health#report_start('Baz')", + \ "call health#report_warn('Zim', ['suggestion 1', 'suggestion 2'])" + \ ]) + ]]) + local result = helpers.eval("g:health_report") + + helpers.eq(helpers.dedent([[ + + + ## Check Bar + - SUCCESS: Bar status + - SUCCESS: Other Bar status + - WARNING: Zub + + ## Baz + - WARNING: Zim + - SUGGESTIONS: + - suggestion 1 + - suggestion 2]]), + result) + end) + + + describe(":CheckHealth", function() + it("concatenates multiple reports", function() + helpers.execute("CheckHealth success1 success2") + helpers.expect([[ + health#success1#check + ================================================================================ + + ## report 1 + - SUCCESS: everything is fine + + ## report 2 + - SUCCESS: nothing to see here + + health#success2#check + ================================================================================ + + ## another 1 + - SUCCESS: ok]]) + end) + + it("gracefully handles broken healthcheck", function() + helpers.execute("CheckHealth broken") + helpers.expect([[ + health#broken#check + ================================================================================ + - ERROR: Failed to run healthcheck for "broken" plugin. Exception: + caused an error]]) + end) + + it("gracefully handles invalid healthcheck", function() + helpers.execute("CheckHealth non_existent_healthcheck") + helpers.expect([[ + health#non_existent_healthcheck#check + ================================================================================ + - ERROR: No healthcheck found for "non_existent_healthcheck" plugin.]]) + end) + end) +end) |