local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local assert_alive = helpers.assert_alive
local assert_log = helpers.assert_log
local clear = helpers.clear
local command = helpers.command
local ok = helpers.ok
local eq = helpers.eq
local matches = helpers.matches
local eval = helpers.eval
local exec = helpers.exec
local exec_capture = helpers.exec_capture
local exec_lua = helpers.exec_lua
local feed = helpers.feed
local funcs = helpers.funcs
local pesc = helpers.pesc
local mkdir = helpers.mkdir
local mkdir_p = helpers.mkdir_p
local nvim_prog = helpers.nvim_prog
local nvim_set = helpers.nvim_set
local read_file = helpers.read_file
local retry = helpers.retry
local rmdir = helpers.rmdir
local sleep = helpers.sleep
local startswith = helpers.startswith
local write_file = helpers.write_file
local meths = helpers.meths
local alter_slashes = helpers.alter_slashes
local is_os = helpers.is_os
local dedent = helpers.dedent
local tbl_map = helpers.tbl_map
local tbl_filter = helpers.tbl_filter
local endswith = helpers.endswith
describe('startup', function()
it('--clean', function()
clear()
ok(string.find(alter_slashes(meths.get_option_value('runtimepath', {})), funcs.stdpath('config'), 1, true) ~= nil)
clear('--clean')
ok(string.find(alter_slashes(meths.get_option_value('runtimepath', {})), funcs.stdpath('config'), 1, true) == nil)
end)
it('prevents remote UI infinite loop', function()
clear()
local screen
screen = Screen.new(84, 3)
screen:attach()
funcs.termopen({ nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' })
screen:expect([[
^Cannot attach UI of :terminal child to its parent. (Unset $NVIM to skip this check) |
|
|
]])
end)
it('--startuptime', function()
local testfile = 'Xtest_startuptime'
finally(function()
os.remove(testfile)
end)
clear({ args = {'--startuptime', testfile}})
assert_log('sourcing', testfile, 100)
assert_log("require%('vim%._editor'%)", testfile, 100)
end)
it('-D does not hang #12647', function()
clear()
local screen
screen = Screen.new(60, 7)
screen:attach()
command([[let g:id = termopen('"]]..nvim_prog..
[[" -u NONE -i NONE --cmd "set noruler" -D')]])
screen:expect([[
^ |
|
Entering Debug mode. Type "cont" to continue. |
nvim_exec2() |
cmd: aunmenu * |
> |
|
]])
command([[call chansend(g:id, "cont\n")]])
screen:expect([[
^ |
~ |
~ |
~ |
[No Name] |
|
|
]])
end)
end)
describe('startup', function()
before_each(clear)
describe('-l Lua', function()
local function assert_l_out(expected, nvim_args, lua_args, script, input)
local args = { nvim_prog }
vim.list_extend(args, nvim_args or {})
vim.list_extend(args, { '-l', (script or 'test/functional/fixtures/startup.lua') })
vim.list_extend(args, lua_args or {})
local out = funcs.system(args, input):gsub('\r\n', '\n')
return eq(dedent(expected), out)
end
it('failure modes', function()
-- nvim -l <empty>
matches('nvim%.?e?x?e?: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' }))
eq(1, eval('v:shell_error'))
end)
it('os.exit() sets Nvim exitcode', function()
-- tricky: LeakSanitizer triggers on os.exit() and disrupts the return value, disable it
exec_lua [[
local asan_options = os.getenv('ASAN_OPTIONS') or ''
if asan_options ~= '' then
asan_options = asan_options .. ':'
end
vim.uv.os_setenv('ASAN_OPTIONS', asan_options .. ':detect_leaks=0')
]]
-- nvim -l foo.lua -arg1 -- a b c
assert_l_out([[
bufs:
nvim args: 7
lua args: { "-arg1", "--exitcode", "73", "--arg2",
[0] = "test/functional/fixtures/startup.lua"
}]],
{},
{ '-arg1', "--exitcode", "73", '--arg2' }
)
eq(73, eval('v:shell_error'))
end)
it('Lua-error sets Nvim exitcode', function()
eq(0, eval('v:shell_error'))
matches('E5113: .* my pearls!!',
funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' }))
eq(1, eval('v:shell_error'))
matches('E5113: .* %[string "error%("whoa"%)"%]:1: whoa',
funcs.system({ nvim_prog, '-l', '-' }, 'error("whoa")'))
eq(1, eval('v:shell_error'))
end)
it('executes stdin "-"', function()
assert_l_out('arg0=- args=2 whoa\n',
nil,
{ 'arg1', 'arg 2' },
'-',
"print(('arg0=%s args=%d %s'):format(_G.arg[0], #_G.arg, 'whoa'))")
assert_l_out('biiig input: 1000042\n',
nil,
nil,
'-',
('print("biiig input: "..("%s"):len())'):format(string.rep('x', (1000 * 1000) + 42)))
eq(0, eval('v:shell_error'))
end)
it('does not truncate long print() message', function()
assert_l_out(('k'):rep(1234) .. '\n', nil, nil, '-', "print(('k'):rep(1234))")
end)
it('does not add newline when unnecessary', function()
assert_l_out('', nil, nil, '-', '')
assert_l_out
|