mirror of
https://github.com/neovim/neovim.git
synced 2025-11-10 04:25:22 +00:00
refactor(tests): Simplify tests at functional/lua/runtime_spec
This commit is contained in:
@@ -11,6 +11,7 @@ local exec_lua = helpers.exec_lua
|
|||||||
local feed = helpers.feed
|
local feed = helpers.feed
|
||||||
local funcs = helpers.funcs
|
local funcs = helpers.funcs
|
||||||
local mkdir = helpers.mkdir
|
local mkdir = helpers.mkdir
|
||||||
|
local mkdir_p = helpers.mkdir_p
|
||||||
local nvim_prog = helpers.nvim_prog
|
local nvim_prog = helpers.nvim_prog
|
||||||
local nvim_set = helpers.nvim_set
|
local nvim_set = helpers.nvim_set
|
||||||
local read_file = helpers.read_file
|
local read_file = helpers.read_file
|
||||||
@@ -494,6 +495,62 @@ describe('user config init', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('runtime:', function()
|
||||||
|
local xhome = 'Xhome'
|
||||||
|
local pathsep = helpers.get_pathsep()
|
||||||
|
local xconfig = xhome .. pathsep .. 'Xconfig'
|
||||||
|
|
||||||
|
setup(function()
|
||||||
|
mkdir_p(xconfig .. pathsep .. 'nvim')
|
||||||
|
end)
|
||||||
|
|
||||||
|
teardown(function()
|
||||||
|
rmdir(xhome)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('loads plugin/*.lua from XDG config home', function()
|
||||||
|
local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep)
|
||||||
|
local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep)
|
||||||
|
mkdir_p(plugin_folder_path)
|
||||||
|
write_file(plugin_file_path, [[ vim.g.lua_plugin = 1 ]])
|
||||||
|
|
||||||
|
clear{ args_rm={'-u'}, env={ XDG_CONFIG_HOME=xconfig }}
|
||||||
|
|
||||||
|
eq(1, eval('g:lua_plugin'))
|
||||||
|
rmdir(plugin_folder_path)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('loads plugin/*.lua from start plugins', function()
|
||||||
|
local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory',
|
||||||
|
'start', 'test_plugin'}, pathsep)
|
||||||
|
local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep)
|
||||||
|
local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'},
|
||||||
|
pathsep)
|
||||||
|
mkdir_p(plugin_folder_path)
|
||||||
|
write_file(plugin_file_path, [[vim.g.lua_plugin = 2]])
|
||||||
|
|
||||||
|
clear{ args_rm={'-u'}, env={ XDG_CONFIG_HOME=xconfig }}
|
||||||
|
|
||||||
|
eq(2, eval('g:lua_plugin'))
|
||||||
|
rmdir(plugin_path)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('loads ftdetect/*.lua', function()
|
||||||
|
local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep)
|
||||||
|
local ftdetect_file = table.concat({ftdetect_folder , 'new-ft.lua'}, pathsep)
|
||||||
|
mkdir_p(ftdetect_folder)
|
||||||
|
write_file(ftdetect_file , [[vim.g.lua_ftdetect = 1]])
|
||||||
|
|
||||||
|
-- TODO(shadmansaleh): Figure out why this test fails without
|
||||||
|
-- setting VIMRUNTIME
|
||||||
|
clear{ args_rm={'-u'}, env={XDG_CONFIG_HOME=xconfig,
|
||||||
|
VIMRUNTIME='runtime/'}}
|
||||||
|
|
||||||
|
eq(1, eval('g:lua_ftdetect'))
|
||||||
|
rmdir(ftdetect_folder)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe('user session', function()
|
describe('user session', function()
|
||||||
local xhome = 'Xhome'
|
local xhome = 'Xhome'
|
||||||
local pathsep = helpers.get_pathsep()
|
local pathsep = helpers.get_pathsep()
|
||||||
|
|||||||
@@ -9,61 +9,36 @@ local rmdir = helpers.rmdir
|
|||||||
local write_file = helpers.write_file
|
local write_file = helpers.write_file
|
||||||
|
|
||||||
describe('runtime:', function()
|
describe('runtime:', function()
|
||||||
local xhome = 'Xhome'
|
local plug_dir = 'Test_Plugin'
|
||||||
local pathsep = helpers.get_pathsep()
|
local sep = helpers.get_pathsep()
|
||||||
local xconfig = xhome .. pathsep .. 'Xconfig'
|
local init = 'dummy_init.lua'
|
||||||
|
|
||||||
|
setup(function()
|
||||||
|
io.open(init, 'w'):close() -- touch init file
|
||||||
|
clear{args = {'-u', init}}
|
||||||
|
exec('set rtp+=' .. plug_dir)
|
||||||
|
end)
|
||||||
|
|
||||||
|
teardown(function()
|
||||||
|
os.remove(init)
|
||||||
|
end)
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
clear()
|
mkdir_p(plug_dir)
|
||||||
mkdir_p(xconfig .. pathsep .. 'nvim')
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
after_each(function()
|
after_each(function()
|
||||||
rmdir(xhome)
|
rmdir(plug_dir)
|
||||||
end)
|
|
||||||
|
|
||||||
describe('plugin', function()
|
|
||||||
before_each(clear)
|
|
||||||
it('loads plugin/*.lua from XDG config home', function()
|
|
||||||
local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep)
|
|
||||||
local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep)
|
|
||||||
mkdir_p(plugin_folder_path)
|
|
||||||
write_file(plugin_file_path, [[ vim.g.lua_plugin = 1 ]])
|
|
||||||
|
|
||||||
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}
|
|
||||||
|
|
||||||
eq(1, eval('g:lua_plugin'))
|
|
||||||
rmdir(plugin_folder_path)
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
it('loads plugin/*.lua from start plugins', function()
|
|
||||||
local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory',
|
|
||||||
'start', 'test_plugin'}, pathsep)
|
|
||||||
local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep)
|
|
||||||
local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'},
|
|
||||||
pathsep)
|
|
||||||
mkdir_p(plugin_folder_path)
|
|
||||||
write_file(plugin_file_path, [[vim.g.lua_plugin = 2]])
|
|
||||||
|
|
||||||
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}
|
|
||||||
|
|
||||||
eq(2, eval('g:lua_plugin'))
|
|
||||||
rmdir(plugin_path)
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('colors', function()
|
describe('colors', function()
|
||||||
before_each(clear)
|
local colorscheme_folder = plug_dir .. sep .. 'colors'
|
||||||
|
|
||||||
it('loads lua colorscheme', function()
|
it('loads lua colorscheme', function()
|
||||||
local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'},
|
local colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme.lua'
|
||||||
pathsep)
|
|
||||||
local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme.lua'},
|
|
||||||
pathsep)
|
|
||||||
mkdir_p(colorscheme_folder)
|
mkdir_p(colorscheme_folder)
|
||||||
write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]])
|
write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]])
|
||||||
|
|
||||||
clear{ args_rm={'-' }, env={ XDG_CONFIG_HOME=xconfig }}
|
|
||||||
exec('colorscheme new_colorscheme')
|
exec('colorscheme new_colorscheme')
|
||||||
|
|
||||||
eq(1, eval('g:lua_colorscheme'))
|
eq(1, eval('g:lua_colorscheme'))
|
||||||
@@ -71,15 +46,11 @@ describe('runtime:', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('loads vim colorscheme when both lua and vim version exist', function()
|
it('loads vim colorscheme when both lua and vim version exist', function()
|
||||||
local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'},
|
local colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme'
|
||||||
pathsep)
|
|
||||||
local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme'},
|
|
||||||
pathsep)
|
|
||||||
mkdir_p(colorscheme_folder)
|
mkdir_p(colorscheme_folder)
|
||||||
write_file(colorscheme_file..'.vim', [[let g:colorscheme = 'vim']])
|
write_file(colorscheme_file..'.vim', [[let g:colorscheme = 'vim']])
|
||||||
write_file(colorscheme_file..'.lua', [[vim.g.colorscheme = 'lua']])
|
write_file(colorscheme_file..'.lua', [[vim.g.colorscheme = 'lua']])
|
||||||
|
|
||||||
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}
|
|
||||||
exec('colorscheme new_colorscheme')
|
exec('colorscheme new_colorscheme')
|
||||||
|
|
||||||
eq('vim', eval('g:colorscheme'))
|
eq('vim', eval('g:colorscheme'))
|
||||||
@@ -88,16 +59,13 @@ describe('runtime:', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
describe('compiler', function()
|
describe('compiler', function()
|
||||||
local compiler_folder = table.concat({xconfig, 'nvim', 'compiler'}, pathsep)
|
local compiler_folder = plug_dir .. sep .. 'compiler'
|
||||||
before_each(clear)
|
|
||||||
|
|
||||||
it('loads lua compilers', function()
|
it('loads lua compilers', function()
|
||||||
local compiler_file = table.concat({compiler_folder, 'new_compiler.lua'},
|
local compiler_file = compiler_folder .. sep .. 'new_compiler.lua'
|
||||||
pathsep)
|
|
||||||
mkdir_p(compiler_folder)
|
mkdir_p(compiler_folder)
|
||||||
write_file(compiler_file, [[vim.g.lua_compiler = 1]])
|
write_file(compiler_file, [[vim.g.lua_compiler = 1]])
|
||||||
|
|
||||||
clear{ args_rm={'-' }, env={ XDG_CONFIG_HOME=xconfig }}
|
|
||||||
exec('compiler new_compiler')
|
exec('compiler new_compiler')
|
||||||
|
|
||||||
eq(1, eval('g:lua_compiler'))
|
eq(1, eval('g:lua_compiler'))
|
||||||
@@ -105,13 +73,11 @@ describe('runtime:', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('loads vim compilers when both lua and vim version exist', function()
|
it('loads vim compilers when both lua and vim version exist', function()
|
||||||
local compiler_file = table.concat({compiler_folder, 'new_compiler'},
|
local compiler_file = compiler_folder .. sep .. 'new_compiler'
|
||||||
pathsep)
|
|
||||||
mkdir_p(compiler_folder)
|
mkdir_p(compiler_folder)
|
||||||
write_file(compiler_file..'.vim', [[let g:compiler = 'vim']])
|
write_file(compiler_file..'.vim', [[let g:compiler = 'vim']])
|
||||||
write_file(compiler_file..'.lua', [[vim.g.compiler = 'lua']])
|
write_file(compiler_file..'.lua', [[vim.g.compiler = 'lua']])
|
||||||
|
|
||||||
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}
|
|
||||||
exec('compiler new_compiler')
|
exec('compiler new_compiler')
|
||||||
|
|
||||||
eq('vim', eval('g:compiler'))
|
eq('vim', eval('g:compiler'))
|
||||||
@@ -120,17 +86,13 @@ describe('runtime:', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
describe('ftplugin', function()
|
describe('ftplugin', function()
|
||||||
local ftplugin_folder = table.concat({xconfig, 'nvim', 'ftplugin'}, pathsep)
|
local ftplugin_folder = table.concat({plug_dir, 'ftplugin'}, sep)
|
||||||
|
|
||||||
before_each(clear)
|
|
||||||
|
|
||||||
it('loads lua ftplugins', function()
|
it('loads lua ftplugins', function()
|
||||||
local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, pathsep)
|
local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, sep)
|
||||||
mkdir_p(ftplugin_folder)
|
mkdir_p(ftplugin_folder)
|
||||||
write_file(ftplugin_file , [[vim.g.lua_ftplugin = 1]])
|
write_file(ftplugin_file , [[vim.g.lua_ftplugin = 1]])
|
||||||
|
|
||||||
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}
|
|
||||||
|
|
||||||
exec [[set filetype=new-ft]]
|
exec [[set filetype=new-ft]]
|
||||||
eq(1, eval('g:lua_ftplugin'))
|
eq(1, eval('g:lua_ftplugin'))
|
||||||
rmdir(ftplugin_folder)
|
rmdir(ftplugin_folder)
|
||||||
@@ -138,64 +100,37 @@ describe('runtime:', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
describe('indent', function()
|
describe('indent', function()
|
||||||
local indent_folder = table.concat({xconfig, 'nvim', 'indent'}, pathsep)
|
local indent_folder = table.concat({plug_dir, 'indent'}, sep)
|
||||||
|
|
||||||
before_each(clear)
|
|
||||||
|
|
||||||
it('loads lua indents', function()
|
it('loads lua indents', function()
|
||||||
local indent_file = table.concat({indent_folder , 'new-ft.lua'}, pathsep)
|
local indent_file = table.concat({indent_folder , 'new-ft.lua'}, sep)
|
||||||
mkdir_p(indent_folder)
|
mkdir_p(indent_folder)
|
||||||
write_file(indent_file , [[vim.g.lua_indent = 1]])
|
write_file(indent_file , [[vim.g.lua_indent = 1]])
|
||||||
|
|
||||||
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}
|
|
||||||
|
|
||||||
exec [[set filetype=new-ft]]
|
exec [[set filetype=new-ft]]
|
||||||
eq(1, eval('g:lua_indent'))
|
eq(1, eval('g:lua_indent'))
|
||||||
rmdir(indent_folder)
|
rmdir(indent_folder)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('ftdetect', function()
|
|
||||||
local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep)
|
|
||||||
|
|
||||||
before_each(clear)
|
|
||||||
|
|
||||||
it('loads lua ftdetects', function()
|
|
||||||
local ftdetect_file = table.concat({ftdetect_folder , 'new-ft.lua'}, pathsep)
|
|
||||||
mkdir_p(ftdetect_folder)
|
|
||||||
write_file(ftdetect_file , [[vim.g.lua_ftdetect = 1]])
|
|
||||||
|
|
||||||
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}
|
|
||||||
|
|
||||||
eq(1, eval('g:lua_ftdetect'))
|
|
||||||
rmdir(ftdetect_folder)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
describe('syntax', function()
|
describe('syntax', function()
|
||||||
local syntax_folder = table.concat({xconfig, 'nvim', 'syntax'}, pathsep)
|
local syntax_folder = table.concat({plug_dir, 'syntax'}, sep)
|
||||||
|
|
||||||
before_each(clear)
|
|
||||||
|
|
||||||
it('loads lua syntaxes on filetype change', function()
|
it('loads lua syntaxes on filetype change', function()
|
||||||
local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, pathsep)
|
local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, sep)
|
||||||
mkdir_p(syntax_folder)
|
mkdir_p(syntax_folder)
|
||||||
write_file(syntax_file , [[vim.g.lua_syntax = 1]])
|
write_file(syntax_file , [[vim.g.lua_syntax = 1]])
|
||||||
|
|
||||||
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}
|
|
||||||
|
|
||||||
exec('set filetype=my-lang')
|
exec('set filetype=my-lang')
|
||||||
eq(1, eval('g:lua_syntax'))
|
eq(1, eval('g:lua_syntax'))
|
||||||
rmdir(syntax_folder)
|
rmdir(syntax_folder)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('loads lua syntaxes on syntax change', function()
|
it('loads lua syntaxes on syntax change', function()
|
||||||
local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, pathsep)
|
local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, sep)
|
||||||
mkdir_p(syntax_folder)
|
mkdir_p(syntax_folder)
|
||||||
write_file(syntax_file , [[vim.g.lua_syntax = 5]])
|
write_file(syntax_file , [[vim.g.lua_syntax = 5]])
|
||||||
|
|
||||||
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}
|
|
||||||
|
|
||||||
exec('set syntax=my-lang')
|
exec('set syntax=my-lang')
|
||||||
eq(5, eval('g:lua_syntax'))
|
eq(5, eval('g:lua_syntax'))
|
||||||
rmdir(syntax_folder)
|
rmdir(syntax_folder)
|
||||||
|
|||||||
Reference in New Issue
Block a user