test(exrc): add tests for .nvimrc and .nvim.lua (#21478)

This commit is contained in:
Munif Tanjim
2022-12-20 06:38:24 +06:00
committed by GitHub
parent b3c9563e6b
commit 03166838ab

View File

@@ -581,15 +581,26 @@ describe('user config init', function()
local exrc_path = '.exrc' local exrc_path = '.exrc'
local xstate = 'Xstate' local xstate = 'Xstate'
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))
else
write_file(exrc_path, string.format([[
let g:exrc_file = "%s"
]], exrc_path))
end
end
before_each(function() before_each(function()
write_file(init_lua_path, [[ write_file(init_lua_path, [[
vim.o.exrc = true vim.o.exrc = true
vim.g.from_exrc = 0 vim.g.exrc_file = '---'
]]) ]])
mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim'))
write_file(exrc_path, [[
let g:from_exrc = 1
]])
end) end)
after_each(function() after_each(function()
@@ -597,10 +608,13 @@ describe('user config init', function()
rmdir(xstate) rmdir(xstate)
end) end)
it('loads .exrc #13501', function() for _, filename in ipairs({ '.exrc', '.nvimrc', '.nvim.lua' }) do
it('loads ' .. filename, function ()
setup_exrc_file(filename)
clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } }
-- 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(0, eval('g:from_exrc')) eq('---', eval('g:exrc_file'))
local screen = Screen.new(50, 8) local screen = Screen.new(50, 8)
screen:attach() screen:attach()
@@ -618,22 +632,23 @@ describe('user config init', function()
| |
-- TERMINAL -- | -- TERMINAL -- |
]]) ]])
feed(':echo g:from_exrc<CR>') feed(':echo g:exrc_file<CR>')
screen:expect([[ screen:expect(string.format([[
| |
~ | ~ |
~ | ~ |
~ | ~ |
~ | ~ |
[No Name] 0,0-1 All| [No Name] 0,0-1 All|
1 | %s%s|
-- TERMINAL -- | -- TERMINAL -- |
]]) ]], filename, string.rep(' ', 50 - #filename)))
clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } }
-- The .exrc file is now trusted. -- The 'exrc' file is now trusted.
eq(1, eval('g:from_exrc')) eq(filename, eval('g:exrc_file'))
end) end)
end
end) end)
describe('with explicitly provided config', function() describe('with explicitly provided config', function()