2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2017-10-31 05:28:16 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local assert_alive = n.assert_alive
|
2024-04-08 02:03:20 -07:00
|
|
|
local assert_log = t.assert_log
|
2024-04-20 08:44:13 -07:00
|
|
|
local clear = n.clear
|
|
|
|
local command = n.command
|
2024-04-08 02:03:20 -07:00
|
|
|
local ok = t.ok
|
|
|
|
local eq = t.eq
|
|
|
|
local matches = t.matches
|
2024-04-20 08:44:13 -07:00
|
|
|
local eval = n.eval
|
|
|
|
local exec = n.exec
|
|
|
|
local exec_capture = n.exec_capture
|
|
|
|
local exec_lua = n.exec_lua
|
|
|
|
local feed = n.feed
|
|
|
|
local fn = n.fn
|
2024-01-12 04:28:20 -07:00
|
|
|
local pesc = vim.pesc
|
2024-04-08 02:03:20 -07:00
|
|
|
local mkdir = t.mkdir
|
2024-04-20 08:44:13 -07:00
|
|
|
local mkdir_p = n.mkdir_p
|
|
|
|
local nvim_prog = n.nvim_prog
|
|
|
|
local nvim_set = n.nvim_set
|
2024-04-08 02:03:20 -07:00
|
|
|
local read_file = t.read_file
|
|
|
|
local retry = t.retry
|
2024-04-20 08:44:13 -07:00
|
|
|
local rmdir = n.rmdir
|
2024-01-12 04:41:09 -07:00
|
|
|
local sleep = vim.uv.sleep
|
2024-01-12 04:28:20 -07:00
|
|
|
local startswith = vim.startswith
|
2024-04-08 02:03:20 -07:00
|
|
|
local write_file = t.write_file
|
2024-04-20 08:44:13 -07:00
|
|
|
local api = n.api
|
|
|
|
local alter_slashes = n.alter_slashes
|
2024-04-08 02:03:20 -07:00
|
|
|
local is_os = t.is_os
|
|
|
|
local dedent = t.dedent
|
2024-01-12 04:28:20 -07:00
|
|
|
local tbl_map = vim.tbl_map
|
|
|
|
local tbl_filter = vim.tbl_filter
|
|
|
|
local endswith = vim.endswith
|
2024-04-20 08:44:13 -07:00
|
|
|
local check_close = n.check_close
|
2017-10-31 05:28:16 -07:00
|
|
|
|
2023-09-24 12:19:01 -07:00
|
|
|
local testlog = 'Xtest-startupspec-log'
|
|
|
|
|
2022-07-09 13:26:10 -07:00
|
|
|
describe('startup', function()
|
|
|
|
it('--clean', function()
|
|
|
|
clear()
|
2022-12-19 09:37:45 -07:00
|
|
|
ok(
|
|
|
|
string.find(
|
2024-01-12 10:59:57 -07:00
|
|
|
alter_slashes(api.nvim_get_option_value('runtimepath', {})),
|
|
|
|
fn.stdpath('config'),
|
2022-12-19 09:37:45 -07:00
|
|
|
1,
|
|
|
|
true
|
|
|
|
) ~= nil
|
|
|
|
)
|
2022-07-09 13:26:10 -07:00
|
|
|
clear('--clean')
|
2022-12-19 09:37:45 -07:00
|
|
|
ok(
|
|
|
|
string.find(
|
2024-01-12 10:59:57 -07:00
|
|
|
alter_slashes(api.nvim_get_option_value('runtimepath', {})),
|
|
|
|
fn.stdpath('config'),
|
2022-12-19 09:37:45 -07:00
|
|
|
1,
|
|
|
|
true
|
|
|
|
) == nil
|
|
|
|
)
|
2022-07-09 13:26:10 -07:00
|
|
|
end)
|
|
|
|
|
2023-08-12 23:14:08 -07:00
|
|
|
it('prevents remote UI infinite loop', function()
|
|
|
|
clear()
|
|
|
|
local screen
|
|
|
|
screen = Screen.new(84, 3)
|
|
|
|
screen:attach()
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.termopen({ nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' })
|
2023-08-12 23:14:08 -07:00
|
|
|
screen:expect([[
|
|
|
|
^Cannot attach UI of :terminal child to its parent. (Unset $NVIM to skip this check) |
|
2023-12-09 05:42:00 -07:00
|
|
|
|*2
|
2023-08-12 23:14:08 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2022-07-09 13:26:10 -07:00
|
|
|
it('--startuptime', function()
|
2023-06-04 23:09:25 -07:00
|
|
|
local testfile = 'Xtest_startuptime'
|
|
|
|
finally(function()
|
|
|
|
os.remove(testfile)
|
|
|
|
end)
|
2022-07-09 13:26:10 -07:00
|
|
|
clear({ args = { '--startuptime', testfile } })
|
2024-02-09 15:56:52 -07:00
|
|
|
assert_log('Embedded', testfile, 100)
|
2023-01-16 16:12:59 -07:00
|
|
|
assert_log('sourcing', testfile, 100)
|
|
|
|
assert_log("require%('vim%._editor'%)", testfile, 100)
|
2022-07-09 13:26:10 -07:00
|
|
|
end)
|
2021-09-20 19:00:50 -07:00
|
|
|
|
|
|
|
it('-D does not hang #12647', function()
|
|
|
|
clear()
|
|
|
|
local screen
|
|
|
|
screen = Screen.new(60, 7)
|
|
|
|
screen:attach()
|
2024-03-22 03:02:52 -07:00
|
|
|
-- not the same colors on windows for some reason
|
|
|
|
screen._default_attr_ids = nil
|
2024-01-12 10:59:57 -07:00
|
|
|
local id = fn.termopen({
|
2023-12-07 15:58:03 -07:00
|
|
|
nvim_prog,
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'--cmd',
|
|
|
|
'set noruler',
|
|
|
|
'-D',
|
|
|
|
}, {
|
|
|
|
env = {
|
|
|
|
VIMRUNTIME = os.getenv('VIMRUNTIME'),
|
|
|
|
},
|
|
|
|
})
|
2024-04-05 03:08:54 -07:00
|
|
|
screen:expect({ any = pesc('Entering Debug mode. Type "cont" to continue.') })
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.chansend(id, 'cont\n')
|
2021-09-20 19:00:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2023-12-09 05:42:00 -07:00
|
|
|
~ |*3
|
2021-09-20 19:00:50 -07:00
|
|
|
[No Name] |
|
2023-12-09 05:42:00 -07:00
|
|
|
|*2
|
2021-09-20 19:00:50 -07:00
|
|
|
]])
|
|
|
|
end)
|
2024-08-06 07:20:26 -07:00
|
|
|
|
|
|
|
it(':filetype detect enables filetype detection with -u NONE', function()
|
|
|
|
clear()
|
|
|
|
eq('filetype detection:OFF plugin:OFF indent:OFF', exec_capture('filetype'))
|
|
|
|
command('filetype detect')
|
|
|
|
eq('filetype detection:ON plugin:OFF indent:OFF', exec_capture('filetype'))
|
|
|
|
end)
|
2022-07-09 13:26:10 -07:00
|
|
|
end)
|
|
|
|
|
2017-10-31 05:28:16 -07:00
|
|
|
describe('startup', function()
|
2023-06-04 23:09:25 -07:00
|
|
|
before_each(clear)
|
2017-10-31 05:28:16 -07:00
|
|
|
|
2023-09-24 12:19:01 -07:00
|
|
|
after_each(function()
|
2024-04-05 20:18:43 -07:00
|
|
|
check_close()
|
2023-09-24 12:19:01 -07:00
|
|
|
os.remove(testlog)
|
|
|
|
end)
|
|
|
|
|
2021-09-20 19:00:50 -07:00
|
|
|
describe('-l Lua', function()
|
2023-01-02 18:54:53 -07:00
|
|
|
local function assert_l_out(expected, nvim_args, lua_args, script, input)
|
|
|
|
local args = { nvim_prog }
|
2023-01-02 07:34:14 -07:00
|
|
|
vim.list_extend(args, nvim_args or {})
|
2023-01-02 18:54:53 -07:00
|
|
|
vim.list_extend(args, { '-l', (script or 'test/functional/fixtures/startup.lua') })
|
2023-01-02 07:34:14 -07:00
|
|
|
vim.list_extend(args, lua_args or {})
|
2024-01-12 10:59:57 -07:00
|
|
|
local out = fn.system(args, input):gsub('\r\n', '\n')
|
2021-09-20 19:00:50 -07:00
|
|
|
return eq(dedent(expected), out)
|
|
|
|
end
|
|
|
|
|
|
|
|
it('failure modes', function()
|
2023-01-02 18:54:53 -07:00
|
|
|
-- nvim -l <empty>
|
2024-01-12 10:59:57 -07:00
|
|
|
matches('nvim%.?e?x?e?: Argument missing after: "%-l"', fn.system({ nvim_prog, '-l' }))
|
2021-09-20 19:00:50 -07:00
|
|
|
eq(1, eval('v:shell_error'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('os.exit() sets Nvim exitcode', function()
|
2023-01-30 12:36:49 -07:00
|
|
|
-- tricky: LeakSanitizer triggers on os.exit() and disrupts the return value, disable it
|
|
|
|
exec_lua [[
|
2023-06-30 17:16:34 -07:00
|
|
|
local asan_options = os.getenv('ASAN_OPTIONS') or ''
|
|
|
|
if asan_options ~= '' then
|
|
|
|
asan_options = asan_options .. ':'
|
2023-01-30 12:36:49 -07:00
|
|
|
end
|
2023-06-30 17:16:34 -07:00
|
|
|
vim.uv.os_setenv('ASAN_OPTIONS', asan_options .. ':detect_leaks=0')
|
2023-01-30 12:36:49 -07:00
|
|
|
]]
|
2021-09-20 19:00:50 -07:00
|
|
|
-- nvim -l foo.lua -arg1 -- a b c
|
|
|
|
assert_l_out(
|
|
|
|
[[
|
|
|
|
bufs:
|
2023-01-02 18:54:53 -07:00
|
|
|
nvim args: 7
|
2023-01-06 18:12:54 -07:00
|
|
|
lua args: { "-arg1", "--exitcode", "73", "--arg2",
|
|
|
|
[0] = "test/functional/fixtures/startup.lua"
|
|
|
|
}]],
|
2021-09-20 19:00:50 -07:00
|
|
|
{},
|
|
|
|
{ '-arg1', '--exitcode', '73', '--arg2' }
|
|
|
|
)
|
|
|
|
eq(73, eval('v:shell_error'))
|
|
|
|
end)
|
|
|
|
|
2023-01-02 18:54:53 -07:00
|
|
|
it('Lua-error sets Nvim exitcode', function()
|
2023-01-02 07:34:14 -07:00
|
|
|
eq(0, eval('v:shell_error'))
|
|
|
|
matches(
|
|
|
|
'E5113: .* my pearls!!',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-01-02 07:34:14 -07:00
|
|
|
eq(1, eval('v:shell_error'))
|
2023-01-02 18:54:53 -07:00
|
|
|
matches(
|
|
|
|
'E5113: .* %[string "error%("whoa"%)"%]:1: whoa',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({ nvim_prog, '-l', '-' }, 'error("whoa")')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-01-02 18:54:53 -07:00
|
|
|
eq(1, eval('v:shell_error'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('executes stdin "-"', function()
|
2023-07-01 14:48:12 -07:00
|
|
|
assert_l_out(
|
|
|
|
'arg0=- args=2 whoa\n',
|
2023-01-02 18:54:53 -07:00
|
|
|
nil,
|
|
|
|
{ 'arg1', 'arg 2' },
|
|
|
|
'-',
|
2023-01-06 18:12:54 -07:00
|
|
|
"print(('arg0=%s args=%d %s'):format(_G.arg[0], #_G.arg, 'whoa'))"
|
|
|
|
)
|
2023-07-01 14:48:12 -07:00
|
|
|
assert_l_out(
|
|
|
|
'biiig input: 1000042\n',
|
2023-01-02 18:54:53 -07:00
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
'-',
|
|
|
|
('print("biiig input: "..("%s"):len())'):format(string.rep('x', (1000 * 1000) + 42))
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-01-02 18:54:53 -07:00
|
|
|
eq(0, eval('v:shell_error'))
|
2023-01-02 07:34:14 -07:00
|
|
|
end)
|
|
|
|
|
2023-06-30 17:16:34 -07:00
|
|
|
it('does not truncate long print() message', function()
|
2023-07-01 14:48:12 -07:00
|
|
|
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('foobar\n', nil, nil, '-', [[print('foobar\n')]])
|
2023-06-30 17:16:34 -07:00
|
|
|
end)
|
|
|
|
|
2021-09-20 19:00:50 -07:00
|
|
|
it('sets _G.arg', function()
|
2023-06-26 02:38:48 -07:00
|
|
|
-- nvim -l foo.lua
|
|
|
|
assert_l_out(
|
|
|
|
[[
|
|
|
|
bufs:
|
|
|
|
nvim args: 3
|
|
|
|
lua args: {
|
|
|
|
[0] = "test/functional/fixtures/startup.lua"
|
2023-07-01 14:48:12 -07:00
|
|
|
}
|
|
|
|
]],
|
2023-06-26 02:38:48 -07:00
|
|
|
{},
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
eq(0, eval('v:shell_error'))
|
|
|
|
|
2023-01-06 18:12:54 -07:00
|
|
|
-- nvim -l foo.lua [args]
|
2021-09-20 19:00:50 -07:00
|
|
|
assert_l_out(
|
|
|
|
[[
|
|
|
|
bufs:
|
2023-01-06 18:12:54 -07:00
|
|
|
nvim args: 7
|
|
|
|
lua args: { "-arg1", "--arg2", "--", "arg3",
|
|
|
|
[0] = "test/functional/fixtures/startup.lua"
|
2023-07-01 14:48:12 -07:00
|
|
|
}
|
|
|
|
]],
|
2021-09-20 19:00:50 -07:00
|
|
|
{},
|
2023-01-06 18:12:54 -07:00
|
|
|
{ '-arg1', '--arg2', '--', 'arg3' }
|
2021-09-20 19:00:50 -07:00
|
|
|
)
|
|
|
|
eq(0, eval('v:shell_error'))
|
|
|
|
|
|
|
|
-- nvim file1 file2 -l foo.lua -arg1 -- file3 file4
|
|
|
|
assert_l_out(
|
|
|
|
[[
|
2022-12-31 19:14:13 -07:00
|
|
|
bufs: file1 file2
|
2023-01-02 18:54:53 -07:00
|
|
|
nvim args: 10
|
2023-01-06 18:12:54 -07:00
|
|
|
lua args: { "-arg1", "arg 2", "--", "file3", "file4",
|
|
|
|
[0] = "test/functional/fixtures/startup.lua"
|
2023-07-01 14:48:12 -07:00
|
|
|
}
|
|
|
|
]],
|
2021-09-20 19:00:50 -07:00
|
|
|
{ 'file1', 'file2' },
|
|
|
|
{ '-arg1', 'arg 2', '--', 'file3', 'file4' }
|
|
|
|
)
|
|
|
|
eq(0, eval('v:shell_error'))
|
|
|
|
|
|
|
|
-- nvim -l foo.lua <vim args>
|
|
|
|
assert_l_out(
|
|
|
|
[[
|
|
|
|
bufs:
|
2023-01-02 18:54:53 -07:00
|
|
|
nvim args: 5
|
2023-01-06 18:12:54 -07:00
|
|
|
lua args: { "-c", "set wrap?",
|
|
|
|
[0] = "test/functional/fixtures/startup.lua"
|
2023-07-01 14:48:12 -07:00
|
|
|
}
|
|
|
|
]],
|
2021-09-20 19:00:50 -07:00
|
|
|
{},
|
|
|
|
{ '-c', 'set wrap?' }
|
|
|
|
)
|
|
|
|
eq(0, eval('v:shell_error'))
|
|
|
|
|
|
|
|
-- nvim <vim args> -l foo.lua <vim args>
|
|
|
|
assert_l_out(
|
|
|
|
-- luacheck: ignore 611 (Line contains only whitespaces)
|
|
|
|
[[
|
|
|
|
wrap
|
|
|
|
|
|
|
|
bufs:
|
2023-01-02 18:54:53 -07:00
|
|
|
nvim args: 7
|
2023-01-06 18:12:54 -07:00
|
|
|
lua args: { "-c", "set wrap?",
|
|
|
|
[0] = "test/functional/fixtures/startup.lua"
|
2023-07-01 14:48:12 -07:00
|
|
|
}
|
|
|
|
]],
|
2021-09-20 19:00:50 -07:00
|
|
|
{ '-c', 'set wrap?' },
|
|
|
|
{ '-c', 'set wrap?' }
|
|
|
|
)
|
|
|
|
eq(0, eval('v:shell_error'))
|
|
|
|
end)
|
2023-01-02 18:54:53 -07:00
|
|
|
|
|
|
|
it('disables swapfile/shada/config/plugins', function()
|
2023-07-01 14:48:12 -07:00
|
|
|
assert_l_out(
|
|
|
|
'updatecount=0 shadafile=NONE loadplugins=false scripts=1\n',
|
2023-01-02 18:54:53 -07:00
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
'-',
|
2023-04-11 18:17:32 -07:00
|
|
|
[[print(('updatecount=%d shadafile=%s loadplugins=%s scripts=%d'):format(
|
|
|
|
vim.o.updatecount, vim.o.shadafile, tostring(vim.o.loadplugins), math.max(1, #vim.fn.getscriptinfo())))]]
|
|
|
|
)
|
2023-01-02 18:54:53 -07:00
|
|
|
end)
|
2021-09-20 19:00:50 -07:00
|
|
|
end)
|
|
|
|
|
2023-06-30 17:16:34 -07:00
|
|
|
it('--cmd/-c/+ do not truncate long Lua print() message with --headless', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local out = fn.system({
|
2023-06-30 17:16:34 -07:00
|
|
|
nvim_prog,
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'--headless',
|
|
|
|
'--cmd',
|
|
|
|
'lua print(("A"):rep(1234))',
|
|
|
|
'-c',
|
|
|
|
'lua print(("B"):rep(1234))',
|
|
|
|
'+lua print(("C"):rep(1234))',
|
|
|
|
'+q',
|
|
|
|
})
|
|
|
|
eq(('A'):rep(1234) .. '\r\n' .. ('B'):rep(1234) .. '\r\n' .. ('C'):rep(1234), out)
|
|
|
|
end)
|
|
|
|
|
2017-10-31 05:28:16 -07:00
|
|
|
it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function()
|
|
|
|
-- system() puts a pipe at both ends.
|
2024-01-12 10:59:57 -07:00
|
|
|
local out = fn.system({
|
2017-10-31 05:28:16 -07:00
|
|
|
nvim_prog,
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'--headless',
|
|
|
|
'--cmd',
|
|
|
|
nvim_set,
|
|
|
|
'-c',
|
|
|
|
[[echo has('ttyin') has('ttyout')]],
|
|
|
|
'+q',
|
|
|
|
})
|
|
|
|
eq('0 0', out)
|
|
|
|
end)
|
2021-09-20 19:00:50 -07:00
|
|
|
|
2017-10-31 05:28:16 -07:00
|
|
|
it('with --embed: has("ttyin")==0 has("ttyout")==0', function()
|
|
|
|
local screen = Screen.new(25, 3)
|
|
|
|
-- Remote UI connected by --embed.
|
|
|
|
screen:attach()
|
2024-03-22 03:02:52 -07:00
|
|
|
-- TODO: a lot of tests in this file already use the new default color scheme.
|
|
|
|
-- once we do the batch update of tests to use it, remove this workarond
|
|
|
|
screen._default_attr_ids = nil
|
2017-10-31 05:28:16 -07:00
|
|
|
command([[echo has('ttyin') has('ttyout')]])
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
0 0 |
|
|
|
|
]])
|
|
|
|
end)
|
2021-09-20 19:00:50 -07:00
|
|
|
|
2017-10-31 05:28:16 -07:00
|
|
|
it('in a TTY: has("ttyin")==1 has("ttyout")==1', function()
|
2019-04-13 08:45:20 -07:00
|
|
|
local screen = Screen.new(25, 4)
|
2017-10-31 05:28:16 -07:00
|
|
|
screen:attach()
|
2024-03-22 03:02:52 -07:00
|
|
|
screen._default_attr_ids = nil
|
2022-11-21 17:13:30 -07:00
|
|
|
if is_os('win') then
|
2017-11-02 03:10:25 -07:00
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
2017-10-31 05:28:16 -07:00
|
|
|
-- Running in :terminal
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.termopen({
|
2023-12-07 15:58:03 -07:00
|
|
|
nvim_prog,
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'--cmd',
|
|
|
|
nvim_set,
|
|
|
|
'-c',
|
|
|
|
'echo has("ttyin") has("ttyout")',
|
|
|
|
}, {
|
|
|
|
env = {
|
|
|
|
VIMRUNTIME = os.getenv('VIMRUNTIME'),
|
|
|
|
},
|
|
|
|
})
|
2017-10-31 05:28:16 -07:00
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2019-04-13 08:45:20 -07:00
|
|
|
~ |
|
2017-10-31 05:28:16 -07:00
|
|
|
1 1 |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2021-09-20 19:00:50 -07:00
|
|
|
|
2017-10-31 05:28:16 -07:00
|
|
|
it('output to pipe: has("ttyin")==1 has("ttyout")==0', function()
|
2023-09-24 12:19:01 -07:00
|
|
|
clear({ env = { NVIM_LOG_FILE = testlog } })
|
2022-11-21 17:13:30 -07:00
|
|
|
if is_os('win') then
|
2017-11-02 03:10:25 -07:00
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
2023-06-04 23:09:25 -07:00
|
|
|
os.remove('Xtest_startup_ttyout')
|
|
|
|
finally(function()
|
|
|
|
os.remove('Xtest_startup_ttyout')
|
|
|
|
end)
|
2017-10-31 05:28:16 -07:00
|
|
|
-- Running in :terminal
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.termopen(
|
2024-01-02 18:09:18 -07:00
|
|
|
(
|
2023-12-07 15:58:03 -07:00
|
|
|
[["%s" -u NONE -i NONE --cmd "%s"]]
|
|
|
|
.. [[ -c "call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')"]]
|
|
|
|
.. [[ -c q | cat -v]]
|
|
|
|
):format(nvim_prog, nvim_set),
|
|
|
|
{
|
|
|
|
env = {
|
|
|
|
VIMRUNTIME = os.getenv('VIMRUNTIME'),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
2017-10-31 05:28:16 -07:00
|
|
|
retry(nil, 3000, function()
|
2017-12-02 19:38:58 -07:00
|
|
|
sleep(1)
|
2017-10-31 05:28:16 -07:00
|
|
|
eq(
|
|
|
|
'1\n0\n', -- stdin is a TTY, stdout is a pipe
|
|
|
|
read_file('Xtest_startup_ttyout')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2017-10-31 05:28:16 -07:00
|
|
|
end)
|
|
|
|
end)
|
2021-09-20 19:00:50 -07:00
|
|
|
|
2017-10-31 05:28:16 -07:00
|
|
|
it('input from pipe: has("ttyin")==0 has("ttyout")==1', function()
|
2023-09-24 12:19:01 -07:00
|
|
|
clear({ env = { NVIM_LOG_FILE = testlog } })
|
2022-11-21 17:13:30 -07:00
|
|
|
if is_os('win') then
|
2017-10-31 05:28:16 -07:00
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
2023-06-04 23:09:25 -07:00
|
|
|
os.remove('Xtest_startup_ttyout')
|
|
|
|
finally(function()
|
|
|
|
os.remove('Xtest_startup_ttyout')
|
|
|
|
end)
|
2017-10-31 05:28:16 -07:00
|
|
|
-- Running in :terminal
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.termopen(
|
2024-01-02 18:09:18 -07:00
|
|
|
(
|
2023-12-07 15:58:03 -07:00
|
|
|
[[echo foo | ]] -- Input from a pipe.
|
|
|
|
.. [["%s" -u NONE -i NONE --cmd "%s"]]
|
|
|
|
.. [[ -c "call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')"]]
|
|
|
|
.. [[ -c q -- -]]
|
|
|
|
):format(nvim_prog, nvim_set),
|
|
|
|
{
|
|
|
|
env = {
|
|
|
|
VIMRUNTIME = os.getenv('VIMRUNTIME'),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
2017-10-31 05:28:16 -07:00
|
|
|
retry(nil, 3000, function()
|
2017-12-02 19:38:58 -07:00
|
|
|
sleep(1)
|
2017-10-31 05:28:16 -07:00
|
|
|
eq(
|
|
|
|
'0\n1\n', -- stdin is a pipe, stdout is a TTY
|
|
|
|
read_file('Xtest_startup_ttyout')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2017-10-31 05:28:16 -07:00
|
|
|
end)
|
|
|
|
end)
|
2021-09-20 19:00:50 -07:00
|
|
|
|
2017-12-02 19:38:58 -07:00
|
|
|
it('input from pipe (implicit) #7679', function()
|
2023-09-24 12:19:01 -07:00
|
|
|
clear({ env = { NVIM_LOG_FILE = testlog } })
|
2019-04-13 08:45:20 -07:00
|
|
|
local screen = Screen.new(25, 4)
|
2017-12-02 19:38:58 -07:00
|
|
|
screen:attach()
|
2024-03-22 03:02:52 -07:00
|
|
|
screen._default_attr_ids = nil
|
2022-11-21 17:13:30 -07:00
|
|
|
if is_os('win') then
|
2017-12-02 19:38:58 -07:00
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
|
|
|
-- Running in :terminal
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.termopen(
|
2024-01-02 18:09:18 -07:00
|
|
|
(
|
2023-12-07 15:58:03 -07:00
|
|
|
[[echo foo | ]]
|
|
|
|
.. [["%s" -u NONE -i NONE --cmd "%s"]]
|
|
|
|
.. [[ -c "echo has('ttyin') has('ttyout')"]]
|
|
|
|
):format(nvim_prog, nvim_set),
|
|
|
|
{
|
|
|
|
env = {
|
|
|
|
VIMRUNTIME = os.getenv('VIMRUNTIME'),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
2017-12-02 19:38:58 -07:00
|
|
|
screen:expect([[
|
|
|
|
^foo |
|
2019-04-13 08:45:20 -07:00
|
|
|
~ |
|
2017-12-02 19:38:58 -07:00
|
|
|
0 1 |
|
|
|
|
|
|
|
|
|
]])
|
2023-09-24 12:19:01 -07:00
|
|
|
if not is_os('win') then
|
2024-04-08 02:03:20 -07:00
|
|
|
assert_log('Failed to get flags on descriptor 3: Bad file descriptor', testlog, 100)
|
2023-09-24 12:19:01 -07:00
|
|
|
end
|
2017-12-02 19:38:58 -07:00
|
|
|
end)
|
2021-09-20 19:00:50 -07:00
|
|
|
|
2018-05-28 22:22:15 -07:00
|
|
|
it('input from pipe + file args #7679', function()
|
2018-05-27 22:09:55 -07:00
|
|
|
eq(
|
|
|
|
'ohyeah\r\n0 0 bufs=3',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({
|
2018-05-27 22:09:55 -07:00
|
|
|
nvim_prog,
|
|
|
|
'-n',
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'--headless',
|
|
|
|
'+.print',
|
|
|
|
"+echo has('ttyin') has('ttyout') 'bufs='.bufnr('$')",
|
|
|
|
'+qall!',
|
|
|
|
'-',
|
|
|
|
'test/functional/fixtures/tty-test.c',
|
|
|
|
'test/functional/fixtures/shell-test.c',
|
|
|
|
}, { 'ohyeah', '' })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2018-06-17 14:05:28 -07:00
|
|
|
end)
|
|
|
|
|
2018-06-18 09:48:28 -07:00
|
|
|
it('if stdin is empty: selects buffer 2, deletes buffer 1 #8561', function()
|
|
|
|
eq(
|
|
|
|
'\r\n 2 %a "file1" line 0\r\n 3 "file2" line 0',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({
|
2018-06-17 14:05:28 -07:00
|
|
|
nvim_prog,
|
|
|
|
'-n',
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'--headless',
|
|
|
|
'+ls!',
|
|
|
|
'+qall!',
|
|
|
|
'-',
|
|
|
|
'file1',
|
|
|
|
'file2',
|
|
|
|
}, { '' })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2017-12-02 19:38:58 -07:00
|
|
|
end)
|
2018-05-26 18:41:02 -07:00
|
|
|
|
2018-05-28 22:22:15 -07:00
|
|
|
it('stdin with -es/-Es #7679', function()
|
2018-05-26 18:41:02 -07:00
|
|
|
local input = { 'append', 'line1', 'line2', '.', '%print', '' }
|
|
|
|
local inputstr = table.concat(input, '\n')
|
|
|
|
|
|
|
|
--
|
|
|
|
-- -Es: read stdin as text
|
|
|
|
--
|
|
|
|
eq(
|
|
|
|
'partylikeits1999\n',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({
|
2018-05-26 18:41:02 -07:00
|
|
|
nvim_prog,
|
|
|
|
'-n',
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'-Es',
|
|
|
|
'+.print',
|
|
|
|
'test/functional/fixtures/tty-test.c',
|
2018-05-27 22:09:55 -07:00
|
|
|
}, { 'partylikeits1999', '' })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(inputstr, fn.system({ nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' }, input))
|
2018-06-17 05:22:02 -07:00
|
|
|
-- with `-u NORC`
|
|
|
|
eq(
|
|
|
|
'thepartycontinues\n',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({ nvim_prog, '-n', '-u', 'NORC', '-Es', '+.print' }, { 'thepartycontinues', '' })
|
2018-06-17 05:22:02 -07:00
|
|
|
)
|
|
|
|
-- without `-u`
|
|
|
|
eq(
|
|
|
|
'thepartycontinues\n',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({ nvim_prog, '-n', '-Es', '+.print' }, { 'thepartycontinues', '' })
|
2018-06-17 05:22:02 -07:00
|
|
|
)
|
2018-05-26 18:41:02 -07:00
|
|
|
|
|
|
|
--
|
|
|
|
-- -es: read stdin as ex-commands
|
|
|
|
--
|
|
|
|
eq(
|
|
|
|
' encoding=utf-8\n',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({
|
2018-05-26 18:41:02 -07:00
|
|
|
nvim_prog,
|
|
|
|
'-n',
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'-es',
|
|
|
|
'test/functional/fixtures/tty-test.c',
|
|
|
|
}, { 'set encoding', '' })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('line1\nline2\n', fn.system({ nvim_prog, '-i', 'NONE', '-es', '-' }, input))
|
2018-06-17 05:22:02 -07:00
|
|
|
-- with `-u NORC`
|
|
|
|
eq(
|
|
|
|
' encoding=utf-8\n',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({ nvim_prog, '-n', '-u', 'NORC', '-es' }, { 'set encoding', '' })
|
2018-06-17 05:22:02 -07:00
|
|
|
)
|
|
|
|
-- without `-u`
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(' encoding=utf-8\n', fn.system({ nvim_prog, '-n', '-es' }, { 'set encoding', '' }))
|
2018-05-26 18:41:02 -07:00
|
|
|
end)
|
2018-10-01 19:58:47 -07:00
|
|
|
|
2019-04-09 18:27:25 -07:00
|
|
|
it('-es/-Es disables swapfile, user config #8540', function()
|
|
|
|
for _, arg in ipairs({ '-es', '-Es' }) do
|
2024-01-12 10:59:57 -07:00
|
|
|
local out = fn.system({
|
2019-04-09 18:27:25 -07:00
|
|
|
nvim_prog,
|
|
|
|
arg,
|
2023-01-02 18:54:53 -07:00
|
|
|
'+set swapfile? updatecount? shadafile?',
|
2023-04-11 18:17:32 -07:00
|
|
|
'+put =map(getscriptinfo(), {-> v:val.name})',
|
|
|
|
'+%print',
|
|
|
|
})
|
2019-04-09 18:27:25 -07:00
|
|
|
local line1 = string.match(out, '^.-\n')
|
|
|
|
-- updatecount=0 means swapfile was disabled.
|
2023-01-02 18:54:53 -07:00
|
|
|
eq(' swapfile updatecount=0 shadafile=\n', line1)
|
2023-04-11 18:17:32 -07:00
|
|
|
-- Standard plugins were loaded, but not user config.
|
|
|
|
ok(string.find(out, 'man.lua') ~= nil)
|
|
|
|
ok(string.find(out, 'init.vim') == nil)
|
2019-04-09 18:27:25 -07:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2023-01-02 07:34:14 -07:00
|
|
|
it('fails on --embed with -es/-Es/-l', function()
|
|
|
|
matches(
|
|
|
|
'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({ nvim_prog, '--embed', '-es' })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-01-02 07:34:14 -07:00
|
|
|
matches(
|
|
|
|
'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({ nvim_prog, '--embed', '-Es' })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-01-02 07:34:14 -07:00
|
|
|
matches(
|
|
|
|
'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l',
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({ nvim_prog, '--embed', '-l', 'foo.lua' })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2019-08-12 07:44:53 -07:00
|
|
|
end)
|
|
|
|
|
2019-08-11 17:42:13 -07:00
|
|
|
it('ENTER dismisses early message #7967', function()
|
2019-05-31 20:19:58 -07:00
|
|
|
local screen
|
|
|
|
screen = Screen.new(60, 6)
|
|
|
|
screen:attach()
|
2024-03-22 03:02:52 -07:00
|
|
|
screen._default_attr_ids = nil
|
2024-01-12 10:59:57 -07:00
|
|
|
local id = fn.termopen({
|
2023-12-07 15:58:03 -07:00
|
|
|
nvim_prog,
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'--cmd',
|
|
|
|
'set noruler',
|
|
|
|
'--cmd',
|
|
|
|
'let g:foo = g:bar',
|
|
|
|
}, {
|
|
|
|
env = {
|
|
|
|
VIMRUNTIME = os.getenv('VIMRUNTIME'),
|
|
|
|
},
|
|
|
|
})
|
2019-05-31 20:19:58 -07:00
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2021-05-21 14:15:31 -07:00
|
|
|
|
|
2019-05-31 20:19:58 -07:00
|
|
|
Error detected while processing pre-vimrc command line: |
|
|
|
|
E121: Undefined variable: g:bar |
|
|
|
|
Press ENTER or type command to continue |
|
|
|
|
|
|
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.chansend(id, '\n')
|
2019-05-31 20:19:58 -07:00
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2023-12-09 05:42:00 -07:00
|
|
|
~ |*2
|
2019-05-31 20:19:58 -07:00
|
|
|
[No Name] |
|
2023-12-09 05:42:00 -07:00
|
|
|
|*2
|
2019-05-31 20:19:58 -07:00
|
|
|
]])
|
|
|
|
end)
|
2019-09-08 12:44:14 -07:00
|
|
|
|
2023-07-25 04:02:39 -07:00
|
|
|
it('-r works without --headless in PTY #23294', function()
|
2023-07-25 05:32:59 -07:00
|
|
|
exec([[
|
|
|
|
func Normalize(data) abort
|
|
|
|
" Windows: remove ^M and term escape sequences
|
|
|
|
return map(a:data, 'substitute(substitute(v:val, "\r", "", "g"), "\x1b\\%(\\]\\d\\+;.\\{-}\x07\\|\\[.\\{-}[\x40-\x7E]\\)", "", "g")')
|
|
|
|
endfunc
|
|
|
|
func OnOutput(id, data, event) dict
|
|
|
|
let g:stdout = Normalize(a:data)
|
|
|
|
endfunc
|
|
|
|
call jobstart([v:progpath, '-u', 'NONE', '-i', 'NONE', '-r'], {
|
|
|
|
\ 'pty': v:true,
|
|
|
|
\ 'stdout_buffered': v:true,
|
|
|
|
\ 'on_stdout': function('OnOutput'),
|
|
|
|
\ })
|
|
|
|
]])
|
|
|
|
retry(nil, nil, function()
|
|
|
|
eq('Swap files found:', eval('g:stdout[0]'))
|
|
|
|
end)
|
2023-07-25 04:02:39 -07:00
|
|
|
end)
|
|
|
|
|
2020-05-20 07:32:02 -07:00
|
|
|
it('fixed hang issue with --headless (#11386)', function()
|
|
|
|
local expected = ''
|
|
|
|
local period = 100
|
|
|
|
for i = 1, period - 1 do
|
|
|
|
expected = expected .. i .. '\r\n'
|
|
|
|
end
|
|
|
|
expected = expected .. period
|
|
|
|
eq(
|
|
|
|
expected,
|
|
|
|
-- FIXME(codehex): We should really set a timeout for the system function.
|
|
|
|
-- If this test fails, there will be a waiting input state.
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({
|
2020-05-20 07:32:02 -07:00
|
|
|
nvim_prog,
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-c',
|
|
|
|
'for i in range(1, 100) | echo i | endfor | quit',
|
|
|
|
'--headless',
|
|
|
|
})
|
|
|
|
)
|
|
|
|
end)
|
2020-05-24 11:45:25 -07:00
|
|
|
|
|
|
|
it('get command line arguments from v:argv', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local out = fn.system({
|
2020-05-24 11:45:25 -07:00
|
|
|
nvim_prog,
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'--headless',
|
|
|
|
'--cmd',
|
|
|
|
nvim_set,
|
|
|
|
'-c',
|
|
|
|
[[echo v:argv[-1:] len(v:argv) > 1]],
|
|
|
|
'+q',
|
|
|
|
})
|
|
|
|
eq("['+q'] 1", out)
|
|
|
|
end)
|
2023-06-04 23:09:25 -07:00
|
|
|
end)
|
2020-10-19 11:05:54 -07:00
|
|
|
|
2023-06-04 23:09:25 -07:00
|
|
|
describe('startup', function()
|
|
|
|
it('-e/-E interactive #7679', function()
|
|
|
|
clear('-e')
|
|
|
|
local screen = Screen.new(25, 3)
|
|
|
|
screen:attach()
|
|
|
|
feed("put ='from -e'<CR>")
|
|
|
|
screen:expect([[
|
|
|
|
:put ='from -e' |
|
|
|
|
from -e |
|
|
|
|
:^ |
|
|
|
|
]])
|
|
|
|
|
|
|
|
clear('-E')
|
|
|
|
screen = Screen.new(25, 3)
|
|
|
|
screen:attach()
|
|
|
|
feed("put ='from -E'<CR>")
|
|
|
|
screen:expect([[
|
|
|
|
:put ='from -E' |
|
|
|
|
from -E |
|
|
|
|
:^ |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('-e sets ex mode', function()
|
|
|
|
local screen = Screen.new(25, 3)
|
|
|
|
clear('-e')
|
|
|
|
screen:attach()
|
|
|
|
-- Verify we set the proper mode both before and after :vi.
|
|
|
|
feed('put =mode(1)<CR>vi<CR>:put =mode(1)<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
cv |
|
|
|
|
^n |
|
|
|
|
:put =mode(1) |
|
|
|
|
]])
|
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('cv\n', fn.system({ nvim_prog, '-n', '-es' }, { 'put =mode(1)', 'print', '' }))
|
2023-06-04 23:09:25 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('-d does not diff non-arglist windows #13720 #21289', function()
|
|
|
|
write_file(
|
|
|
|
'Xdiff.vim',
|
|
|
|
[[
|
|
|
|
let bufnr = nvim_create_buf(0, 1)
|
|
|
|
let config = {
|
|
|
|
\ 'relative': 'editor',
|
|
|
|
\ 'focusable': v:false,
|
|
|
|
\ 'width': 1,
|
|
|
|
\ 'height': 1,
|
|
|
|
\ 'row': 3,
|
|
|
|
\ 'col': 3
|
|
|
|
\ }
|
|
|
|
autocmd WinEnter * call nvim_open_win(bufnr, v:false, config)]]
|
|
|
|
)
|
|
|
|
finally(function()
|
|
|
|
os.remove('Xdiff.vim')
|
|
|
|
end)
|
|
|
|
clear { args = { '-u', 'Xdiff.vim', '-d', 'Xdiff.vim', 'Xdiff.vim' } }
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(true, api.nvim_get_option_value('diff', { win = fn.win_getid(1) }))
|
|
|
|
eq(true, api.nvim_get_option_value('diff', { win = fn.win_getid(2) }))
|
|
|
|
local float_win = fn.win_getid(3)
|
|
|
|
eq('editor', api.nvim_win_get_config(float_win).relative)
|
|
|
|
eq(false, api.nvim_get_option_value('diff', { win = float_win }))
|
2023-06-04 23:09:25 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not crash if --embed is given twice', function()
|
|
|
|
clear { args = { '--embed' } }
|
|
|
|
assert_alive()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not crash when expanding cdpath during early_init', function()
|
|
|
|
clear { env = { CDPATH = '~doesnotexist' } }
|
|
|
|
assert_alive()
|
|
|
|
eq(',~doesnotexist', eval('&cdpath'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("sets 'shortmess' when loading other tabs", function()
|
|
|
|
clear({ args = { '-p', 'a', 'b', 'c' } })
|
|
|
|
local screen = Screen.new(25, 4)
|
|
|
|
screen:attach()
|
|
|
|
screen:expect({
|
|
|
|
grid = [[
|
|
|
|
{1: a }{2: b c }{3: }{2:X}|
|
|
|
|
^ |
|
|
|
|
{4:~ }|
|
|
|
|
|
|
|
|
|
]],
|
|
|
|
attr_ids = {
|
|
|
|
[1] = { bold = true },
|
|
|
|
[2] = { background = Screen.colors.LightGrey, underline = true },
|
|
|
|
[3] = { reverse = true },
|
|
|
|
[4] = { bold = true, foreground = Screen.colors.Blue1 },
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2023-06-04 23:09:25 -07:00
|
|
|
})
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('startup', function()
|
2020-10-19 11:05:54 -07:00
|
|
|
local function pack_clear(cmd)
|
2021-09-30 10:01:09 -07:00
|
|
|
-- add packages after config dir in rtp but before config/after
|
2022-09-24 17:20:47 -07:00
|
|
|
clear {
|
|
|
|
args = {
|
|
|
|
'--cmd',
|
|
|
|
'set packpath=test/functional/fixtures',
|
|
|
|
'--cmd',
|
|
|
|
'let paths=split(&rtp, ",")',
|
|
|
|
'--cmd',
|
|
|
|
'let &rtp = paths[0]..",test/functional/fixtures,test/functional/fixtures/middle,"..join(paths[1:],",")',
|
|
|
|
'--cmd',
|
|
|
|
cmd,
|
|
|
|
},
|
|
|
|
env = { XDG_CONFIG_HOME = 'test/functional/fixtures/' },
|
|
|
|
args_rm = { 'runtimepath' },
|
|
|
|
}
|
2020-10-19 11:05:54 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it('handles &packpath during startup', function()
|
2020-11-18 12:02:44 -07:00
|
|
|
pack_clear [[
|
|
|
|
let g:x = bar#test()
|
|
|
|
let g:y = leftpad#pad("heyya")
|
|
|
|
]]
|
2020-10-19 11:05:54 -07:00
|
|
|
eq(-3, eval 'g:x')
|
2020-11-18 12:02:44 -07:00
|
|
|
eq(' heyya', eval 'g:y')
|
2020-10-19 11:05:54 -07:00
|
|
|
|
2020-11-18 12:02:44 -07:00
|
|
|
pack_clear [[ lua _G.y = require'bar'.doit() _G.z = require'leftpad''howdy' ]]
|
|
|
|
eq({ 9003, '\thowdy' }, exec_lua [[ return { _G.y, _G.z } ]])
|
2020-10-19 11:05:54 -07:00
|
|
|
end)
|
|
|
|
|
2021-09-28 04:51:26 -07:00
|
|
|
it('handles require from &packpath in an async handler', function()
|
|
|
|
-- NO! you cannot just speed things up by calling async functions during startup!
|
|
|
|
-- It doesn't make anything actually faster! NOOOO!
|
|
|
|
pack_clear [[ lua require'async_leftpad'('brrrr', 'async_res') ]]
|
|
|
|
|
|
|
|
-- haha, async leftpad go brrrrr
|
|
|
|
eq('\tbrrrr', exec_lua [[ return _G.async_res ]])
|
|
|
|
end)
|
|
|
|
|
2020-10-19 11:05:54 -07:00
|
|
|
it('handles :packadd during startup', function()
|
2020-11-18 12:02:44 -07:00
|
|
|
-- control group: opt/bonus is not available by default
|
|
|
|
pack_clear [[
|
|
|
|
try
|
|
|
|
let g:x = bonus#secret()
|
|
|
|
catch
|
|
|
|
let g:err = v:exception
|
|
|
|
endtry
|
|
|
|
]]
|
|
|
|
eq('Vim(let):E117: Unknown function: bonus#secret', eval 'g:err')
|
|
|
|
|
|
|
|
pack_clear [[ lua _G.test = {pcall(function() require'bonus'.launch() end)} ]]
|
|
|
|
eq(
|
|
|
|
{ false, [[[string ":lua"]:1: module 'bonus' not found:]] },
|
|
|
|
exec_lua [[ _G.test[2] = string.gsub(_G.test[2], '[\r\n].*', '') return _G.test ]]
|
|
|
|
)
|
|
|
|
|
|
|
|
-- ok, time to launch the nukes:
|
2020-10-19 11:05:54 -07:00
|
|
|
pack_clear [[ packadd! bonus | let g:x = bonus#secret() ]]
|
|
|
|
eq('halloj', eval 'g:x')
|
|
|
|
|
|
|
|
pack_clear [[ packadd! bonus | lua _G.y = require'bonus'.launch() ]]
|
|
|
|
eq('CPE 1704 TKS', exec_lua [[ return _G.y ]])
|
|
|
|
end)
|
2021-09-11 11:11:16 -07:00
|
|
|
|
|
|
|
it('handles the correct order with start packages and after/', function()
|
|
|
|
pack_clear [[ lua _G.test_loadorder = {} vim.cmd "runtime! filen.lua" ]]
|
2021-09-30 10:01:09 -07:00
|
|
|
eq(
|
|
|
|
{ 'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after' },
|
|
|
|
exec_lua [[ return _G.test_loadorder ]]
|
|
|
|
)
|
2021-09-11 11:11:16 -07:00
|
|
|
end)
|
|
|
|
|
2021-10-02 01:37:30 -07:00
|
|
|
it('handles the correct order with start packages and after/ after startup', function()
|
|
|
|
pack_clear [[ lua _G.test_loadorder = {} ]]
|
|
|
|
command [[ runtime! filen.lua ]]
|
|
|
|
eq(
|
|
|
|
{ 'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after' },
|
|
|
|
exec_lua [[ return _G.test_loadorder ]]
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('handles the correct order with globpath(&rtp, ...)', function()
|
|
|
|
pack_clear [[ set loadplugins | lua _G.test_loadorder = {} ]]
|
|
|
|
command [[
|
|
|
|
for x in globpath(&rtp, "filen.lua",1,1)
|
|
|
|
call v:lua.dofile(x)
|
|
|
|
endfor
|
|
|
|
]]
|
|
|
|
eq(
|
|
|
|
{ 'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after' },
|
|
|
|
exec_lua [[ return _G.test_loadorder ]]
|
|
|
|
)
|
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
local rtp = api.nvim_get_option_value('rtp', {})
|
2022-06-30 04:16:46 -07:00
|
|
|
ok(
|
|
|
|
startswith(
|
|
|
|
rtp,
|
|
|
|
'test/functional/fixtures/nvim,test/functional/fixtures/pack/*/start/*,test/functional/fixtures/start/*,test/functional/fixtures,test/functional/fixtures/middle,'
|
|
|
|
),
|
|
|
|
'startswith(…)',
|
|
|
|
'rtp=' .. rtp
|
|
|
|
)
|
2021-10-02 01:37:30 -07:00
|
|
|
end)
|
|
|
|
|
2021-09-11 11:11:16 -07:00
|
|
|
it('handles the correct order with opt packages and after/', function()
|
|
|
|
pack_clear [[ lua _G.test_loadorder = {} vim.cmd "packadd! superspecial\nruntime! filen.lua" ]]
|
2021-09-30 10:01:09 -07:00
|
|
|
eq({
|
|
|
|
'ordinary',
|
|
|
|
'SuperSpecial',
|
|
|
|
'FANCY',
|
|
|
|
'mittel',
|
|
|
|
'FANCY after',
|
|
|
|
'SuperSpecial after',
|
|
|
|
'ordinary after',
|
|
|
|
}, exec_lua [[ return _G.test_loadorder ]])
|
2021-09-11 11:11:16 -07:00
|
|
|
end)
|
2021-09-27 01:00:36 -07:00
|
|
|
|
2021-10-02 01:37:30 -07:00
|
|
|
it('handles the correct order with opt packages and after/ after startup', function()
|
|
|
|
pack_clear [[ lua _G.test_loadorder = {} ]]
|
|
|
|
command [[
|
|
|
|
packadd! superspecial
|
|
|
|
runtime! filen.lua
|
|
|
|
]]
|
|
|
|
eq({
|
|
|
|
'ordinary',
|
|
|
|
'SuperSpecial',
|
|
|
|
'FANCY',
|
|
|
|
'mittel',
|
|
|
|
'FANCY after',
|
|
|
|
'SuperSpecial after',
|
|
|
|
'ordinary after',
|
|
|
|
}, exec_lua [[ return _G.test_loadorder ]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('handles the correct order with opt packages and globpath(&rtp, ...)', function()
|
|
|
|
pack_clear [[ set loadplugins | lua _G.test_loadorder = {} ]]
|
|
|
|
command [[
|
|
|
|
packadd! superspecial
|
|
|
|
for x in globpath(&rtp, "filen.lua",1,1)
|
|
|
|
call v:lua.dofile(x)
|
|
|
|
endfor
|
|
|
|
]]
|
|
|
|
eq({
|
|
|
|
'ordinary',
|
|
|
|
'SuperSpecial',
|
|
|
|
'FANCY',
|
|
|
|
'mittel',
|
|
|
|
'SuperSpecial after',
|
|
|
|
'FANCY after',
|
|
|
|
'ordinary after',
|
|
|
|
}, exec_lua [[ return _G.test_loadorder ]])
|
|
|
|
end)
|
|
|
|
|
2021-09-27 01:00:36 -07:00
|
|
|
it('handles the correct order with a package that changes packpath', function()
|
|
|
|
pack_clear [[ lua _G.test_loadorder = {} vim.cmd "packadd! funky\nruntime! filen.lua" ]]
|
2021-09-30 10:01:09 -07:00
|
|
|
eq(
|
|
|
|
{ 'ordinary', 'funky!', 'FANCY', 'mittel', 'FANCY after', 'ordinary after' },
|
|
|
|
exec_lua [[ return _G.test_loadorder ]]
|
|
|
|
)
|
|
|
|
eq({ 'ordinary', 'funky!', 'mittel', 'ordinary after' }, exec_lua [[ return _G.nested_order ]])
|
2021-09-27 01:00:36 -07:00
|
|
|
end)
|
2021-10-31 02:20:35 -07:00
|
|
|
|
|
|
|
it('handles the correct order when prepending packpath', function()
|
|
|
|
clear {
|
|
|
|
args = {
|
|
|
|
'--cmd',
|
|
|
|
'set packpath^=test/functional/fixtures',
|
|
|
|
'--cmd',
|
|
|
|
[[ lua _G.test_loadorder = {} vim.cmd "runtime! filen.lua" ]],
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2021-10-31 02:20:35 -07:00
|
|
|
env = { XDG_CONFIG_HOME = 'test/functional/fixtures/' },
|
|
|
|
}
|
|
|
|
eq(
|
|
|
|
{ 'ordinary', 'FANCY', 'FANCY after', 'ordinary after' },
|
|
|
|
exec_lua [[ return _G.test_loadorder ]]
|
|
|
|
)
|
|
|
|
end)
|
2022-12-30 00:06:47 -07:00
|
|
|
|
|
|
|
it('window widths are correct when modelines set &columns with tabpages', function()
|
2023-06-04 23:09:25 -07:00
|
|
|
write_file('Xtab1.noft', 'vim: columns=81')
|
|
|
|
write_file('Xtab2.noft', 'vim: columns=81')
|
2022-12-30 00:06:47 -07:00
|
|
|
finally(function()
|
2023-06-04 23:09:25 -07:00
|
|
|
os.remove('Xtab1.noft')
|
|
|
|
os.remove('Xtab2.noft')
|
2022-12-30 00:06:47 -07:00
|
|
|
end)
|
2023-06-04 23:09:25 -07:00
|
|
|
clear({ args = { '-p', 'Xtab1.noft', 'Xtab2.noft' } })
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(81, api.nvim_win_get_width(0))
|
2022-12-30 00:06:47 -07:00
|
|
|
command('tabnext')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(81, api.nvim_win_get_width(0))
|
2022-12-30 00:06:47 -07:00
|
|
|
end)
|
2017-10-31 05:28:16 -07:00
|
|
|
end)
|
|
|
|
|
2018-12-15 21:40:41 -07:00
|
|
|
describe('sysinit', function()
|
|
|
|
local xdgdir = 'Xxdg'
|
|
|
|
local vimdir = 'Xvim'
|
|
|
|
local xhome = 'Xhome'
|
2024-04-20 08:44:13 -07:00
|
|
|
local pathsep = n.get_pathsep()
|
2018-12-15 21:40:41 -07:00
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
rmdir(xdgdir)
|
|
|
|
rmdir(vimdir)
|
|
|
|
rmdir(xhome)
|
|
|
|
|
|
|
|
mkdir(xdgdir)
|
|
|
|
mkdir(xdgdir .. pathsep .. 'nvim')
|
|
|
|
write_file(
|
|
|
|
table.concat({ xdgdir, 'nvim', 'sysinit.vim' }, pathsep),
|
|
|
|
[[
|
|
|
|
let g:loaded = get(g:, "loaded", 0) + 1
|
|
|
|
let g:xdg = 1
|
|
|
|
]]
|
|
|
|
)
|
|
|
|
|
|
|
|
mkdir(vimdir)
|
|
|
|
write_file(
|
|
|
|
table.concat({ vimdir, 'sysinit.vim' }, pathsep),
|
|
|
|
[[
|
|
|
|
let g:loaded = get(g:, "loaded", 0) + 1
|
|
|
|
let g:vim = 1
|
|
|
|
]]
|
|
|
|
)
|
|
|
|
|
|
|
|
mkdir(xhome)
|
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
rmdir(xdgdir)
|
|
|
|
rmdir(vimdir)
|
|
|
|
rmdir(xhome)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('prefers XDG_CONFIG_DIRS over VIM', function()
|
2019-04-16 16:08:48 -07:00
|
|
|
clear {
|
|
|
|
args = { '--cmd', 'set nomore undodir=. directory=. belloff=' },
|
|
|
|
args_rm = { '-u', '--cmd' },
|
|
|
|
env = { HOME = xhome, XDG_CONFIG_DIRS = xdgdir, VIM = vimdir },
|
|
|
|
}
|
2018-12-15 21:40:41 -07:00
|
|
|
eq(
|
|
|
|
'loaded 1 xdg 1 vim 0',
|
|
|
|
eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2018-12-15 21:40:41 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('uses VIM if XDG_CONFIG_DIRS unset', function()
|
2019-04-16 16:08:48 -07:00
|
|
|
clear {
|
|
|
|
args = { '--cmd', 'set nomore undodir=. directory=. belloff=' },
|
|
|
|
args_rm = { '-u', '--cmd' },
|
|
|
|
env = { HOME = xhome, XDG_CONFIG_DIRS = '', VIM = vimdir },
|
|
|
|
}
|
2018-12-15 21:40:41 -07:00
|
|
|
eq(
|
|
|
|
'loaded 1 xdg 0 vim 1',
|
|
|
|
eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2018-12-15 21:40:41 -07:00
|
|
|
end)
|
|
|
|
end)
|
2020-06-07 10:13:52 -07:00
|
|
|
|
2020-05-03 13:49:11 -07:00
|
|
|
describe('user config init', function()
|
|
|
|
local xhome = 'Xhome'
|
2024-04-20 08:44:13 -07:00
|
|
|
local pathsep = n.get_pathsep()
|
2020-05-03 13:49:11 -07:00
|
|
|
local xconfig = xhome .. pathsep .. 'Xconfig'
|
2021-09-12 00:14:36 -07:00
|
|
|
local xdata = xhome .. pathsep .. 'Xdata'
|
2020-05-03 13:49:11 -07:00
|
|
|
local init_lua_path = table.concat({ xconfig, 'nvim', 'init.lua' }, pathsep)
|
2021-09-12 00:14:36 -07:00
|
|
|
local xenv = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata }
|
2020-05-03 13:49:11 -07:00
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
rmdir(xhome)
|
|
|
|
|
2021-06-12 10:15:38 -07:00
|
|
|
mkdir_p(xconfig .. pathsep .. 'nvim')
|
2021-09-12 00:14:36 -07:00
|
|
|
mkdir_p(xdata)
|
2020-05-03 13:49:11 -07:00
|
|
|
|
|
|
|
write_file(
|
|
|
|
init_lua_path,
|
|
|
|
[[
|
|
|
|
vim.g.lua_rc = 1
|
|
|
|
]]
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
rmdir(xhome)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('loads init.lua from XDG config home by default', function()
|
2023-06-04 23:09:25 -07:00
|
|
|
clear { args_rm = { '-u' }, env = xenv }
|
2020-05-03 13:49:11 -07:00
|
|
|
|
|
|
|
eq(1, eval('g:lua_rc'))
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(fn.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC'))
|
2020-05-03 13:49:11 -07:00
|
|
|
end)
|
|
|
|
|
2023-06-04 23:09:25 -07:00
|
|
|
describe('loads existing', function()
|
2022-11-25 17:50:52 -07:00
|
|
|
local exrc_path = '.exrc'
|
|
|
|
local xstate = 'Xstate'
|
2023-06-04 23:09:25 -07:00
|
|
|
local xstateenv = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata, XDG_STATE_HOME = xstate }
|
2022-11-25 17:50:52 -07:00
|
|
|
|
2022-12-19 17:38:24 -07:00
|
|
|
local function setup_exrc_file(filename)
|
|
|
|
exrc_path = filename
|
|
|
|
|
|
|
|
if string.find(exrc_path, '%.lua$') then
|
|
|
|
write_file(
|
|
|
|
exrc_path,
|
|
|
|
string.format(
|
|
|
|
[[
|
|
|
|
vim.g.exrc_file = "%s"
|
|
|
|
]],
|
|
|
|
exrc_path
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-12-19 17:38:24 -07:00
|
|
|
else
|
|
|
|
write_file(
|
|
|
|
exrc_path,
|
|
|
|
string.format(
|
|
|
|
[[
|
|
|
|
let g:exrc_file = "%s"
|
|
|
|
]],
|
|
|
|
exrc_path
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-12-19 17:38:24 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-25 17:50:52 -07:00
|
|
|
before_each(function()
|
|
|
|
write_file(
|
|
|
|
init_lua_path,
|
|
|
|
[[
|
|
|
|
vim.o.exrc = true
|
2022-12-19 17:38:24 -07:00
|
|
|
vim.g.exrc_file = '---'
|
2022-11-25 17:50:52 -07:00
|
|
|
]]
|
|
|
|
)
|
|
|
|
mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
os.remove(exrc_path)
|
|
|
|
rmdir(xstate)
|
|
|
|
end)
|
|
|
|
|
2022-12-19 17:38:24 -07:00
|
|
|
for _, filename in ipairs({ '.exrc', '.nvimrc', '.nvim.lua' }) do
|
2023-06-04 23:09:25 -07:00
|
|
|
it(filename .. ' in cwd', function()
|
2022-12-19 17:38:24 -07:00
|
|
|
setup_exrc_file(filename)
|
|
|
|
|
2023-06-04 23:09:25 -07:00
|
|
|
clear { args_rm = { '-u' }, env = xstateenv }
|
2022-12-19 17:38:24 -07:00
|
|
|
-- The 'exrc' file is not trusted, and the prompt is skipped because there is no UI.
|
|
|
|
eq('---', eval('g:exrc_file'))
|
|
|
|
|
|
|
|
local screen = Screen.new(50, 8)
|
|
|
|
screen:attach()
|
2024-03-22 03:02:52 -07:00
|
|
|
screen._default_attr_ids = nil
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.termopen({ nvim_prog }, {
|
2023-12-07 10:28:46 -07:00
|
|
|
env = {
|
|
|
|
VIMRUNTIME = os.getenv('VIMRUNTIME'),
|
|
|
|
},
|
|
|
|
})
|
2022-12-19 17:38:24 -07:00
|
|
|
screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') })
|
|
|
|
-- `i` to enter Terminal mode, `a` to allow
|
|
|
|
feed('ia')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2023-12-09 05:42:00 -07:00
|
|
|
~ |*4
|
2022-12-19 17:38:24 -07:00
|
|
|
[No Name] 0,0-1 All|
|
|
|
|
|
|
|
|
|
-- TERMINAL -- |
|
|
|
|
]])
|
|
|
|
feed(':echo g:exrc_file<CR>')
|
|
|
|
screen:expect(string.format(
|
|
|
|
[[
|
|
|
|
|
|
2023-12-09 05:42:00 -07:00
|
|
|
~ |*4
|
2022-12-19 17:38:24 -07:00
|
|
|
[No Name] 0,0-1 All|
|
|
|
|
%s%s|
|
|
|
|
-- TERMINAL -- |
|
|
|
|
]],
|
|
|
|
filename,
|
|
|
|
string.rep(' ', 50 - #filename)
|
|
|
|
))
|
|
|
|
|
2023-06-04 23:09:25 -07:00
|
|
|
clear { args_rm = { '-u' }, env = xstateenv }
|
2022-12-19 17:38:24 -07:00
|
|
|
-- The 'exrc' file is now trusted.
|
|
|
|
eq(filename, eval('g:exrc_file'))
|
|
|
|
end)
|
|
|
|
end
|
2022-11-25 17:50:52 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('with explicitly provided config', function()
|
2020-05-03 13:49:11 -07:00
|
|
|
local custom_lua_path = table.concat({ xhome, 'custom.lua' }, pathsep)
|
|
|
|
before_each(function()
|
|
|
|
write_file(
|
|
|
|
custom_lua_path,
|
|
|
|
[[
|
|
|
|
vim.g.custom_lua_rc = 1
|
|
|
|
]]
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('loads custom lua config and does not set $MYVIMRC', function()
|
2021-09-12 00:14:36 -07:00
|
|
|
clear { args = { '-u', custom_lua_path }, env = xenv }
|
2020-05-03 13:49:11 -07:00
|
|
|
eq(1, eval('g:custom_lua_rc'))
|
|
|
|
eq('', eval('$MYVIMRC'))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2022-11-25 17:50:52 -07:00
|
|
|
describe('VIMRC also exists', function()
|
2020-05-03 13:49:11 -07:00
|
|
|
before_each(function()
|
|
|
|
write_file(
|
|
|
|
table.concat({ xconfig, 'nvim', 'init.vim' }, pathsep),
|
|
|
|
[[
|
|
|
|
let g:vim_rc = 1
|
|
|
|
]]
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('loads default lua config, but shows an error', function()
|
2021-09-12 00:14:36 -07:00
|
|
|
clear { args_rm = { '-u' }, env = xenv }
|
2022-05-23 21:44:15 -07:00
|
|
|
feed('<cr><c-c>') -- Dismiss "Conflicting config …" message.
|
2020-05-03 13:49:11 -07:00
|
|
|
eq(1, eval('g:lua_rc'))
|
2023-03-25 19:49:32 -07:00
|
|
|
matches('^E5422: Conflicting configs', exec_capture('messages'))
|
2020-05-03 13:49:11 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
2020-05-03 13:57:47 -07:00
|
|
|
|
2021-06-02 09:46:25 -07:00
|
|
|
describe('runtime:', function()
|
|
|
|
local xhome = 'Xhome'
|
2024-04-20 08:44:13 -07:00
|
|
|
local pathsep = n.get_pathsep()
|
2021-06-02 09:46:25 -07:00
|
|
|
local xconfig = xhome .. pathsep .. 'Xconfig'
|
2021-09-12 00:14:36 -07:00
|
|
|
local xdata = xhome .. pathsep .. 'Xdata'
|
|
|
|
local xenv = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata }
|
2021-06-02 09:46:25 -07:00
|
|
|
|
|
|
|
setup(function()
|
2021-09-11 11:11:16 -07:00
|
|
|
rmdir(xhome)
|
2021-06-02 09:46:25 -07:00
|
|
|
mkdir_p(xconfig .. pathsep .. 'nvim')
|
2021-09-12 00:14:36 -07:00
|
|
|
mkdir_p(xdata)
|
2021-06-02 09:46:25 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
teardown(function()
|
|
|
|
rmdir(xhome)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('loads plugin/*.lua from XDG config home', function()
|
|
|
|
local plugin_folder_path = table.concat({ xconfig, 'nvim', 'plugin' }, pathsep)
|
|
|
|
local plugin_file_path = table.concat({ plugin_folder_path, 'plugin.lua' }, pathsep)
|
|
|
|
mkdir_p(plugin_folder_path)
|
2023-07-18 16:14:32 -07:00
|
|
|
finally(function()
|
|
|
|
rmdir(plugin_folder_path)
|
|
|
|
end)
|
2021-06-02 09:46:25 -07:00
|
|
|
write_file(plugin_file_path, [[ vim.g.lua_plugin = 1 ]])
|
|
|
|
|
2021-09-12 00:14:36 -07:00
|
|
|
clear { args_rm = { '-u' }, env = xenv }
|
2021-06-02 09:46:25 -07:00
|
|
|
|
|
|
|
eq(1, eval('g:lua_plugin'))
|
|
|
|
end)
|
|
|
|
|
2021-09-11 11:11:16 -07:00
|
|
|
it('loads plugin/*.lua from start packages', function()
|
2023-07-18 16:14:32 -07:00
|
|
|
local plugin_path =
|
|
|
|
table.concat({ xconfig, 'nvim', 'pack', 'category', 'start', 'test_plugin' }, pathsep)
|
2021-06-02 09:46:25 -07:00
|
|
|
local plugin_folder_path = table.concat({ plugin_path, 'plugin' }, pathsep)
|
2023-07-18 16:14:32 -07:00
|
|
|
local plugin_file_path = table.concat({ plugin_folder_path, 'plugin.lua' }, pathsep)
|
2021-06-11 23:10:05 -07:00
|
|
|
local profiler_file = 'test_startuptime.log'
|
2023-07-18 16:14:32 -07:00
|
|
|
mkdir_p(plugin_folder_path)
|
2023-04-11 18:17:32 -07:00
|
|
|
finally(function()
|
|
|
|
os.remove(profiler_file)
|
|
|
|
rmdir(plugin_path)
|
|
|
|
end)
|
2021-06-11 23:10:05 -07:00
|
|
|
|
2021-06-02 09:46:25 -07:00
|
|
|
write_file(plugin_file_path, [[vim.g.lua_plugin = 2]])
|
|
|
|
|
2021-09-12 00:14:36 -07:00
|
|
|
clear { args_rm = { '-u' }, args = { '--startuptime', profiler_file }, env = xenv }
|
2021-06-02 09:46:25 -07:00
|
|
|
|
|
|
|
eq(2, eval('g:lua_plugin'))
|
2023-04-11 18:17:32 -07:00
|
|
|
-- Check if plugin_file_path is listed in getscriptinfo()
|
|
|
|
local scripts = tbl_map(function(s)
|
|
|
|
return s.name
|
2024-01-12 10:59:57 -07:00
|
|
|
end, fn.getscriptinfo())
|
2023-04-11 18:17:32 -07:00
|
|
|
ok(#tbl_filter(function(s)
|
|
|
|
return endswith(s, plugin_file_path)
|
|
|
|
end, scripts) > 0)
|
2021-06-11 23:10:05 -07:00
|
|
|
|
|
|
|
-- Check if plugin_file_path is listed in startup profile
|
|
|
|
local profile_reader = io.open(profiler_file, 'r')
|
|
|
|
local profile_log = profile_reader:read('*a')
|
|
|
|
profile_reader:close()
|
2023-04-11 18:17:32 -07:00
|
|
|
ok(profile_log:find(plugin_file_path) ~= nil)
|
2021-06-02 09:46:25 -07:00
|
|
|
end)
|
|
|
|
|
2021-09-11 11:11:16 -07:00
|
|
|
it('loads plugin/*.lua from site packages', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
local nvimdata = is_os('win') and 'nvim-data' or 'nvim'
|
2021-09-11 11:11:16 -07:00
|
|
|
local plugin_path =
|
|
|
|
table.concat({ xdata, nvimdata, 'site', 'pack', 'xa', 'start', 'yb' }, pathsep)
|
|
|
|
local plugin_folder_path = table.concat({ plugin_path, 'plugin' }, pathsep)
|
|
|
|
local plugin_after_path = table.concat({ plugin_path, 'after', 'plugin' }, pathsep)
|
|
|
|
local plugin_file_path = table.concat({ plugin_folder_path, 'plugin.lua' }, pathsep)
|
|
|
|
local plugin_after_file_path = table.concat({ plugin_after_path, 'helloo.lua' }, pathsep)
|
|
|
|
mkdir_p(plugin_folder_path)
|
|
|
|
mkdir_p(plugin_after_path)
|
2023-07-18 16:14:32 -07:00
|
|
|
finally(function()
|
|
|
|
rmdir(plugin_path)
|
|
|
|
end)
|
|
|
|
|
|
|
|
write_file(plugin_file_path, [[table.insert(_G.lista, "unos")]])
|
2021-09-11 11:11:16 -07:00
|
|
|
write_file(plugin_after_file_path, [[table.insert(_G.lista, "dos")]])
|
|
|
|
|
|
|
|
clear { args_rm = { '-u' }, args = { '--cmd', 'lua _G.lista = {}' }, env = xenv }
|
|
|
|
|
|
|
|
eq({ 'unos', 'dos' }, exec_lua 'return _G.lista')
|
|
|
|
end)
|
|
|
|
|
2023-07-18 16:14:32 -07:00
|
|
|
it('no crash setting &rtp in plugins with :packloadall called before #18315', function()
|
|
|
|
local plugin_folder_path = table.concat({ xconfig, 'nvim', 'plugin' }, pathsep)
|
|
|
|
mkdir_p(plugin_folder_path)
|
|
|
|
finally(function()
|
|
|
|
rmdir(plugin_folder_path)
|
|
|
|
end)
|
|
|
|
|
|
|
|
write_file(
|
|
|
|
table.concat({ plugin_folder_path, 'plugin.vim' }, pathsep),
|
|
|
|
[[
|
|
|
|
let &runtimepath = &runtimepath
|
|
|
|
let g:vim_plugin = 1
|
|
|
|
]]
|
|
|
|
)
|
|
|
|
write_file(
|
|
|
|
table.concat({ plugin_folder_path, 'plugin.lua' }, pathsep),
|
|
|
|
[[
|
|
|
|
vim.o.runtimepath = vim.o.runtimepath
|
|
|
|
vim.g.lua_plugin = 1
|
|
|
|
]]
|
|
|
|
)
|
|
|
|
|
|
|
|
clear { args_rm = { '-u' }, args = { '--cmd', 'packloadall' }, env = xenv }
|
|
|
|
|
|
|
|
eq(1, eval('g:vim_plugin'))
|
|
|
|
eq(1, eval('g:lua_plugin'))
|
|
|
|
end)
|
2021-09-11 11:11:16 -07:00
|
|
|
|
2023-07-13 15:46:16 -07:00
|
|
|
it("loads ftdetect/*.{vim,lua} respecting 'rtp' order", function()
|
2024-06-22 06:17:36 -07:00
|
|
|
local rtp_folder = table.concat({ xconfig, 'nvim' }, pathsep)
|
|
|
|
local after_rtp_folder = table.concat({ rtp_folder, 'after' }, pathsep)
|
|
|
|
local ftdetect_folder = table.concat({ rtp_folder, 'ftdetect' }, pathsep)
|
|
|
|
local after_ftdetect_folder = table.concat({ after_rtp_folder, 'ftdetect' }, pathsep)
|
2021-06-02 09:46:25 -07:00
|
|
|
mkdir_p(ftdetect_folder)
|
2023-07-13 15:46:16 -07:00
|
|
|
mkdir_p(after_ftdetect_folder)
|
|
|
|
finally(function()
|
|
|
|
rmdir(ftdetect_folder)
|
|
|
|
rmdir(after_ftdetect_folder)
|
|
|
|
end)
|
2024-06-22 06:17:36 -07:00
|
|
|
write_file(table.concat({ rtp_folder, 'scripts.vim' }, pathsep), [[let g:aseq ..= 'S']])
|
|
|
|
write_file(table.concat({ after_rtp_folder, 'scripts.vim' }, pathsep), [[let g:aseq ..= 's']])
|
2023-07-13 15:46:16 -07:00
|
|
|
-- A .lua file is loaded after a .vim file if they only differ in extension.
|
|
|
|
-- All files in after/ftdetect/ are loaded after all files in ftdetect/.
|
2024-06-22 06:17:36 -07:00
|
|
|
write_file(
|
|
|
|
table.concat({ ftdetect_folder, 'new-ft.vim' }, pathsep),
|
|
|
|
[[
|
|
|
|
let g:seq ..= 'A'
|
|
|
|
autocmd BufRead,BufNewFile FTDETECT let g:aseq ..= 'A'
|
|
|
|
]]
|
|
|
|
)
|
2023-07-13 15:46:16 -07:00
|
|
|
write_file(
|
|
|
|
table.concat({ ftdetect_folder, 'new-ft.lua' }, pathsep),
|
2024-06-22 06:17:36 -07:00
|
|
|
[[
|
|
|
|
vim.g.seq = vim.g.seq .. 'B'
|
|
|
|
vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
|
|
|
|
pattern = 'FTDETECT',
|
|
|
|
command = "let g:aseq ..= 'B'",
|
|
|
|
})
|
|
|
|
]]
|
2023-07-13 15:46:16 -07:00
|
|
|
)
|
|
|
|
write_file(
|
|
|
|
table.concat({ after_ftdetect_folder, 'new-ft.vim' }, pathsep),
|
2024-06-22 06:17:36 -07:00
|
|
|
[[
|
|
|
|
let g:seq ..= 'a'
|
|
|
|
autocmd BufRead,BufNewFile FTDETECT let g:aseq ..= 'a'
|
|
|
|
]]
|
2023-07-13 15:46:16 -07:00
|
|
|
)
|
|
|
|
write_file(
|
|
|
|
table.concat({ after_ftdetect_folder, 'new-ft.lua' }, pathsep),
|
2024-06-22 06:17:36 -07:00
|
|
|
[[
|
|
|
|
vim.g.seq = vim.g.seq .. 'b'
|
|
|
|
vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
|
|
|
|
pattern = 'FTDETECT',
|
|
|
|
command = "let g:aseq ..= 'b'",
|
|
|
|
})
|
|
|
|
]]
|
2023-07-13 15:46:16 -07:00
|
|
|
)
|
|
|
|
clear { args_rm = { '-u' }, args = { '--cmd', 'let g:seq = ""' }, env = xenv }
|
|
|
|
eq('ABab', eval('g:seq'))
|
2024-06-22 06:17:36 -07:00
|
|
|
command('let g:aseq = ""')
|
|
|
|
command('edit FTDETECT')
|
|
|
|
eq('SsABab', eval('g:aseq'))
|
2021-06-02 09:46:25 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2020-05-03 13:57:47 -07:00
|
|
|
describe('user session', function()
|
|
|
|
local xhome = 'Xhome'
|
2024-04-20 08:44:13 -07:00
|
|
|
local pathsep = n.get_pathsep()
|
2020-05-03 13:57:47 -07:00
|
|
|
local session_file = table.concat({ xhome, 'session.lua' }, pathsep)
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
rmdir(xhome)
|
|
|
|
|
|
|
|
mkdir(xhome)
|
|
|
|
write_file(
|
|
|
|
session_file,
|
|
|
|
[[
|
|
|
|
vim.g.lua_session = 1
|
|
|
|
]]
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
rmdir(xhome)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('loads session from the provided lua file', function()
|
|
|
|
clear { args = { '-S', session_file }, env = { HOME = xhome } }
|
|
|
|
eq(1, eval('g:lua_session'))
|
|
|
|
end)
|
|
|
|
end)
|
2023-12-27 00:18:22 -07:00
|
|
|
|
|
|
|
describe('inccommand on ex mode', function()
|
|
|
|
it('should not preview', function()
|
|
|
|
clear()
|
|
|
|
local screen
|
|
|
|
screen = Screen.new(60, 10)
|
|
|
|
screen:attach()
|
2024-01-15 09:12:07 -07:00
|
|
|
local id = fn.termopen({
|
|
|
|
nvim_prog,
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'-c',
|
|
|
|
'set termguicolors background=dark',
|
|
|
|
'-E',
|
|
|
|
'test/README.md',
|
|
|
|
}, {
|
|
|
|
env = { VIMRUNTIME = os.getenv('VIMRUNTIME') },
|
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.chansend(id, '%s/N')
|
2023-12-27 00:18:22 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
{1:^ }|
|
|
|
|
{1: }|*6
|
|
|
|
{1:Entering Ex mode. Type "visual" to go to Normal mode. }|
|
|
|
|
{1::%s/N }|
|
|
|
|
|
|
|
|
|
]],
|
|
|
|
attr_ids = {
|
|
|
|
[1] = {
|
|
|
|
background = Screen.colors.NvimDarkGrey2,
|
|
|
|
foreground = Screen.colors.NvimLightGrey2,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
|
|
|
},
|
2023-12-27 00:18:22 -07:00
|
|
|
}
|
|
|
|
end)
|
|
|
|
end)
|