diff options
author | Munif Tanjim <hello@muniftanjim.dev> | 2022-12-20 06:38:24 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-20 08:38:24 +0800 |
commit | 03166838abf23e3c2de55333fb2b9b0af34a2c56 (patch) | |
tree | 54b21c593be70235269e067242fc021e6d46a2a9 | |
parent | b3c9563e6b7f217e4cc6c0e426af867d42b683cc (diff) | |
download | rneovim-03166838abf23e3c2de55333fb2b9b0af34a2c56.tar.gz rneovim-03166838abf23e3c2de55333fb2b9b0af34a2c56.tar.bz2 rneovim-03166838abf23e3c2de55333fb2b9b0af34a2c56.zip |
test(exrc): add tests for .nvimrc and .nvim.lua (#21478)
-rw-r--r-- | test/functional/core/startup_spec.lua | 97 |
1 files changed, 56 insertions, 41 deletions
diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 41596f5416..7664401824 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -581,15 +581,26 @@ describe('user config init', function() local exrc_path = '.exrc' 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() write_file(init_lua_path, [[ 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')) - write_file(exrc_path, [[ - let g:from_exrc = 1 - ]]) end) after_each(function() @@ -597,43 +608,47 @@ describe('user config init', function() rmdir(xstate) end) - it('loads .exrc #13501', function() - 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. - eq(0, eval('g:from_exrc')) - - local screen = Screen.new(50, 8) - screen:attach() - funcs.termopen({nvim_prog}) - 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 } } - -- The .exrc file is now trusted. - eq(1, eval('g:from_exrc')) - end) + 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 } } + -- The 'exrc' file is not trusted, and the prompt is skipped because there is no UI. + eq('---', eval('g:exrc_file')) + + local screen = Screen.new(50, 8) + screen:attach() + funcs.termopen({nvim_prog}) + 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) describe('with explicitly provided config', function() |