mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
test(exrc): add tests for .nvimrc and .nvim.lua (#21478)
This commit is contained in:
@@ -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,43 +608,47 @@ 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
|
||||||
clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } }
|
it('loads ' .. filename, function ()
|
||||||
-- The .exrc file is not trusted, and the prompt is skipped because there is no UI.
|
setup_exrc_file(filename)
|
||||||
eq(0, eval('g:from_exrc'))
|
|
||||||
|
|
||||||
local screen = Screen.new(50, 8)
|
clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } }
|
||||||
screen:attach()
|
-- The 'exrc' file is not trusted, and the prompt is skipped because there is no UI.
|
||||||
funcs.termopen({nvim_prog})
|
eq('---', eval('g:exrc_file'))
|
||||||
screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') })
|
|
||||||
-- `i` to enter Terminal mode, `a` to allow
|
|
||||||
feed('ia')
|
|
||||||
screen:expect([[
|
|
||||||
|
|
|
||||||
~ |
|
|
||||||
~ |
|
|
||||||
~ |
|
|
||||||
~ |
|
|
||||||
[No Name] 0,0-1 All|
|
|
||||||
|
|
|
||||||
-- TERMINAL -- |
|
|
||||||
]])
|
|
||||||
feed(':echo g:from_exrc<CR>')
|
|
||||||
screen:expect([[
|
|
||||||
|
|
|
||||||
~ |
|
|
||||||
~ |
|
|
||||||
~ |
|
|
||||||
~ |
|
|
||||||
[No Name] 0,0-1 All|
|
|
||||||
1 |
|
|
||||||
-- TERMINAL -- |
|
|
||||||
]])
|
|
||||||
|
|
||||||
clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } }
|
local screen = Screen.new(50, 8)
|
||||||
-- The .exrc file is now trusted.
|
screen:attach()
|
||||||
eq(1, eval('g:from_exrc'))
|
funcs.termopen({nvim_prog})
|
||||||
end)
|
screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') })
|
||||||
|
-- `i` to enter Terminal mode, `a` to allow
|
||||||
|
feed('ia')
|
||||||
|
screen:expect([[
|
||||||
|
|
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
[No Name] 0,0-1 All|
|
||||||
|
|
|
||||||
|
-- TERMINAL -- |
|
||||||
|
]])
|
||||||
|
feed(':echo g:exrc_file<CR>')
|
||||||
|
screen:expect(string.format([[
|
||||||
|
|
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
[No Name] 0,0-1 All|
|
||||||
|
%s%s|
|
||||||
|
-- TERMINAL -- |
|
||||||
|
]], filename, string.rep(' ', 50 - #filename)))
|
||||||
|
|
||||||
|
clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } }
|
||||||
|
-- The 'exrc' file is now trusted.
|
||||||
|
eq(filename, eval('g:exrc_file'))
|
||||||
|
end)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('with explicitly provided config', function()
|
describe('with explicitly provided config', function()
|
||||||
|
Reference in New Issue
Block a user