test(core/startup_spec): add a test for #13720

(cherry picked from commit 3cd69055de)
This commit is contained in:
zeertzjq
2023-06-05 11:38:57 +08:00
committed by github-actions[bot]
parent 8dd4a2bdd1
commit cba4362d85

View File

@@ -29,11 +29,6 @@ local alter_slashes = helpers.alter_slashes
local is_os = helpers.is_os local is_os = helpers.is_os
local dedent = helpers.dedent local dedent = helpers.dedent
local testfile = 'Xtest_startuptime'
after_each(function()
os.remove(testfile)
end)
describe('startup', function() describe('startup', function()
it('--clean', function() it('--clean', function()
clear() clear()
@@ -43,6 +38,10 @@ describe('startup', function()
end) end)
it('--startuptime', function() it('--startuptime', function()
local testfile = 'Xtest_startuptime'
finally(function()
os.remove(testfile)
end)
clear({ args = {'--startuptime', testfile}}) clear({ args = {'--startuptime', testfile}})
assert_log('sourcing', testfile, 100) assert_log('sourcing', testfile, 100)
assert_log("require%('vim%._editor'%)", testfile, 100) assert_log("require%('vim%._editor'%)", testfile, 100)
@@ -78,13 +77,7 @@ describe('startup', function()
end) end)
describe('startup', function() describe('startup', function()
before_each(function() before_each(clear)
clear()
os.remove('Xtest_startup_ttyout')
end)
after_each(function()
os.remove('Xtest_startup_ttyout')
end)
describe('-l Lua', function() describe('-l Lua', function()
local function assert_l_out(expected, nvim_args, lua_args, script, input) local function assert_l_out(expected, nvim_args, lua_args, script, input)
@@ -267,6 +260,10 @@ describe('startup', function()
if is_os('win') then if is_os('win') then
command([[set shellcmdflag=/s\ /c shellxquote=\"]]) command([[set shellcmdflag=/s\ /c shellxquote=\"]])
end end
os.remove('Xtest_startup_ttyout')
finally(function()
os.remove('Xtest_startup_ttyout')
end)
-- Running in :terminal -- Running in :terminal
command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]] command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]]
..nvim_set..[[\"]] ..nvim_set..[[\"]]
@@ -284,6 +281,10 @@ describe('startup', function()
if is_os('win') then if is_os('win') then
command([[set shellcmdflag=/s\ /c shellxquote=\"]]) command([[set shellcmdflag=/s\ /c shellxquote=\"]])
end end
os.remove('Xtest_startup_ttyout')
finally(function()
os.remove('Xtest_startup_ttyout')
end)
-- Running in :terminal -- Running in :terminal
command([[exe printf("terminal echo foo | ]] -- Input from a pipe. command([[exe printf("terminal echo foo | ]] -- Input from a pipe.
..[[%s -u NONE -i NONE --cmd \"]] ..[[%s -u NONE -i NONE --cmd \"]]
@@ -343,28 +344,6 @@ describe('startup', function()
{ '' })) { '' }))
end) end)
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('stdin with -es/-Es #7679', function() it('stdin with -es/-Es #7679', function()
local input = { 'append', 'line1', 'line2', '.', '%print', '' } local input = { 'append', 'line1', 'line2', '.', '%print', '' }
local inputstr = table.concat(input, '\n') local inputstr = table.concat(input, '\n')
@@ -420,23 +399,6 @@ describe('startup', function()
end end
end) 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) |
]])
eq('cv\n',
funcs.system({nvim_prog, '-n', '-es' },
{ 'put =mode(1)', 'print', '' }))
end)
it('fails on --embed with -es/-Es/-l', function() it('fails on --embed with -es/-Es/-l', function()
matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l',
funcs.system({nvim_prog, '--embed', '-es' })) funcs.system({nvim_prog, '--embed', '-es' }))
@@ -446,17 +408,6 @@ describe('startup', function()
funcs.system({nvim_prog, '--embed', '-l', 'foo.lua' })) funcs.system({nvim_prog, '--embed', '-l', 'foo.lua' }))
end) 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('ENTER dismisses early message #7967', function() it('ENTER dismisses early message #7967', function()
local screen local screen
screen = Screen.new(60, 6) screen = Screen.new(60, 6)
@@ -482,24 +433,6 @@ describe('startup', function()
]]) ]])
end) 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},
}})
end)
it('fixed hang issue with --headless (#11386)', function() it('fixed hang issue with --headless (#11386)', function()
local expected = '' local expected = ''
local period = 100 local period = 100
@@ -525,7 +458,102 @@ describe('startup', function()
'+q' }) '+q' })
eq('[\'+q\'] 1', out) eq('[\'+q\'] 1', out)
end) end)
end)
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) |
]])
eq('cv\n',
funcs.system({nvim_prog, '-n', '-es' },
{ 'put =mode(1)', 'print', '' }))
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'}}
eq(true, meths.get_option_value('diff', {win = funcs.win_getid(1)}))
eq(true, meths.get_option_value('diff', {win = funcs.win_getid(2)}))
local float_win = funcs.win_getid(3)
eq('editor', meths.win_get_config(float_win).relative)
eq(false, meths.get_option_value('diff', {win = float_win}))
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},
}})
end)
end)
describe('startup', function()
local function pack_clear(cmd) local function pack_clear(cmd)
-- add packages after config dir in rtp but before config/after -- 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/'}, 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/'},
@@ -533,7 +561,6 @@ describe('startup', function()
} }
end end
it("handles &packpath during startup", function() it("handles &packpath during startup", function()
pack_clear [[ pack_clear [[
let g:x = bar#test() let g:x = bar#test()
@@ -640,13 +667,13 @@ describe('startup', function()
end) end)
it('window widths are correct when modelines set &columns with tabpages', function() it('window widths are correct when modelines set &columns with tabpages', function()
write_file('tab1.noft', 'vim: columns=81') write_file('Xtab1.noft', 'vim: columns=81')
write_file('tab2.noft', 'vim: columns=81') write_file('Xtab2.noft', 'vim: columns=81')
finally(function() finally(function()
os.remove('tab1.noft') os.remove('Xtab1.noft')
os.remove('tab2.noft') os.remove('Xtab2.noft')
end) end)
clear({args = {'-p', 'tab1.noft', 'tab2.noft'}}) clear({args = {'-p', 'Xtab1.noft', 'Xtab2.noft'}})
eq(81, meths.win_get_width(0)) eq(81, meths.win_get_width(0))
command('tabnext') command('tabnext')
eq(81, meths.win_get_width(0)) eq(81, meths.win_get_width(0))
@@ -730,15 +757,16 @@ describe('user config init', function()
end) end)
it('loads init.lua from XDG config home by default', function() it('loads init.lua from XDG config home by default', function()
clear{ args_rm={'-u' }, env=xenv } clear{ args_rm={'-u'}, env=xenv }
eq(1, eval('g:lua_rc')) eq(1, eval('g:lua_rc'))
eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC')) eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC'))
end) end)
describe('with existing .exrc in cwd', function() describe('loads existing', function()
local exrc_path = '.exrc' local exrc_path = '.exrc'
local xstate = 'Xstate' local xstate = 'Xstate'
local xstateenv = { XDG_CONFIG_HOME=xconfig, XDG_DATA_HOME=xdata, XDG_STATE_HOME=xstate }
local function setup_exrc_file(filename) local function setup_exrc_file(filename)
exrc_path = filename exrc_path = filename
@@ -768,10 +796,10 @@ describe('user config init', function()
end) end)
for _, filename in ipairs({ '.exrc', '.nvimrc', '.nvim.lua' }) do for _, filename in ipairs({ '.exrc', '.nvimrc', '.nvim.lua' }) do
it('loads ' .. filename, function () it(filename .. ' in cwd', function()
setup_exrc_file(filename) setup_exrc_file(filename)
clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } clear{ args_rm={'-u'}, env=xstateenv }
-- The 'exrc' file is not trusted, and the prompt is skipped because there is no UI. -- The 'exrc' file is not trusted, and the prompt is skipped because there is no UI.
eq('---', eval('g:exrc_file')) eq('---', eval('g:exrc_file'))
@@ -803,7 +831,7 @@ describe('user config init', function()
-- TERMINAL -- | -- TERMINAL -- |
]], filename, string.rep(' ', 50 - #filename))) ]], filename, string.rep(' ', 50 - #filename)))
clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } clear{ args_rm={'-u'}, env=xstateenv }
-- The 'exrc' file is now trusted. -- The 'exrc' file is now trusted.
eq(filename, eval('g:exrc_file')) eq(filename, eval('g:exrc_file'))
end) end)