mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
test: cleanup ftplugin_spec.lua #32948
Problem: - cannot run ftplugin_spec.lua by itself - test leaves foo/ dir Solution: - fix setup and teardown
This commit is contained in:
@@ -3,18 +3,12 @@ local M = {}
|
||||
--- @param module string
|
||||
---@return string
|
||||
function M.includeexpr(module)
|
||||
---@param fname string
|
||||
---@return boolean
|
||||
local function filereadable(fname)
|
||||
return vim.fn.filereadable(fname) == 1
|
||||
end
|
||||
|
||||
local fname = module:gsub('%.', '/')
|
||||
|
||||
local root = vim.fs.root(vim.api.nvim_buf_get_name(0), 'lua') or vim.fn.getcwd()
|
||||
for _, suf in ipairs { '.lua', '/init.lua' } do
|
||||
local path = vim.fs.joinpath(root, 'lua', fname .. suf)
|
||||
if filereadable(path) then
|
||||
if vim.uv.fs_stat(path) then
|
||||
return path
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
-- Tests for filetype-plugin behavior (files in runtime/ftplugin/*).
|
||||
|
||||
local t = require('test.testutil')
|
||||
local n = require('test.functional.testnvim')()
|
||||
|
||||
@@ -8,7 +10,7 @@ local eq = t.eq
|
||||
---@param type string
|
||||
---@return string
|
||||
local function stdpath(type)
|
||||
return exec_lua(([[return vim.fs.normalize(vim.fn.stdpath("%s"))]]):format(type))
|
||||
return exec_lua([[return vim.fs.normalize(vim.fn.stdpath(...))]], type)
|
||||
end
|
||||
|
||||
---@return string
|
||||
@@ -19,14 +21,24 @@ end
|
||||
---@param module string
|
||||
---@return string
|
||||
local function lua_includeexpr(module)
|
||||
return exec_lua(([[return require('vim._ftplugin.lua').includeexpr("%s")]]):format(module))
|
||||
return exec_lua([[return require('vim._ftplugin.lua').includeexpr(...)]], module)
|
||||
end
|
||||
|
||||
local root = exec_lua [[ return vim.fs.normalize(vim.fn.getcwd()) ]]
|
||||
describe("ftplugin: Lua 'includeexpr'", function()
|
||||
local repo_root = ''
|
||||
local temp_dir = ''
|
||||
|
||||
setup(function()
|
||||
repo_root = vim.fs.normalize(assert(vim.uv.cwd()))
|
||||
temp_dir = t.tmpname(false)
|
||||
n.clear()
|
||||
end)
|
||||
|
||||
teardown(function()
|
||||
n.expect_exit(n.command, 'qall!')
|
||||
n.rmdir('runtime/lua/foo/')
|
||||
end)
|
||||
|
||||
describe("Lua 'includeexpr'", function()
|
||||
setup(n.clear)
|
||||
local temp_dir = t.tmpname(false)
|
||||
before_each(function()
|
||||
command(([[
|
||||
edit `=stdpath('config') .. '/lua/user-foo/init.lua'`
|
||||
@@ -52,13 +64,13 @@ describe("Lua 'includeexpr'", function()
|
||||
|
||||
it('finds module in current repo', function()
|
||||
command [[ edit runtime/lua/vim/_ftplugin/lua.lua ]]
|
||||
eq(root .. '/runtime/lua/vim/_ftplugin/lua.lua', lua_includeexpr('vim._ftplugin.lua'))
|
||||
eq(root .. '/runtime/lua/editorconfig.lua', lua_includeexpr('editorconfig'))
|
||||
eq(root .. '/runtime/lua/foo/init.lua', lua_includeexpr('foo'))
|
||||
eq(root .. '/runtime/lua/foo/bar/init.lua', lua_includeexpr('foo.bar'))
|
||||
eq(repo_root .. '/runtime/lua/vim/_ftplugin/lua.lua', lua_includeexpr('vim._ftplugin.lua'))
|
||||
eq(repo_root .. '/runtime/lua/editorconfig.lua', lua_includeexpr('editorconfig'))
|
||||
eq(repo_root .. '/runtime/lua/foo/init.lua', lua_includeexpr('foo'))
|
||||
eq(repo_root .. '/runtime/lua/foo/bar/init.lua', lua_includeexpr('foo.bar'))
|
||||
end)
|
||||
|
||||
it('find module in packpath/start', function()
|
||||
it('finds module in packpath/start', function()
|
||||
eq(
|
||||
stdpath('data') .. '/site/pack/packer/start/plugin-foo/lua/plugin-foo/init.lua',
|
||||
lua_includeexpr('plugin-foo')
|
||||
@@ -70,12 +82,12 @@ describe("Lua 'includeexpr'", function()
|
||||
end)
|
||||
|
||||
it('finds module in $VIMRUNTIME', function()
|
||||
command('edit ' .. root)
|
||||
command('edit ' .. repo_root)
|
||||
eq(vimruntime() .. '/lua/vim/_ftplugin/lua.lua', lua_includeexpr('vim._ftplugin.lua'))
|
||||
eq(vimruntime() .. '/lua/editorconfig.lua', lua_includeexpr('editorconfig'))
|
||||
end)
|
||||
|
||||
it('find module in runtimepath', function()
|
||||
it('finds module in runtimepath', function()
|
||||
eq(stdpath('config') .. '/lua/user-foo/init.lua', lua_includeexpr('user-foo'))
|
||||
eq(stdpath('config') .. '/lua/user-foo/bar.lua', lua_includeexpr('user-foo.bar'))
|
||||
command('set rtp+=' .. temp_dir)
|
||||
|
||||
Reference in New Issue
Block a user