2017-10-31 05:28:16 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
|
2021-09-01 09:42:53 -07:00
|
|
|
local assert_alive = helpers.assert_alive
|
2017-10-31 05:28:16 -07:00
|
|
|
local clear = helpers.clear
|
|
|
|
local command = helpers.command
|
2020-06-07 10:13:52 -07:00
|
|
|
local ok = helpers.ok
|
2017-10-31 05:28:16 -07:00
|
|
|
local eq = helpers.eq
|
2019-09-13 16:29:59 -07:00
|
|
|
local matches = helpers.matches
|
2018-10-01 19:58:47 -07:00
|
|
|
local eval = helpers.eval
|
2020-10-19 11:05:54 -07:00
|
|
|
local exec_lua = helpers.exec_lua
|
2018-05-29 22:21:45 -07:00
|
|
|
local feed = helpers.feed
|
2017-10-31 05:28:16 -07:00
|
|
|
local funcs = helpers.funcs
|
2018-12-15 21:40:41 -07:00
|
|
|
local mkdir = helpers.mkdir
|
2021-06-02 09:46:25 -07:00
|
|
|
local mkdir_p = helpers.mkdir_p
|
2017-10-31 05:28:16 -07:00
|
|
|
local nvim_prog = helpers.nvim_prog
|
|
|
|
local nvim_set = helpers.nvim_set
|
|
|
|
local read_file = helpers.read_file
|
|
|
|
local retry = helpers.retry
|
2018-12-15 21:40:41 -07:00
|
|
|
local rmdir = helpers.rmdir
|
2017-12-02 19:38:58 -07:00
|
|
|
local sleep = helpers.sleep
|
2017-11-02 03:10:25 -07:00
|
|
|
local iswin = helpers.iswin
|
2021-10-02 01:37:30 -07:00
|
|
|
local startswith = helpers.startswith
|
2018-12-15 21:40:41 -07:00
|
|
|
local write_file = helpers.write_file
|
2020-06-07 10:13:52 -07:00
|
|
|
local meths = helpers.meths
|
2017-10-31 05:28:16 -07:00
|
|
|
|
|
|
|
describe('startup', function()
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
2017-12-02 19:38:58 -07:00
|
|
|
os.remove('Xtest_startup_ttyout')
|
2017-10-31 05:28:16 -07:00
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
os.remove('Xtest_startup_ttyout')
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function()
|
|
|
|
-- system() puts a pipe at both ends.
|
|
|
|
local out = funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless',
|
|
|
|
'--cmd', nvim_set,
|
|
|
|
'-c', [[echo has('ttyin') has('ttyout')]],
|
|
|
|
'+q' })
|
|
|
|
eq('0 0', out)
|
|
|
|
end)
|
|
|
|
it('with --embed: has("ttyin")==0 has("ttyout")==0', function()
|
|
|
|
local screen = Screen.new(25, 3)
|
|
|
|
-- Remote UI connected by --embed.
|
|
|
|
screen:attach()
|
|
|
|
command([[echo has('ttyin') has('ttyout')]])
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
0 0 |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
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()
|
2017-11-02 03:10:25 -07:00
|
|
|
if iswin() then
|
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
2017-10-31 05:28:16 -07:00
|
|
|
-- Running in :terminal
|
|
|
|
command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]]
|
2017-12-02 19:38:58 -07:00
|
|
|
..nvim_set..[[\"]]
|
|
|
|
..[[ -c \"echo has('ttyin') has('ttyout')\""]]
|
2017-10-31 05:28:16 -07:00
|
|
|
..[[, shellescape(v:progpath))]])
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2019-04-13 08:45:20 -07:00
|
|
|
~ |
|
2017-10-31 05:28:16 -07:00
|
|
|
1 1 |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
it('output to pipe: has("ttyin")==1 has("ttyout")==0', function()
|
2017-11-02 03:10:25 -07:00
|
|
|
if iswin() then
|
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
2017-10-31 05:28:16 -07:00
|
|
|
-- Running in :terminal
|
|
|
|
command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]]
|
2017-12-02 19:38:58 -07:00
|
|
|
..nvim_set..[[\"]]
|
|
|
|
..[[ -c \"call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')\"]]
|
|
|
|
..[[ -c q | cat -v"]] -- Output to a pipe.
|
2017-10-31 05:28:16 -07:00
|
|
|
..[[, shellescape(v:progpath))]])
|
|
|
|
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'))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
it('input from pipe: has("ttyin")==0 has("ttyout")==1', function()
|
|
|
|
if iswin() then
|
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
|
|
|
-- Running in :terminal
|
|
|
|
command([[exe printf("terminal echo foo | ]] -- Input from a pipe.
|
|
|
|
..[[%s -u NONE -i NONE --cmd \"]]
|
2017-12-02 19:38:58 -07:00
|
|
|
..nvim_set..[[\"]]
|
|
|
|
..[[ -c \"call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')\"]]
|
|
|
|
..[[ -c q -- -"]]
|
2017-10-31 05:28:16 -07:00
|
|
|
..[[, shellescape(v:progpath))]])
|
|
|
|
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'))
|
|
|
|
end)
|
|
|
|
end)
|
2017-12-02 19:38:58 -07:00
|
|
|
it('input from pipe (implicit) #7679', function()
|
2019-04-13 08:45:20 -07:00
|
|
|
local screen = Screen.new(25, 4)
|
2017-12-02 19:38:58 -07:00
|
|
|
screen:attach()
|
|
|
|
if iswin() then
|
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
|
|
|
-- Running in :terminal
|
|
|
|
command([[exe printf("terminal echo foo | ]] -- Input from a pipe.
|
|
|
|
..[[%s -u NONE -i NONE --cmd \"]]
|
|
|
|
..nvim_set..[[\"]]
|
|
|
|
..[[ -c \"echo has('ttyin') has('ttyout')\""]]
|
|
|
|
..[[, shellescape(v:progpath))]])
|
|
|
|
screen:expect([[
|
|
|
|
^foo |
|
2019-04-13 08:45:20 -07:00
|
|
|
~ |
|
2017-12-02 19:38:58 -07:00
|
|
|
0 1 |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
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',
|
|
|
|
funcs.system({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', '' }))
|
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',
|
2018-06-17 14:05:28 -07:00
|
|
|
funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '--headless',
|
|
|
|
'+ls!',
|
|
|
|
'+qall!',
|
|
|
|
'-',
|
|
|
|
'file1',
|
|
|
|
'file2',
|
|
|
|
},
|
|
|
|
{ '' }))
|
2017-12-02 19:38:58 -07:00
|
|
|
end)
|
2018-05-26 18:41:02 -07:00
|
|
|
|
2018-05-29 22:21:45 -07:00
|
|
|
it('-e/-E interactive #7679', function()
|
2018-06-03 17:06:32 -07:00
|
|
|
clear('-e')
|
2018-05-29 22:21:45 -07:00
|
|
|
local screen = Screen.new(25, 3)
|
|
|
|
screen:attach()
|
2018-06-03 17:06:32 -07:00
|
|
|
feed("put ='from -e'<CR>")
|
|
|
|
screen:expect([[
|
|
|
|
:put ='from -e' |
|
|
|
|
from -e |
|
|
|
|
:^ |
|
|
|
|
]])
|
|
|
|
|
|
|
|
clear('-E')
|
|
|
|
screen = Screen.new(25, 3)
|
|
|
|
screen:attach()
|
2018-05-29 22:21:45 -07:00
|
|
|
feed("put ='from -E'<CR>")
|
|
|
|
screen:expect([[
|
2018-06-10 07:27:13 -07:00
|
|
|
:put ='from -E' |
|
2018-05-29 22:21:45 -07:00
|
|
|
from -E |
|
|
|
|
:^ |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
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',
|
|
|
|
funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '-Es', '+.print', 'test/functional/fixtures/tty-test.c' },
|
2018-05-27 22:09:55 -07:00
|
|
|
{ 'partylikeits1999', '' }))
|
2018-05-26 18:41:02 -07:00
|
|
|
eq(inputstr,
|
|
|
|
funcs.system({nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' },
|
|
|
|
input))
|
2018-06-17 05:22:02 -07:00
|
|
|
-- with `-u NORC`
|
|
|
|
eq('thepartycontinues\n',
|
|
|
|
funcs.system({nvim_prog, '-n', '-u', 'NORC', '-Es', '+.print' },
|
|
|
|
{ 'thepartycontinues', '' }))
|
|
|
|
-- without `-u`
|
|
|
|
eq('thepartycontinues\n',
|
|
|
|
funcs.system({nvim_prog, '-n', '-Es', '+.print' },
|
|
|
|
{ 'thepartycontinues', '' }))
|
2018-05-26 18:41:02 -07:00
|
|
|
|
|
|
|
--
|
|
|
|
-- -es: read stdin as ex-commands
|
|
|
|
--
|
|
|
|
eq(' encoding=utf-8\n',
|
|
|
|
funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '-es', 'test/functional/fixtures/tty-test.c' },
|
|
|
|
{ 'set encoding', '' }))
|
|
|
|
eq('line1\nline2\n',
|
|
|
|
funcs.system({nvim_prog, '-i', 'NONE', '-es', '-' },
|
|
|
|
input))
|
2018-06-17 05:22:02 -07:00
|
|
|
-- with `-u NORC`
|
|
|
|
eq(' encoding=utf-8\n',
|
|
|
|
funcs.system({nvim_prog, '-n', '-u', 'NORC', '-es' },
|
|
|
|
{ 'set encoding', '' }))
|
|
|
|
-- without `-u`
|
|
|
|
eq(' encoding=utf-8\n',
|
|
|
|
funcs.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
|
|
|
|
local out = funcs.system({nvim_prog, arg,
|
|
|
|
'+set swapfile? updatecount? shada?',
|
|
|
|
"+put =execute('scriptnames')", '+%print'})
|
|
|
|
local line1 = string.match(out, '^.-\n')
|
|
|
|
-- updatecount=0 means swapfile was disabled.
|
|
|
|
eq(" swapfile updatecount=0 shada=!,'100,<50,s10,h\n", line1)
|
|
|
|
-- Standard plugins were loaded, but not user config.
|
|
|
|
eq('health.vim', string.match(out, 'health.vim'))
|
|
|
|
eq(nil, string.match(out, 'init.vim'))
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2022-01-07 19:13:11 -07:00
|
|
|
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) |
|
|
|
|
]])
|
|
|
|
|
|
|
|
eq('cv\n',
|
|
|
|
funcs.system({nvim_prog, '-n', '-es' },
|
|
|
|
{ 'put =mode(1)', 'print', '' }))
|
|
|
|
end)
|
|
|
|
|
2019-08-12 07:44:53 -07:00
|
|
|
it('fails on --embed with -es/-Es', function()
|
2019-09-13 16:29:59 -07:00
|
|
|
matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es',
|
2019-08-12 07:44:53 -07:00
|
|
|
funcs.system({nvim_prog, '--embed', '-es' }))
|
2019-09-13 16:29:59 -07:00
|
|
|
matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es',
|
2019-08-12 07:44:53 -07:00
|
|
|
funcs.system({nvim_prog, '--embed', '-Es' }))
|
|
|
|
end)
|
|
|
|
|
2018-10-01 19:58:47 -07:00
|
|
|
it('does not crash if --embed is given twice', function()
|
|
|
|
clear{args={'--embed'}}
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive()
|
2018-10-01 19:58:47 -07:00
|
|
|
end)
|
2019-06-12 05:22:42 -07:00
|
|
|
|
|
|
|
it('does not crash when expanding cdpath during early_init', function()
|
|
|
|
clear{env={CDPATH='~doesnotexist'}}
|
|
|
|
eq(',~doesnotexist', eval('&cdpath'))
|
|
|
|
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()
|
|
|
|
command([[let g:id = termopen('"]]..nvim_prog..
|
|
|
|
[[" -u NONE -i NONE --cmd "set noruler" --cmd "let g:foo = g:bar"')]])
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
]])
|
2019-08-11 17:42:13 -07:00
|
|
|
command([[call chansend(g:id, "\n")]])
|
2019-05-31 20:19:58 -07:00
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
[No Name] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2019-09-08 12:44:14 -07:00
|
|
|
|
2019-09-08 20:58:36 -07:00
|
|
|
it("sets 'shortmess' when loading other tabs", function()
|
2019-09-08 12:44:14 -07:00
|
|
|
clear({args={'-p', 'a', 'b', 'c'}})
|
|
|
|
local screen = Screen.new(25, 4)
|
|
|
|
screen:attach()
|
|
|
|
screen:expect({grid=[[
|
2019-09-08 20:58:36 -07:00
|
|
|
{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},
|
2019-09-08 12:44:14 -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.
|
|
|
|
funcs.system({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()
|
|
|
|
local out = funcs.system({ 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)
|
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
|
|
|
|
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/'}}
|
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 availabe 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 ]])
|
|
|
|
|
|
|
|
local rtp = meths.get_option'rtp'
|
|
|
|
ok(startswith(rtp, 'test/functional/fixtures/nvim,test/functional/fixtures/pack/*/start/*,test/functional/fixtures/start/*,test/functional/fixtures,test/functional/fixtures/middle,'), 'rtp='..rtp)
|
|
|
|
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" ]]}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}}
|
|
|
|
eq({'ordinary', 'FANCY', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]])
|
|
|
|
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'
|
|
|
|
local pathsep = helpers.get_pathsep()
|
|
|
|
|
|
|
|
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))'))
|
|
|
|
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))'))
|
|
|
|
end)
|
2020-07-19 08:44:22 -07:00
|
|
|
|
|
|
|
it('fixed hang issue with -D (#12647)', function()
|
|
|
|
local screen
|
|
|
|
screen = Screen.new(60, 6)
|
|
|
|
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. |
|
|
|
|
cmd: augroup nvim_terminal |
|
|
|
|
> |
|
|
|
|
<" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
command([[call chansend(g:id, "cont\n")]])
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
[No Name] |
|
|
|
|
|
|
|
|
|
<" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2018-12-15 21:40:41 -07:00
|
|
|
end)
|
2020-06-07 10:13:52 -07:00
|
|
|
|
|
|
|
describe('clean', function()
|
|
|
|
clear()
|
2020-12-11 16:54:39 -07:00
|
|
|
ok(string.find(meths.get_option('runtimepath'), funcs.stdpath('config'), 1, true) ~= nil)
|
2020-06-07 10:13:52 -07:00
|
|
|
clear('--clean')
|
2020-12-11 16:54:39 -07:00
|
|
|
ok(string.find(meths.get_option('runtimepath'), funcs.stdpath('config'), 1, true) == nil)
|
2020-06-07 10:13:52 -07:00
|
|
|
end)
|
2020-05-03 13:49:11 -07:00
|
|
|
|
|
|
|
describe('user config init', function()
|
|
|
|
local xhome = 'Xhome'
|
|
|
|
local pathsep = helpers.get_pathsep()
|
|
|
|
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()
|
2021-09-12 00:14:36 -07:00
|
|
|
clear{ args_rm={'-u' }, env=xenv }
|
2020-05-03 13:49:11 -07:00
|
|
|
|
|
|
|
eq(1, eval('g:lua_rc'))
|
2021-09-21 08:47:46 -07:00
|
|
|
eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC'))
|
2020-05-03 13:49:11 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe 'with explicitly provided config'(function()
|
|
|
|
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)
|
|
|
|
|
|
|
|
describe 'VIMRC also exists'(function()
|
|
|
|
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 }
|
2021-11-27 09:10:48 -07:00
|
|
|
feed('<cr>') -- confirm "Conflicting config ..." message
|
2020-05-03 13:49:11 -07:00
|
|
|
eq(1, eval('g:lua_rc'))
|
2021-07-03 06:31:00 -07:00
|
|
|
matches('^E5422: Conflicting configs', meths.exec('messages', true))
|
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'
|
|
|
|
local pathsep = helpers.get_pathsep()
|
|
|
|
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)
|
|
|
|
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'))
|
|
|
|
rmdir(plugin_folder_path)
|
|
|
|
end)
|
|
|
|
|
2021-09-11 11:11:16 -07:00
|
|
|
it('loads plugin/*.lua from start packages', function()
|
2021-06-02 09:46:25 -07:00
|
|
|
local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory',
|
|
|
|
'start', 'test_plugin'}, pathsep)
|
|
|
|
local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep)
|
|
|
|
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'
|
|
|
|
|
2021-06-02 09:46:25 -07:00
|
|
|
mkdir_p(plugin_folder_path)
|
|
|
|
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'))
|
2021-06-11 23:10:05 -07:00
|
|
|
-- Check if plugin_file_path is listed in :scriptname
|
|
|
|
local scripts = meths.exec(':scriptnames', true)
|
|
|
|
assert.Truthy(scripts:find(plugin_file_path))
|
|
|
|
|
|
|
|
-- 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()
|
|
|
|
assert.Truthy(profile_log :find(plugin_file_path))
|
|
|
|
|
|
|
|
os.remove(profiler_file)
|
2021-06-02 09:46:25 -07:00
|
|
|
rmdir(plugin_path)
|
|
|
|
end)
|
|
|
|
|
2021-09-11 11:11:16 -07:00
|
|
|
it('loads plugin/*.lua from site packages', function()
|
|
|
|
local nvimdata = iswin() and "nvim-data" or "nvim"
|
|
|
|
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)
|
|
|
|
write_file(plugin_file_path, [[table.insert(_G.lista, "unos")]])
|
|
|
|
mkdir_p(plugin_after_path)
|
|
|
|
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")
|
|
|
|
|
|
|
|
rmdir(plugin_path)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
2021-06-02 09:46:25 -07:00
|
|
|
it('loads ftdetect/*.lua', function()
|
|
|
|
local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep)
|
|
|
|
local ftdetect_file = table.concat({ftdetect_folder , 'new-ft.lua'}, pathsep)
|
|
|
|
mkdir_p(ftdetect_folder)
|
|
|
|
write_file(ftdetect_file , [[vim.g.lua_ftdetect = 1]])
|
|
|
|
|
|
|
|
-- TODO(shadmansaleh): Figure out why this test fails without
|
|
|
|
-- setting VIMRUNTIME
|
|
|
|
clear{ args_rm={'-u'}, env={XDG_CONFIG_HOME=xconfig,
|
2021-09-12 00:14:36 -07:00
|
|
|
XDG_DATA_HOME=xdata,
|
2021-06-02 09:46:25 -07:00
|
|
|
VIMRUNTIME='runtime/'}}
|
|
|
|
|
|
|
|
eq(1, eval('g:lua_ftdetect'))
|
|
|
|
rmdir(ftdetect_folder)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2020-05-03 13:57:47 -07:00
|
|
|
describe('user session', function()
|
|
|
|
local xhome = 'Xhome'
|
|
|
|
local pathsep = helpers.get_pathsep()
|
|
|
|
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)
|