local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local tt = require('test.functional.testterm')
local describe, it, before_each, pending, finally =
t.describe, t.it, t.before_each, t.pending, t.finally
local clear = n.clear
local eq = t.eq
local eval = n.eval
local feed_command = n.feed_command
local feed = n.feed
local insert = n.insert
local neq = t.neq
local next_msg = n.next_msg
local testprg = n.testprg
local ok = t.ok
local source = n.source
local write_file = t.write_file
local mkdir = t.mkdir
local rmdir = n.rmdir
local assert_alive = n.assert_alive
local command = n.command
local fn = n.fn
local retry = t.retry
local api = n.api
local NIL = vim.NIL
local poke_eventloop = n.poke_eventloop
local get_pathsep = n.get_pathsep
local pathroot = n.pathroot
local exec_lua = n.exec_lua
local nvim_set = n.nvim_set
local expect_twostreams = n.expect_twostreams
local expect_msg_seq = n.expect_msg_seq
local pcall_err = t.pcall_err
local matches = t.matches
local skip = t.skip
local is_os = t.is_os
describe('jobs', function()
local channel
before_each(function()
clear()
channel = api.nvim_get_chan_info(0).id
api.nvim_set_var('channel', channel)
source([[
function! Normalize(data) abort
" Windows: remove ^M and term escape sequences
return type([]) == type(a:data)
\ ? mapnew(a:data, 'substitute(substitute(v:val, "\r", "", "g"), "\x1b\\%(\\]\\d\\+;.\\{-}\x07\\|\\[.\\{-}[\x40-\x7E]\\)", "", "g")')
\ : a:data
endfunction
function! OnEvent(id, data, event) dict
let userdata = get(self, 'user')
let data = Normalize(a:data)
" If Normalize() made non-empty data empty, doesn't send a notification.
if type([]) == type(data) && len(data) == 1 && !empty(a:data[0]) && empty(data[0])
return
endif
call rpcnotify(g:channel, a:event, userdata, data)
endfunction
let g:job_opts = {
\ 'on_stdout': function('OnEvent'),
\ 'on_exit': function('OnEvent'),
\ 'user': 0
\ }
]])
end)
it('validation', function()
matches(
"E475: Invalid argument: job cannot have both 'pty' and 'rpc' options set",
pcall_err(command, "call jobstart(['cat', '-'], { 'pty': v:true, 'rpc': v:true })")
)
matches(
'E475: Invalid argument: expected valid directory',
pcall_err(command, "call jobstart(['cat', '-'], { 'cwd': 9313843 })")
)
matches(
'E475: Invalid argument: expected valid directory',
pcall_err(command, "call jobstart(['cat', '-'], { 'cwd': 'bogusssssss/bogus' })")
)
matches(
"E475: Invalid argument: 'term' must be Boolean",
pcall_err(command, "call jobstart(['cat', '-'], { 'term': 'bogus' })")
)
matches(
"E475: Invalid argument: 'term' must be Boolean",
pcall_err(command, "call jobstart(['cat', '-'], { 'term': 1 })")
)
command('set modified')
matches(
vim.pesc('jobstart(...,{term=true}) requires unmodified buffer'),
pcall_err(command, "call jobstart(['cat', '-'], { 'term': v:true })")
)
-- Non-failure cases:
command('set nomodified')
command("call jobstart(['cat', '-'], { 'term': v:true })")
command
|