test(startup_spec): use getscriptinfo() instead of :scriptnames (#23034)

This commit is contained in:
zeertzjq 2023-04-12 09:17:32 +08:00 committed by GitHub
parent 2b35de386e
commit 57e9b7f2e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,9 @@ local meths = helpers.meths
local alter_slashes = helpers.alter_slashes 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 tbl_map = helpers.tbl_map
local tbl_filter = helpers.tbl_filter
local endswith = helpers.endswith
local testfile = 'Xtest_startuptime' local testfile = 'Xtest_startuptime'
after_each(function() after_each(function()
@ -202,12 +205,12 @@ describe('startup', function()
end) end)
it('disables swapfile/shada/config/plugins', function() it('disables swapfile/shada/config/plugins', function()
assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scriptnames=1', assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scripts=1',
nil, nil,
nil, nil,
'-', '-',
[[print(('updatecount=%d shadafile=%s loadplugins=%s scriptnames=%d'):format( [[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.split(vim.fn.execute('scriptnames'),'\n'))))]]) vim.o.updatecount, vim.o.shadafile, tostring(vim.o.loadplugins), math.max(1, #vim.fn.getscriptinfo())))]])
end) end)
end) end)
@ -398,11 +401,13 @@ describe('startup', function()
for _,arg in ipairs({'-es', '-Es'}) do for _,arg in ipairs({'-es', '-Es'}) do
local out = funcs.system({nvim_prog, arg, local out = funcs.system({nvim_prog, arg,
'+set swapfile? updatecount? shadafile?', '+set swapfile? updatecount? shadafile?',
"+put =execute('scriptnames')", '+%print'}) "+put =map(getscriptinfo(), {-> v:val.name})", '+%print'})
local line1 = string.match(out, '^.-\n') local line1 = string.match(out, '^.-\n')
-- updatecount=0 means swapfile was disabled. -- updatecount=0 means swapfile was disabled.
eq(" swapfile updatecount=0 shadafile=\n", line1) eq(" swapfile updatecount=0 shadafile=\n", line1)
eq(nil, string.match(out, 'init.vim')) -- Standard plugins were loaded, but not user config.
ok(string.find(out, 'man.lua') ~= nil)
ok(string.find(out, 'init.vim') == nil)
end end
end) end)
@ -863,6 +868,10 @@ describe('runtime:', function()
local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'},
pathsep) pathsep)
local profiler_file = 'test_startuptime.log' local profiler_file = 'test_startuptime.log'
finally(function()
os.remove(profiler_file)
rmdir(plugin_path)
end)
mkdir_p(plugin_folder_path) mkdir_p(plugin_folder_path)
write_file(plugin_file_path, [[vim.g.lua_plugin = 2]]) write_file(plugin_file_path, [[vim.g.lua_plugin = 2]])
@ -870,18 +879,15 @@ describe('runtime:', function()
clear{ args_rm={'-u'}, args={'--startuptime', profiler_file}, env=xenv } clear{ args_rm={'-u'}, args={'--startuptime', profiler_file}, env=xenv }
eq(2, eval('g:lua_plugin')) eq(2, eval('g:lua_plugin'))
-- Check if plugin_file_path is listed in :scriptname -- Check if plugin_file_path is listed in getscriptinfo()
local scripts = exec_capture('scriptnames') local scripts = tbl_map(function(s) return s.name end, funcs.getscriptinfo())
assert(scripts:find(plugin_file_path)) ok(#tbl_filter(function(s) return endswith(s, plugin_file_path) end, scripts) > 0)
-- Check if plugin_file_path is listed in startup profile -- Check if plugin_file_path is listed in startup profile
local profile_reader = io.open(profiler_file, 'r') local profile_reader = io.open(profiler_file, 'r')
local profile_log = profile_reader:read('*a') local profile_log = profile_reader:read('*a')
profile_reader:close() profile_reader:close()
assert(profile_log:find(plugin_file_path)) ok(profile_log:find(plugin_file_path) ~= nil)
os.remove(profiler_file)
rmdir(plugin_path)
end) end)
it('loads plugin/*.lua from site packages', function() it('loads plugin/*.lua from site packages', function()