diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/core/startup_spec.lua | 85 | ||||
-rw-r--r-- | test/unit/path_spec.lua | 17 |
2 files changed, 102 insertions, 0 deletions
diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 27793ab936..ff0fdbea45 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -432,3 +432,88 @@ describe('clean', function() clear('--clean') ok(string.match(meths.get_option('runtimepath'), funcs.stdpath('config')) == nil) end) + +describe('user config init', function() + local xhome = 'Xhome' + local pathsep = helpers.get_pathsep() + local xconfig = xhome .. pathsep .. 'Xconfig' + local init_lua_path = table.concat({xconfig, 'nvim', 'init.lua'}, pathsep) + + before_each(function() + rmdir(xhome) + + -- TODO, make mkdir_p helper + mkdir(xhome) + mkdir(xconfig) + mkdir(xconfig .. pathsep .. 'nvim') + + write_file(init_lua_path, [[ + vim.g.lua_rc = 1 + ]]) + end) + + after_each(function() + rmdir(xhome) + end) + + it('loads init.lua from XDG config home by default', function() + clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }} + + eq(1, eval('g:lua_rc')) + eq(init_lua_path, eval('$MYVIMRC')) + end) + + describe 'with explicitly provided config'(function() + local custom_lua_path = table.concat({xhome, 'custom.lua'}, pathsep) + before_each(function() + write_file(custom_lua_path, [[ + vim.g.custom_lua_rc = 1 + ]]) + end) + + it('loads custom lua config and does not set $MYVIMRC', function() + clear{ args={'-u', custom_lua_path }, env={ XDG_CONFIG_HOME=xconfig }} + eq(1, eval('g:custom_lua_rc')) + eq('', eval('$MYVIMRC')) + end) + end) + + describe 'VIMRC also exists'(function() + before_each(function() + write_file(table.concat({xconfig, 'nvim', 'init.vim'}, pathsep), [[ + let g:vim_rc = 1 + ]]) + end) + + it('loads default lua config, but shows an error', function() + clear{ args_rm={'-u'}, env={ XDG_CONFIG_HOME=xconfig }} + feed('<cr>') -- TODO check this, test execution is blocked without it + eq(1, eval('g:lua_rc')) + matches('Conflicting configs', meths.exec('messages', true)) + end) + end) +end) + +describe('user session', function() + local xhome = 'Xhome' + local pathsep = helpers.get_pathsep() + local session_file = table.concat({xhome, 'session.lua'}, pathsep) + + before_each(function() + rmdir(xhome) + + mkdir(xhome) + write_file(session_file, [[ + vim.g.lua_session = 1 + ]]) + end) + + after_each(function() + rmdir(xhome) + end) + + it('loads session from the provided lua file', function() + clear{ args={'-S', session_file }, env={ HOME=xhome }} + eq(1, eval('g:lua_session')) + end) +end) diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index 356c4997fa..41954de9be 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -603,4 +603,21 @@ describe('path.c', function() eq(FAIL, path_is_absolute('not/in/my/home~/directory')) end) end) + + describe('path_with_extension', function() + local function path_with_extension(filename, extension) + local c_filename = to_cstr(filename) + local c_extension = to_cstr(extension) + return cimp.path_with_extension(c_filename, c_extension) + end + + itp('returns true if filename includes a provided extension', function() + eq(true, path_with_extension('/some/path/file.lua', 'lua')) + end) + + itp('returns false if filename does not include a provided extension', function() + eq(false, path_with_extension('/some/path/file.vim', 'lua')) + eq(false, path_with_extension('/some/path/file', 'lua')) + end) + end) end) |