mirror of
https://github.com/nix-community/nixvim.git
synced 2025-08-28 13:58:41 +02:00
tests/performance: disable test
Invalid generated rockspec. Error: /build/init.lua/lib1-0.0.1-1.rockspec: Unknown field build_dependencies (using rockspec format 1.0)
This commit is contained in:
parent
b4571a064f
commit
90671c8a90
3 changed files with 600 additions and 592 deletions
|
@ -86,256 +86,236 @@ let
|
||||||
"numpy"
|
"numpy"
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
{
|
# TODO: 2025-07-25 luajit2.1-lib[1-5]-0.0.1 failing to build
|
||||||
default =
|
# Error: /build/init.lua/lib1-0.0.1-1.rockspec: Unknown field build_dependencies (using rockspec format 1.0)
|
||||||
{
|
lib.optionalAttrs false (
|
||||||
config,
|
{
|
||||||
lib,
|
default =
|
||||||
pkgs,
|
{
|
||||||
...
|
config,
|
||||||
}:
|
lib,
|
||||||
let
|
pkgs,
|
||||||
writeLua = lib.nixvim.builders.writeLuaWith pkgs;
|
...
|
||||||
in
|
}:
|
||||||
{
|
let
|
||||||
performance.byteCompileLua.enable = true;
|
writeLua = lib.nixvim.builders.writeLuaWith pkgs;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
performance.byteCompileLua.enable = true;
|
||||||
|
|
||||||
extraFiles = {
|
extraFiles = {
|
||||||
# By text
|
# By text
|
||||||
"plugin/extra_file_text.lua".text = "vim.g.extra_file_text = true";
|
"plugin/extra_file_text.lua".text = "vim.g.extra_file_text = true";
|
||||||
# By simple source derivation using buildCommand
|
# By simple source derivation using buildCommand
|
||||||
"plugin/extra_file_source.lua".source =
|
"plugin/extra_file_source.lua".source =
|
||||||
writeLua "extra_file_source.lua" "vim.g.extra_file_source = true";
|
writeLua "extra_file_source.lua" "vim.g.extra_file_source = true";
|
||||||
# By standard derivation, it needs to execute fixupPhase
|
# By standard derivation, it needs to execute fixupPhase
|
||||||
"plugin/extra_file_drv.lua".source = pkgs.stdenvNoCC.mkDerivation {
|
"plugin/extra_file_drv.lua".source = pkgs.stdenvNoCC.mkDerivation {
|
||||||
name = "extra_file_drv.lua";
|
name = "extra_file_drv.lua";
|
||||||
src = pkgs.emptyDirectory;
|
src = pkgs.emptyDirectory;
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
echo "vim.g.extra_file_drv = true" > $out
|
echo "vim.g.extra_file_drv = true" > $out
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
# By path
|
||||||
|
"plugin/extra_file_path.lua".source = ./files/file.lua;
|
||||||
|
# By string
|
||||||
|
"plugin/extra_file_string.lua".source =
|
||||||
|
builtins.toFile "extra_file_path.lua" "vim.g.extra_file_string = true";
|
||||||
|
# By derivation converted to string
|
||||||
|
"plugin/extra_file_drv_string.lua".source = toString (
|
||||||
|
writeLua "extra_file_drv_string.lua" "vim.g.extra_file_drv_string = true"
|
||||||
|
);
|
||||||
|
# Non-lua file
|
||||||
|
"plugin/extra_file_non_lua.vim".text = "let g:extra_file_non_lua = 1";
|
||||||
|
# Lua file with txt extension won't be byte compiled
|
||||||
|
"text.txt".source = writeLua "text.txt" "vim.g.text = true";
|
||||||
|
};
|
||||||
|
|
||||||
|
files = {
|
||||||
|
"plugin/file.lua" = {
|
||||||
|
globals.file_lua = true;
|
||||||
|
};
|
||||||
|
"plugin/file.vim" = {
|
||||||
|
globals.file_vimscript = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
extraPlugins = shortPluginList;
|
||||||
|
|
||||||
|
extraLuaPackages = _: shortLuaList;
|
||||||
|
|
||||||
|
extraConfigLua = ''
|
||||||
|
-- The test will search for the next string in nixvim-print-init's output: VALIDATING_STRING.
|
||||||
|
-- Since this is the comment, it won't appear in byte compiled file.
|
||||||
|
|
||||||
|
vim.g.init_lua = true
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Using plugin for the test code to avoid infinite recursion
|
||||||
|
extraFiles."plugin/test.lua".text =
|
||||||
|
# lua
|
||||||
|
''
|
||||||
|
${isByteCompiledFun}
|
||||||
|
|
||||||
|
${shortChecks}
|
||||||
|
|
||||||
|
-- vimrc is byte compiled
|
||||||
|
local init = vim.env.MYVIMRC or vim.fn.getscriptinfo({name = "init.lua"})[1].name
|
||||||
|
assert(is_byte_compiled(init), "MYVIMRC is expected to be byte compiled, but it's not")
|
||||||
|
assert_g_var("init_lua", "MYVIMRC")
|
||||||
|
|
||||||
|
-- nixvim-print-init prints text
|
||||||
|
local init_content = vim.fn.system("${lib.getExe config.build.printInitPackage}")
|
||||||
|
assert(init_content:find("VALIDATING_STRING"), "nixvim-print-init's output is byte compiled")
|
||||||
|
|
||||||
|
local runtime_lua_files = {
|
||||||
|
-- lua 'extraFiles' are byte compiled
|
||||||
|
{ "plugin/extra_file_text.lua", true, "extra_file_text" },
|
||||||
|
{ "plugin/extra_file_source.lua", true, "extra_file_source" },
|
||||||
|
{ "plugin/extra_file_drv.lua", true, "extra_file_drv" },
|
||||||
|
{ "plugin/extra_file_path.lua", true, "extra_file_path" },
|
||||||
|
{ "plugin/extra_file_string.lua", true, "extra_file_string" },
|
||||||
|
{ "plugin/extra_file_drv_string.lua", true, "extra_file_drv_string" },
|
||||||
|
-- other 'extraFiles'
|
||||||
|
{ "plugin/extra_file_non_lua.vim", false, "extra_file_non_lua" },
|
||||||
|
-- lua 'files' are byte compiled
|
||||||
|
{ "plugin/file.lua", true, "file_lua" },
|
||||||
|
-- other 'files'
|
||||||
|
{ "plugin/file.vim", false, "file_vimscript" },
|
||||||
|
}
|
||||||
|
for _, test in ipairs(runtime_lua_files) do
|
||||||
|
local file, expected_byte_compiled, varname = unpack(test)
|
||||||
|
test_rtp_file(file, expected_byte_compiled)
|
||||||
|
-- Runtime plugin scripts are loaded last, so activate each manually before a test
|
||||||
|
vim.cmd.runtime(file)
|
||||||
|
assert_g_var(varname, file)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Nvim runtime isn't byte compiled by default
|
||||||
|
test_rtp_file("lua/vim/lsp.lua", false)
|
||||||
|
|
||||||
|
-- Plugins aren't byte-compiled by default
|
||||||
|
${lib.concatMapStrings (name: ''
|
||||||
|
test_rtp_file("lua/${name}/init.lua", false)
|
||||||
|
test_rtp_file("plugin/${name}.lua", false)
|
||||||
|
'') shortPluginNames}
|
||||||
|
|
||||||
|
-- Lua library isn't byte-compiled by default
|
||||||
|
${lib.concatMapStrings (name: ''
|
||||||
|
test_lualib_file(require("${name}").name, false)
|
||||||
|
'') shortLuaAllNames}
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
# By path
|
|
||||||
"plugin/extra_file_path.lua".source = ./files/file.lua;
|
|
||||||
# By string
|
|
||||||
"plugin/extra_file_string.lua".source =
|
|
||||||
builtins.toFile "extra_file_path.lua" "vim.g.extra_file_string = true";
|
|
||||||
# By derivation converted to string
|
|
||||||
"plugin/extra_file_drv_string.lua".source = toString (
|
|
||||||
writeLua "extra_file_drv_string.lua" "vim.g.extra_file_drv_string = true"
|
|
||||||
);
|
|
||||||
# Non-lua file
|
|
||||||
"plugin/extra_file_non_lua.vim".text = "let g:extra_file_non_lua = 1";
|
|
||||||
# Lua file with txt extension won't be byte compiled
|
|
||||||
"text.txt".source = writeLua "text.txt" "vim.g.text = true";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
files = {
|
disabled = {
|
||||||
"plugin/file.lua" = {
|
performance.byteCompileLua.enable = false;
|
||||||
globals.file_lua = true;
|
|
||||||
};
|
extraFiles."plugin/test1.lua".text = "vim.opt.tabstop = 2";
|
||||||
"plugin/file.vim" = {
|
|
||||||
globals.file_vimscript = true;
|
files."plugin/test2.lua".opts.tabstop = 2;
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
extraPlugins = shortPluginList;
|
extraPlugins = shortPluginList;
|
||||||
|
|
||||||
extraLuaPackages = _: shortLuaList;
|
extraLuaPackages = _: shortLuaList;
|
||||||
|
|
||||||
extraConfigLua = ''
|
extraConfigLua = ''
|
||||||
-- The test will search for the next string in nixvim-print-init's output: VALIDATING_STRING.
|
${isByteCompiledFun}
|
||||||
-- Since this is the comment, it won't appear in byte compiled file.
|
|
||||||
|
|
||||||
vim.g.init_lua = true
|
-- Nothing is byte compiled
|
||||||
|
-- vimrc
|
||||||
|
local init = vim.env.MYVIMRC or vim.fn.getscriptinfo({name = "init.lua"})[1].name
|
||||||
|
assert(not is_byte_compiled(init), "MYVIMRC is not expected to be byte compiled, but it is")
|
||||||
|
-- extraFiles
|
||||||
|
test_rtp_file("plugin/test1.lua", false)
|
||||||
|
-- files
|
||||||
|
test_rtp_file("plugin/test2.lua", false)
|
||||||
|
-- Neovim runtime
|
||||||
|
test_rtp_file("lua/vim/lsp.lua", false)
|
||||||
|
-- plugins
|
||||||
|
test_rtp_file("lua/${builtins.elemAt shortPluginNames 0}/init.lua", false)
|
||||||
|
-- lua library
|
||||||
|
test_lualib_file(require("${builtins.elemAt shortLuaNames 0}").name, false)
|
||||||
|
test_lualib_file(require("${builtins.elemAt shortPluginLuaNames 0}").name, false)
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Using plugin for the test code to avoid infinite recursion
|
|
||||||
extraFiles."plugin/test.lua".text =
|
|
||||||
# lua
|
|
||||||
''
|
|
||||||
${isByteCompiledFun}
|
|
||||||
|
|
||||||
${shortChecks}
|
|
||||||
|
|
||||||
-- vimrc is byte compiled
|
|
||||||
local init = vim.env.MYVIMRC or vim.fn.getscriptinfo({name = "init.lua"})[1].name
|
|
||||||
assert(is_byte_compiled(init), "MYVIMRC is expected to be byte compiled, but it's not")
|
|
||||||
assert_g_var("init_lua", "MYVIMRC")
|
|
||||||
|
|
||||||
-- nixvim-print-init prints text
|
|
||||||
local init_content = vim.fn.system("${lib.getExe config.build.printInitPackage}")
|
|
||||||
assert(init_content:find("VALIDATING_STRING"), "nixvim-print-init's output is byte compiled")
|
|
||||||
|
|
||||||
local runtime_lua_files = {
|
|
||||||
-- lua 'extraFiles' are byte compiled
|
|
||||||
{ "plugin/extra_file_text.lua", true, "extra_file_text" },
|
|
||||||
{ "plugin/extra_file_source.lua", true, "extra_file_source" },
|
|
||||||
{ "plugin/extra_file_drv.lua", true, "extra_file_drv" },
|
|
||||||
{ "plugin/extra_file_path.lua", true, "extra_file_path" },
|
|
||||||
{ "plugin/extra_file_string.lua", true, "extra_file_string" },
|
|
||||||
{ "plugin/extra_file_drv_string.lua", true, "extra_file_drv_string" },
|
|
||||||
-- other 'extraFiles'
|
|
||||||
{ "plugin/extra_file_non_lua.vim", false, "extra_file_non_lua" },
|
|
||||||
-- lua 'files' are byte compiled
|
|
||||||
{ "plugin/file.lua", true, "file_lua" },
|
|
||||||
-- other 'files'
|
|
||||||
{ "plugin/file.vim", false, "file_vimscript" },
|
|
||||||
}
|
|
||||||
for _, test in ipairs(runtime_lua_files) do
|
|
||||||
local file, expected_byte_compiled, varname = unpack(test)
|
|
||||||
test_rtp_file(file, expected_byte_compiled)
|
|
||||||
-- Runtime plugin scripts are loaded last, so activate each manually before a test
|
|
||||||
vim.cmd.runtime(file)
|
|
||||||
assert_g_var(varname, file)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Nvim runtime isn't byte compiled by default
|
|
||||||
test_rtp_file("lua/vim/lsp.lua", false)
|
|
||||||
|
|
||||||
-- Plugins aren't byte-compiled by default
|
|
||||||
${lib.concatMapStrings (name: ''
|
|
||||||
test_rtp_file("lua/${name}/init.lua", false)
|
|
||||||
test_rtp_file("plugin/${name}.lua", false)
|
|
||||||
'') shortPluginNames}
|
|
||||||
|
|
||||||
-- Lua library isn't byte-compiled by default
|
|
||||||
${lib.concatMapStrings (name: ''
|
|
||||||
test_lualib_file(require("${name}").name, false)
|
|
||||||
'') shortLuaAllNames}
|
|
||||||
'';
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
disabled = {
|
init-lua-disabled = {
|
||||||
performance.byteCompileLua.enable = false;
|
performance.byteCompileLua = {
|
||||||
|
enable = true;
|
||||||
|
initLua = false;
|
||||||
|
};
|
||||||
|
|
||||||
extraFiles."plugin/test1.lua".text = "vim.opt.tabstop = 2";
|
extraConfigLuaPost = ''
|
||||||
|
${isByteCompiledFun}
|
||||||
|
|
||||||
files."plugin/test2.lua".opts.tabstop = 2;
|
-- vimrc is not byte compiled
|
||||||
|
local init = vim.env.MYVIMRC or vim.fn.getscriptinfo({name = "init.lua"})[1].name
|
||||||
extraPlugins = shortPluginList;
|
assert(not is_byte_compiled(init), "MYVIMRC is not expected to be byte compiled, but it is")
|
||||||
|
'';
|
||||||
extraLuaPackages = _: shortLuaList;
|
|
||||||
|
|
||||||
extraConfigLua = ''
|
|
||||||
${isByteCompiledFun}
|
|
||||||
|
|
||||||
-- Nothing is byte compiled
|
|
||||||
-- vimrc
|
|
||||||
local init = vim.env.MYVIMRC or vim.fn.getscriptinfo({name = "init.lua"})[1].name
|
|
||||||
assert(not is_byte_compiled(init), "MYVIMRC is not expected to be byte compiled, but it is")
|
|
||||||
-- extraFiles
|
|
||||||
test_rtp_file("plugin/test1.lua", false)
|
|
||||||
-- files
|
|
||||||
test_rtp_file("plugin/test2.lua", false)
|
|
||||||
-- Neovim runtime
|
|
||||||
test_rtp_file("lua/vim/lsp.lua", false)
|
|
||||||
-- plugins
|
|
||||||
test_rtp_file("lua/${builtins.elemAt shortPluginNames 0}/init.lua", false)
|
|
||||||
-- lua library
|
|
||||||
test_lualib_file(require("${builtins.elemAt shortLuaNames 0}").name, false)
|
|
||||||
test_lualib_file(require("${builtins.elemAt shortPluginLuaNames 0}").name, false)
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
init-lua-disabled = {
|
|
||||||
performance.byteCompileLua = {
|
|
||||||
enable = true;
|
|
||||||
initLua = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfigLuaPost = ''
|
configs-disabled = {
|
||||||
${isByteCompiledFun}
|
performance.byteCompileLua = {
|
||||||
|
enable = true;
|
||||||
|
configs = false;
|
||||||
|
};
|
||||||
|
|
||||||
-- vimrc is not byte compiled
|
extraFiles."plugin/test1.lua".text = "vim.opt.tabstop = 2";
|
||||||
local init = vim.env.MYVIMRC or vim.fn.getscriptinfo({name = "init.lua"})[1].name
|
|
||||||
assert(not is_byte_compiled(init), "MYVIMRC is not expected to be byte compiled, but it is")
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
configs-disabled = {
|
files."plugin/test2.lua".opts.tabstop = 2;
|
||||||
performance.byteCompileLua = {
|
|
||||||
enable = true;
|
extraConfigLuaPost = ''
|
||||||
configs = false;
|
${isByteCompiledFun}
|
||||||
|
|
||||||
|
-- extraFiles
|
||||||
|
test_rtp_file("plugin/test1.lua", false)
|
||||||
|
-- files
|
||||||
|
test_rtp_file("plugin/test2.lua", false)
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
extraFiles."plugin/test1.lua".text = "vim.opt.tabstop = 2";
|
nvim-runtime = {
|
||||||
|
performance.byteCompileLua = {
|
||||||
|
enable = true;
|
||||||
|
nvimRuntime = true;
|
||||||
|
};
|
||||||
|
|
||||||
files."plugin/test2.lua".opts.tabstop = 2;
|
extraPlugins = shortPluginList;
|
||||||
|
extraLuaPackages = _: shortLuaList;
|
||||||
|
|
||||||
extraConfigLuaPost = ''
|
extraConfigLuaPost = ''
|
||||||
${isByteCompiledFun}
|
${isByteCompiledFun}
|
||||||
|
|
||||||
-- extraFiles
|
${shortChecks}
|
||||||
test_rtp_file("plugin/test1.lua", false)
|
|
||||||
-- files
|
|
||||||
test_rtp_file("plugin/test2.lua", false)
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
nvim-runtime = {
|
-- vim namespace is working
|
||||||
performance.byteCompileLua = {
|
vim.opt.tabstop = 2
|
||||||
enable = true;
|
vim.api.nvim_get_runtime_file("init.lua", false)
|
||||||
nvimRuntime = true;
|
vim.lsp.get_clients()
|
||||||
|
vim.treesitter.language.get_filetypes("nix")
|
||||||
|
vim.iter({})
|
||||||
|
|
||||||
|
test_rtp_file("lua/vim/lsp.lua", true)
|
||||||
|
test_rtp_file("lua/vim/iter.lua", true)
|
||||||
|
test_rtp_file("lua/vim/treesitter/query.lua", true)
|
||||||
|
test_rtp_file("lua/vim/lsp/buf.lua", true)
|
||||||
|
test_rtp_file("plugin/editorconfig.lua", true)
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
extraPlugins = shortPluginList;
|
# performance.byteCompileLua.luaLib for extraLuaPackages
|
||||||
extraLuaPackages = _: shortLuaList;
|
lua-lib-extra-lua-packages = {
|
||||||
|
|
||||||
extraConfigLuaPost = ''
|
|
||||||
${isByteCompiledFun}
|
|
||||||
|
|
||||||
${shortChecks}
|
|
||||||
|
|
||||||
-- vim namespace is working
|
|
||||||
vim.opt.tabstop = 2
|
|
||||||
vim.api.nvim_get_runtime_file("init.lua", false)
|
|
||||||
vim.lsp.get_clients()
|
|
||||||
vim.treesitter.language.get_filetypes("nix")
|
|
||||||
vim.iter({})
|
|
||||||
|
|
||||||
test_rtp_file("lua/vim/lsp.lua", true)
|
|
||||||
test_rtp_file("lua/vim/iter.lua", true)
|
|
||||||
test_rtp_file("lua/vim/treesitter/query.lua", true)
|
|
||||||
test_rtp_file("lua/vim/lsp/buf.lua", true)
|
|
||||||
test_rtp_file("plugin/editorconfig.lua", true)
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
# performance.byteCompileLua.luaLib for extraLuaPackages
|
|
||||||
lua-lib-extra-lua-packages = {
|
|
||||||
performance.byteCompileLua = {
|
|
||||||
enable = true;
|
|
||||||
luaLib = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
extraLuaPackages = _: pluginStubs.libPack;
|
|
||||||
|
|
||||||
extraConfigLuaPost = ''
|
|
||||||
${pluginStubs.libChecks}
|
|
||||||
|
|
||||||
${isByteCompiledFun}
|
|
||||||
|
|
||||||
-- Lua modules are byte-compiled
|
|
||||||
${lib.concatMapStringsSep "\n" (
|
|
||||||
name: "test_lualib_file(require('${name}').name, true)"
|
|
||||||
) pluginStubs.libNames}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
# performance.byteCompileLua.luaLib for propagatedBuildInputs
|
|
||||||
lua-lib-propagated-build-inputs =
|
|
||||||
{ config, ... }:
|
|
||||||
{
|
|
||||||
performance.byteCompileLua = {
|
performance.byteCompileLua = {
|
||||||
enable = true;
|
enable = true;
|
||||||
luaLib = true;
|
luaLib = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
extraPlugins = pluginStubs.pluginPack;
|
extraLuaPackages = _: pluginStubs.libPack;
|
||||||
|
|
||||||
extraConfigLuaPost = ''
|
extraConfigLuaPost = ''
|
||||||
${pluginStubs.pluginChecks}
|
${pluginStubs.libChecks}
|
||||||
|
|
||||||
${isByteCompiledFun}
|
${isByteCompiledFun}
|
||||||
|
|
||||||
|
@ -343,96 +323,120 @@ in
|
||||||
${lib.concatMapStringsSep "\n" (
|
${lib.concatMapStringsSep "\n" (
|
||||||
name: "test_lualib_file(require('${name}').name, true)"
|
name: "test_lualib_file(require('${name}').name, true)"
|
||||||
) pluginStubs.libNames}
|
) pluginStubs.libNames}
|
||||||
|
|
||||||
-- Plugins themselves are not byte-compiled
|
|
||||||
${lib.concatMapStringsSep "\n" (
|
|
||||||
name: "test_rtp_file('lua/${name}/init.lua', false)"
|
|
||||||
) pluginStubs.pluginNames}
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
assertions =
|
|
||||||
let
|
|
||||||
# Get plugins with all dependencies
|
|
||||||
getDeps = drv: [ drv ] ++ builtins.concatMap getDeps drv.dependencies or [ ];
|
|
||||||
plugins = lib.pipe config.build.plugins [
|
|
||||||
(builtins.catAttrs "plugin")
|
|
||||||
(builtins.concatMap getDeps)
|
|
||||||
lib.unique
|
|
||||||
];
|
|
||||||
# Collect both propagatedBuildInputs and requiredLuaModules to one list
|
|
||||||
getAllRequiredLuaModules = lib.flip lib.pipe [
|
|
||||||
(
|
|
||||||
drvs: builtins.catAttrs "propagatedBuildInputs" drvs ++ builtins.catAttrs "requiredLuaModules" drvs
|
|
||||||
)
|
|
||||||
(builtins.concatMap (deps: deps ++ getAllRequiredLuaModules deps))
|
|
||||||
lib.unique
|
|
||||||
];
|
|
||||||
allRequiredLuaModules = getAllRequiredLuaModules plugins;
|
|
||||||
in
|
|
||||||
[
|
|
||||||
# Ensure that lua dependencies are byte-compiled recursively
|
|
||||||
# by checking that every library is present only once.
|
|
||||||
# If there are two different derivations with the same name,
|
|
||||||
# then one of them probably isn't byte-compiled.
|
|
||||||
{
|
|
||||||
assertion = lib.allUnique (map lib.getName allRequiredLuaModules);
|
|
||||||
message = ''
|
|
||||||
Expected propagatedBuildInputs and requiredLuaModules of all plugins to have unique names.
|
|
||||||
Got the following derivations:''\n${lib.concatLines allRequiredLuaModules}
|
|
||||||
Possible reasons:
|
|
||||||
- not all dependencies are overridden the same way
|
|
||||||
- requiredLuaModules are not updated along with propagatedBuildInputs
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
//
|
# performance.byteCompileLua.luaLib for propagatedBuildInputs
|
||||||
# Two equal tests, one with combinePlugins.enable = true
|
lua-lib-propagated-build-inputs =
|
||||||
lib.genAttrs
|
{ config, ... }:
|
||||||
[
|
{
|
||||||
"plugins"
|
performance.byteCompileLua = {
|
||||||
"plugins-combined"
|
|
||||||
]
|
|
||||||
(name: {
|
|
||||||
performance = {
|
|
||||||
byteCompileLua = {
|
|
||||||
enable = true;
|
enable = true;
|
||||||
plugins = true;
|
luaLib = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
combinePlugins.enable = lib.hasSuffix "combined" name;
|
extraPlugins = pluginStubs.pluginPack;
|
||||||
|
|
||||||
|
extraConfigLuaPost = ''
|
||||||
|
${pluginStubs.pluginChecks}
|
||||||
|
|
||||||
|
${isByteCompiledFun}
|
||||||
|
|
||||||
|
-- Lua modules are byte-compiled
|
||||||
|
${lib.concatMapStringsSep "\n" (
|
||||||
|
name: "test_lualib_file(require('${name}').name, true)"
|
||||||
|
) pluginStubs.libNames}
|
||||||
|
|
||||||
|
-- Plugins themselves are not byte-compiled
|
||||||
|
${lib.concatMapStringsSep "\n" (
|
||||||
|
name: "test_rtp_file('lua/${name}/init.lua', false)"
|
||||||
|
) pluginStubs.pluginNames}
|
||||||
|
'';
|
||||||
|
|
||||||
|
assertions =
|
||||||
|
let
|
||||||
|
# Get plugins with all dependencies
|
||||||
|
getDeps = drv: [ drv ] ++ builtins.concatMap getDeps drv.dependencies or [ ];
|
||||||
|
plugins = lib.pipe config.build.plugins [
|
||||||
|
(builtins.catAttrs "plugin")
|
||||||
|
(builtins.concatMap getDeps)
|
||||||
|
lib.unique
|
||||||
|
];
|
||||||
|
# Collect both propagatedBuildInputs and requiredLuaModules to one list
|
||||||
|
getAllRequiredLuaModules = lib.flip lib.pipe [
|
||||||
|
(
|
||||||
|
drvs: builtins.catAttrs "propagatedBuildInputs" drvs ++ builtins.catAttrs "requiredLuaModules" drvs
|
||||||
|
)
|
||||||
|
(builtins.concatMap (deps: deps ++ getAllRequiredLuaModules deps))
|
||||||
|
lib.unique
|
||||||
|
];
|
||||||
|
allRequiredLuaModules = getAllRequiredLuaModules plugins;
|
||||||
|
in
|
||||||
|
[
|
||||||
|
# Ensure that lua dependencies are byte-compiled recursively
|
||||||
|
# by checking that every library is present only once.
|
||||||
|
# If there are two different derivations with the same name,
|
||||||
|
# then one of them probably isn't byte-compiled.
|
||||||
|
{
|
||||||
|
assertion = lib.allUnique (map lib.getName allRequiredLuaModules);
|
||||||
|
message = ''
|
||||||
|
Expected propagatedBuildInputs and requiredLuaModules of all plugins to have unique names.
|
||||||
|
Got the following derivations:''\n${lib.concatLines allRequiredLuaModules}
|
||||||
|
Possible reasons:
|
||||||
|
- not all dependencies are overridden the same way
|
||||||
|
- requiredLuaModules are not updated along with propagatedBuildInputs
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
//
|
||||||
|
# Two equal tests, one with combinePlugins.enable = true
|
||||||
|
lib.genAttrs
|
||||||
|
[
|
||||||
|
"plugins"
|
||||||
|
"plugins-combined"
|
||||||
|
]
|
||||||
|
(name: {
|
||||||
|
performance = {
|
||||||
|
byteCompileLua = {
|
||||||
|
enable = true;
|
||||||
|
plugins = true;
|
||||||
|
};
|
||||||
|
|
||||||
extraPlugins = pluginStubs.pluginPack ++ [
|
combinePlugins.enable = lib.hasSuffix "combined" name;
|
||||||
# A plugin with invalid lua file
|
};
|
||||||
(pluginStubs.mkPlugin "invalid" {
|
|
||||||
postInstall = ''
|
|
||||||
mkdir $out/ftplugin
|
|
||||||
echo "if true then" >$out/ftplugin/invalid.lua
|
|
||||||
'';
|
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
||||||
extraConfigLuaPost = ''
|
extraPlugins = pluginStubs.pluginPack ++ [
|
||||||
${pluginStubs.pluginChecks}
|
# A plugin with invalid lua file
|
||||||
|
(pluginStubs.mkPlugin "invalid" {
|
||||||
|
postInstall = ''
|
||||||
|
mkdir $out/ftplugin
|
||||||
|
echo "if true then" >$out/ftplugin/invalid.lua
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
${isByteCompiledFun}
|
extraConfigLuaPost = ''
|
||||||
|
${pluginStubs.pluginChecks}
|
||||||
|
|
||||||
-- Plugins are byte-compiled
|
${isByteCompiledFun}
|
||||||
${lib.concatMapStrings (name: ''
|
|
||||||
test_rtp_file("lua/${name}/init.lua", true)
|
|
||||||
test_rtp_file("plugin/${name}.lua", true)
|
|
||||||
'') pluginStubs.pluginNames}
|
|
||||||
|
|
||||||
-- Lua modules aren't byte-compiled
|
-- Plugins are byte-compiled
|
||||||
${lib.concatMapStrings (name: ''
|
${lib.concatMapStrings (name: ''
|
||||||
test_lualib_file(require("${name}").name, false)
|
test_rtp_file("lua/${name}/init.lua", true)
|
||||||
'') pluginStubs.libNames}
|
test_rtp_file("plugin/${name}.lua", true)
|
||||||
|
'') pluginStubs.pluginNames}
|
||||||
|
|
||||||
-- A plugin with invalid file
|
-- Lua modules aren't byte-compiled
|
||||||
${pluginStubs.pluginChecksFor [ "invalid" ]}
|
${lib.concatMapStrings (name: ''
|
||||||
-- invalid file exists, but isn't byte compiled
|
test_lualib_file(require("${name}").name, false)
|
||||||
test_rtp_file("ftplugin/invalid.lua", false)
|
'') pluginStubs.libNames}
|
||||||
'';
|
|
||||||
})
|
-- A plugin with invalid file
|
||||||
|
${pluginStubs.pluginChecksFor [ "invalid" ]}
|
||||||
|
-- invalid file exists, but isn't byte compiled
|
||||||
|
test_rtp_file("ftplugin/invalid.lua", false)
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
|
@ -21,307 +21,311 @@ let
|
||||||
# Assertion that exactly one start plugin is defined in nvimPackage.packpathDirs
|
# Assertion that exactly one start plugin is defined in nvimPackage.packpathDirs
|
||||||
expectOneStartPlugin = config: expectNPlugins config "start" 1;
|
expectOneStartPlugin = config: expectNPlugins config "start" 1;
|
||||||
in
|
in
|
||||||
{
|
# TODO: 2025-07-25 luajit2.1-lib[1-5]-0.0.1 failing to build
|
||||||
# Test basic functionality
|
# Error: /build/init.lua/lib1-0.0.1-1.rockspec: Unknown field build_dependencies (using rockspec format 1.0)
|
||||||
default =
|
lib.optionalAttrs false (
|
||||||
{ config, ... }:
|
{
|
||||||
{
|
# Test basic functionality
|
||||||
performance.combinePlugins.enable = true;
|
default =
|
||||||
extraPlugins = pluginStubs.pluginPack;
|
{ config, ... }:
|
||||||
extraConfigLuaPost = ''
|
{
|
||||||
${pluginStubs.pluginChecks}
|
performance.combinePlugins.enable = true;
|
||||||
|
extraPlugins = pluginStubs.pluginPack;
|
||||||
|
extraConfigLuaPost = ''
|
||||||
|
${pluginStubs.pluginChecks}
|
||||||
|
|
||||||
-- No separate plugin entry in vim.api.nvim_list_runtime_paths()
|
-- No separate plugin entry in vim.api.nvim_list_runtime_paths()
|
||||||
${lib.concatMapStrings (
|
${lib.concatMapStrings (
|
||||||
name: # lua
|
|
||||||
''
|
|
||||||
assert(not vim.iter(vim.api.nvim_list_runtime_paths()):any(function(entry)
|
|
||||||
return entry:find("${name}", 1, true)
|
|
||||||
end), "plugin '${name}' found in runtime, expected to be combined")
|
|
||||||
'') pluginStubs.pluginNames}
|
|
||||||
'';
|
|
||||||
assertions = [
|
|
||||||
(expectOneStartPlugin config)
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
# Test disabled option
|
|
||||||
disabled =
|
|
||||||
{ config, ... }:
|
|
||||||
{
|
|
||||||
performance.combinePlugins.enable = false;
|
|
||||||
extraPlugins = pluginStubs.pluginPack;
|
|
||||||
extraConfigLuaPost = lib.concatMapStringsSep "\n" (
|
|
||||||
name:
|
|
||||||
# lua
|
|
||||||
''
|
|
||||||
-- Separate plugin entry in vim.api.nvim_list_runtime_paths()
|
|
||||||
assert(vim.iter(vim.api.nvim_list_runtime_paths()):any(function(entry)
|
|
||||||
return entry:find("${name}", 1, true)
|
|
||||||
end), "plugin '${name}' isn't found in runtime as a separate entry, expected not to be combined")
|
|
||||||
'') pluginStubs.pluginNames;
|
|
||||||
assertions = [
|
|
||||||
(expectNPlugins config "start" (builtins.length pluginStubs.pluginPack))
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
# Test that pathsToLink option works
|
|
||||||
paths-to-link =
|
|
||||||
{ config, ... }:
|
|
||||||
{
|
|
||||||
performance.combinePlugins = {
|
|
||||||
enable = true;
|
|
||||||
pathsToLink = [ "/_extra" ];
|
|
||||||
};
|
|
||||||
extraPlugins = [
|
|
||||||
# A plugin with extra directory
|
|
||||||
(pluginStubs.mkPlugin "extra" {
|
|
||||||
postInstall = ''
|
|
||||||
mkdir $out/_extra
|
|
||||||
touch $out/_extra/test
|
|
||||||
'';
|
|
||||||
})
|
|
||||||
];
|
|
||||||
extraConfigLuaPost = ''
|
|
||||||
${pluginStubs.pluginChecksFor [ "extra" ]}
|
|
||||||
|
|
||||||
-- Test file is in runtime
|
|
||||||
assert(
|
|
||||||
vim.api.nvim_get_runtime_file("_extra/test", false)[1],
|
|
||||||
"'_extra/test' file isn't found in runtime, expected to be found"
|
|
||||||
)
|
|
||||||
'';
|
|
||||||
assertions = [
|
|
||||||
(expectOneStartPlugin config)
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
# Test that optional plugins are handled
|
|
||||||
optional-plugins =
|
|
||||||
{ config, ... }:
|
|
||||||
{
|
|
||||||
performance.combinePlugins.enable = true;
|
|
||||||
extraPlugins = with pluginStubs; [
|
|
||||||
# Start plugins
|
|
||||||
plugin1
|
|
||||||
plugin3
|
|
||||||
# Optional plugin
|
|
||||||
{
|
|
||||||
plugin = plugin2;
|
|
||||||
optional = true;
|
|
||||||
}
|
|
||||||
# Optional plugin with dependencies on plugin3 and plugin4
|
|
||||||
# Dependencies should not be duplicated
|
|
||||||
{
|
|
||||||
plugin = pluginWithDep4;
|
|
||||||
optional = true;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
extraConfigLuaPost = ''
|
|
||||||
-- Start plugins are working. Dependencies of the optional plugins are also available.
|
|
||||||
${pluginStubs.pluginChecksFor [
|
|
||||||
"plugin1"
|
|
||||||
"plugin3"
|
|
||||||
"plugin4" # Dependency of the optional plugin
|
|
||||||
]}
|
|
||||||
|
|
||||||
-- Lua libraries are available. Libs of the optional plugins are also available.
|
|
||||||
${pluginStubs.libChecksFor [
|
|
||||||
"lib1"
|
|
||||||
"lib2" # Dependency of the optional plugin
|
|
||||||
"lib3"
|
|
||||||
]}
|
|
||||||
|
|
||||||
${lib.concatMapStrings
|
|
||||||
(
|
|
||||||
name: # lua
|
name: # lua
|
||||||
''
|
''
|
||||||
-- Optional plugin is not loadable
|
assert(not vim.iter(vim.api.nvim_list_runtime_paths()):any(function(entry)
|
||||||
local ok = pcall(require, "${name}")
|
return entry:find("${name}", 1, true)
|
||||||
assert(not ok, "${name} is loadable, expected it to be an opt plugin")
|
end), "plugin '${name}' found in runtime, expected to be combined")
|
||||||
|
'') pluginStubs.pluginNames}
|
||||||
-- Load plugin
|
'';
|
||||||
vim.cmd.packadd("${name}")
|
assertions = [
|
||||||
|
(expectOneStartPlugin config)
|
||||||
-- Now opt plugin is working
|
];
|
||||||
${pluginStubs.pluginChecksFor [ name ]}
|
|
||||||
'')
|
|
||||||
[
|
|
||||||
"plugin2"
|
|
||||||
"plugin_with_dep4"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Only one copy of dependent plugin should be available
|
|
||||||
${lib.concatMapStrings
|
|
||||||
(
|
|
||||||
name: # lua
|
|
||||||
''
|
|
||||||
local num_plugins = #vim.api.nvim_get_runtime_file("lua/${name}/init.lua", true)
|
|
||||||
assert(num_plugins == 1, "expected 1 copy of ${name}, got " .. num_plugins)
|
|
||||||
'')
|
|
||||||
[
|
|
||||||
"plugin3"
|
|
||||||
"plugin4"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
assertions = [
|
|
||||||
(expectOneStartPlugin config)
|
|
||||||
# plugin2 plugin_with_dep4
|
|
||||||
(expectNPlugins config "opt" 2)
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
# Test that plugin configs are handled
|
|
||||||
configs =
|
|
||||||
{ config, ... }:
|
|
||||||
{
|
|
||||||
performance.combinePlugins.enable = true;
|
|
||||||
extraPlugins = with pluginStubs; [
|
|
||||||
# A plugin without config
|
|
||||||
plugin1
|
|
||||||
# A plugin with config
|
|
||||||
{
|
|
||||||
plugin = plugin2;
|
|
||||||
config = "let g:plugin2_var = 1";
|
|
||||||
}
|
|
||||||
# Optional plugin with config
|
|
||||||
{
|
|
||||||
plugin = plugin3;
|
|
||||||
optional = true;
|
|
||||||
config = "let g:plugin3_var = 1";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
extraConfigLuaPost = ''
|
|
||||||
-- Configs are evaluated
|
|
||||||
assert(vim.g.plugin2_var == 1, "plugin2's config isn't evaluated")
|
|
||||||
assert(vim.g.plugin3_var == 1, "plugin3's config isn't evaluated")
|
|
||||||
'';
|
|
||||||
assertions = [
|
|
||||||
(expectOneStartPlugin config)
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
# Test if plenary.filetype is working
|
|
||||||
plenary-nvim = {
|
|
||||||
performance.combinePlugins.enable = true;
|
|
||||||
extraPlugins = [ pkgs.vimPlugins.plenary-nvim ];
|
|
||||||
extraConfigLuaPost = ''
|
|
||||||
-- Plenary filetype detection is usable
|
|
||||||
assert(require("plenary.filetype").detect(".bashrc") == "sh", "plenary.filetype is not working")
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
//
|
|
||||||
# Test that config.build.extraFiles is not combined
|
|
||||||
# with or without byteCompileLua.enable = true
|
|
||||||
lib.genAttrs [ "files-plugin" "files-plugin-byte-compiled" ] (
|
|
||||||
name:
|
|
||||||
{ config, ... }:
|
|
||||||
{
|
|
||||||
performance = {
|
|
||||||
combinePlugins.enable = true;
|
|
||||||
byteCompileLua = lib.optionalAttrs (lib.hasSuffix "byte-compiled" name) {
|
|
||||||
enable = true;
|
|
||||||
plugins = true;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
extraPlugins = with pluginStubs; [
|
|
||||||
plugin1
|
|
||||||
plugin2
|
|
||||||
];
|
|
||||||
# Ensure that build.extraFiles is added to extraPlugins
|
|
||||||
wrapRc = true;
|
|
||||||
# Extra user files colliding with plugins
|
|
||||||
extraFiles = {
|
|
||||||
"lua/plugin1/init.lua".text = "return 1";
|
|
||||||
};
|
|
||||||
# Another form of user files
|
|
||||||
files = {
|
|
||||||
"lua/plugin2/init.lua" = {
|
|
||||||
extraConfigLua = "return 1";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
extraConfigLuaPost = ''
|
|
||||||
for _, file in ipairs({"lua/plugin1/init.lua", "lua/plugin2/init.lua"}) do
|
|
||||||
local paths_found = vim.api.nvim_get_runtime_file(file, true)
|
|
||||||
local num_found = #paths_found
|
|
||||||
|
|
||||||
-- Both plugin and user version are available
|
# Test disabled option
|
||||||
assert(num_found == 2, "expected exactly 2 versions of '" .. file .. "', got " .. num_found)
|
disabled =
|
||||||
|
{ config, ... }:
|
||||||
-- First found file is from build.extraFiles
|
{
|
||||||
assert(
|
performance.combinePlugins.enable = false;
|
||||||
paths_found[1]:find("${lib.getName config.build.extraFiles}", 1, true),
|
extraPlugins = pluginStubs.pluginPack;
|
||||||
"expected first found '" .. file .. "' to be from build.extraFiles, got " .. paths_found[1]
|
extraConfigLuaPost = lib.concatMapStringsSep "\n" (
|
||||||
)
|
|
||||||
end
|
|
||||||
'';
|
|
||||||
assertions = [
|
|
||||||
(expectOneStartPlugin config)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
)
|
|
||||||
//
|
|
||||||
# Test that standalonePlugins option works
|
|
||||||
# with or without byteCompileLua.enable = true
|
|
||||||
lib.genAttrs [ "standalone-plugins" "standalone-plugins-byte-compiled" ] (
|
|
||||||
name:
|
|
||||||
{ config, ... }:
|
|
||||||
let
|
|
||||||
standalonePlugins = [
|
|
||||||
# By plugin name
|
|
||||||
"plugin1"
|
|
||||||
# By package itself. Its dependency, plugin4, not in this list, so will be combined
|
|
||||||
pluginStubs.pluginWithDep4
|
|
||||||
# Dependency of other plugin
|
|
||||||
"plugin5"
|
|
||||||
# Both dependency and top-level plugin
|
|
||||||
"plugin3"
|
|
||||||
];
|
|
||||||
in
|
|
||||||
{
|
|
||||||
performance = {
|
|
||||||
combinePlugins = {
|
|
||||||
enable = true;
|
|
||||||
inherit standalonePlugins;
|
|
||||||
};
|
|
||||||
byteCompileLua = lib.optionalAttrs (lib.hasSuffix "byte-compiled" name) {
|
|
||||||
enable = true;
|
|
||||||
plugins = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
extraPlugins = pluginStubs.pluginPack;
|
|
||||||
extraConfigLuaPost = ''
|
|
||||||
${pluginStubs.pluginChecks}
|
|
||||||
|
|
||||||
${lib.concatMapStringsSep "\n" (
|
|
||||||
name:
|
name:
|
||||||
let
|
|
||||||
isStandalone = builtins.elem name (
|
|
||||||
map (x: if builtins.isString x then x else lib.getName x) standalonePlugins
|
|
||||||
);
|
|
||||||
expectedText = if isStandalone then "standalone" else "combined";
|
|
||||||
in
|
|
||||||
# lua
|
# lua
|
||||||
''
|
''
|
||||||
-- Check that ${name} plugin is ${expectedText}
|
-- Separate plugin entry in vim.api.nvim_list_runtime_paths()
|
||||||
local paths = vim.api.nvim_get_runtime_file("lua/${name}", true)
|
assert(vim.iter(vim.api.nvim_list_runtime_paths()):any(function(entry)
|
||||||
-- Plugins shouldn't be duplicated
|
return entry:find("${name}", 1, true)
|
||||||
assert(#paths == 1, "expected exactly 1 copy of '${name}' in runtime, got ", #paths)
|
end), "plugin '${name}' isn't found in runtime as a separate entry, expected not to be combined")
|
||||||
-- Test if plugin is standalone. This matches directory name before '/lua/'.
|
'') pluginStubs.pluginNames;
|
||||||
local is_standalone = paths[1]:match("^(.+)/lua/"):find("${name}", 1, true) ~= nil
|
assertions = [
|
||||||
assert(
|
(expectNPlugins config "start" (builtins.length pluginStubs.pluginPack))
|
||||||
is_standalone == ${lib.nixvim.toLuaObject isStandalone},
|
];
|
||||||
"expected '${name}' to be ${expectedText}, found path: " .. paths[1]
|
};
|
||||||
)
|
|
||||||
''
|
# Test that pathsToLink option works
|
||||||
) pluginStubs.pluginNames}
|
paths-to-link =
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
performance.combinePlugins = {
|
||||||
|
enable = true;
|
||||||
|
pathsToLink = [ "/_extra" ];
|
||||||
|
};
|
||||||
|
extraPlugins = [
|
||||||
|
# A plugin with extra directory
|
||||||
|
(pluginStubs.mkPlugin "extra" {
|
||||||
|
postInstall = ''
|
||||||
|
mkdir $out/_extra
|
||||||
|
touch $out/_extra/test
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
];
|
||||||
|
extraConfigLuaPost = ''
|
||||||
|
${pluginStubs.pluginChecksFor [ "extra" ]}
|
||||||
|
|
||||||
|
-- Test file is in runtime
|
||||||
|
assert(
|
||||||
|
vim.api.nvim_get_runtime_file("_extra/test", false)[1],
|
||||||
|
"'_extra/test' file isn't found in runtime, expected to be found"
|
||||||
|
)
|
||||||
|
'';
|
||||||
|
assertions = [
|
||||||
|
(expectOneStartPlugin config)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
# Test that optional plugins are handled
|
||||||
|
optional-plugins =
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
performance.combinePlugins.enable = true;
|
||||||
|
extraPlugins = with pluginStubs; [
|
||||||
|
# Start plugins
|
||||||
|
plugin1
|
||||||
|
plugin3
|
||||||
|
# Optional plugin
|
||||||
|
{
|
||||||
|
plugin = plugin2;
|
||||||
|
optional = true;
|
||||||
|
}
|
||||||
|
# Optional plugin with dependencies on plugin3 and plugin4
|
||||||
|
# Dependencies should not be duplicated
|
||||||
|
{
|
||||||
|
plugin = pluginWithDep4;
|
||||||
|
optional = true;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
extraConfigLuaPost = ''
|
||||||
|
-- Start plugins are working. Dependencies of the optional plugins are also available.
|
||||||
|
${pluginStubs.pluginChecksFor [
|
||||||
|
"plugin1"
|
||||||
|
"plugin3"
|
||||||
|
"plugin4" # Dependency of the optional plugin
|
||||||
|
]}
|
||||||
|
|
||||||
|
-- Lua libraries are available. Libs of the optional plugins are also available.
|
||||||
|
${pluginStubs.libChecksFor [
|
||||||
|
"lib1"
|
||||||
|
"lib2" # Dependency of the optional plugin
|
||||||
|
"lib3"
|
||||||
|
]}
|
||||||
|
|
||||||
|
${lib.concatMapStrings
|
||||||
|
(
|
||||||
|
name: # lua
|
||||||
|
''
|
||||||
|
-- Optional plugin is not loadable
|
||||||
|
local ok = pcall(require, "${name}")
|
||||||
|
assert(not ok, "${name} is loadable, expected it to be an opt plugin")
|
||||||
|
|
||||||
|
-- Load plugin
|
||||||
|
vim.cmd.packadd("${name}")
|
||||||
|
|
||||||
|
-- Now opt plugin is working
|
||||||
|
${pluginStubs.pluginChecksFor [ name ]}
|
||||||
|
'')
|
||||||
|
[
|
||||||
|
"plugin2"
|
||||||
|
"plugin_with_dep4"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Only one copy of dependent plugin should be available
|
||||||
|
${lib.concatMapStrings
|
||||||
|
(
|
||||||
|
name: # lua
|
||||||
|
''
|
||||||
|
local num_plugins = #vim.api.nvim_get_runtime_file("lua/${name}/init.lua", true)
|
||||||
|
assert(num_plugins == 1, "expected 1 copy of ${name}, got " .. num_plugins)
|
||||||
|
'')
|
||||||
|
[
|
||||||
|
"plugin3"
|
||||||
|
"plugin4"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
assertions = [
|
||||||
|
(expectOneStartPlugin config)
|
||||||
|
# plugin2 plugin_with_dep4
|
||||||
|
(expectNPlugins config "opt" 2)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
# Test that plugin configs are handled
|
||||||
|
configs =
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
performance.combinePlugins.enable = true;
|
||||||
|
extraPlugins = with pluginStubs; [
|
||||||
|
# A plugin without config
|
||||||
|
plugin1
|
||||||
|
# A plugin with config
|
||||||
|
{
|
||||||
|
plugin = plugin2;
|
||||||
|
config = "let g:plugin2_var = 1";
|
||||||
|
}
|
||||||
|
# Optional plugin with config
|
||||||
|
{
|
||||||
|
plugin = plugin3;
|
||||||
|
optional = true;
|
||||||
|
config = "let g:plugin3_var = 1";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
extraConfigLuaPost = ''
|
||||||
|
-- Configs are evaluated
|
||||||
|
assert(vim.g.plugin2_var == 1, "plugin2's config isn't evaluated")
|
||||||
|
assert(vim.g.plugin3_var == 1, "plugin3's config isn't evaluated")
|
||||||
|
'';
|
||||||
|
assertions = [
|
||||||
|
(expectOneStartPlugin config)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
# Test if plenary.filetype is working
|
||||||
|
plenary-nvim = {
|
||||||
|
performance.combinePlugins.enable = true;
|
||||||
|
extraPlugins = [ pkgs.vimPlugins.plenary-nvim ];
|
||||||
|
extraConfigLuaPost = ''
|
||||||
|
-- Plenary filetype detection is usable
|
||||||
|
assert(require("plenary.filetype").detect(".bashrc") == "sh", "plenary.filetype is not working")
|
||||||
'';
|
'';
|
||||||
assertions = [
|
};
|
||||||
# plugin-pack and 'standalonePlugins'
|
}
|
||||||
(expectNPlugins config "start" (builtins.length standalonePlugins + 1))
|
//
|
||||||
];
|
# Test that config.build.extraFiles is not combined
|
||||||
}
|
# with or without byteCompileLua.enable = true
|
||||||
)
|
lib.genAttrs [ "files-plugin" "files-plugin-byte-compiled" ] (
|
||||||
|
name:
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
performance = {
|
||||||
|
combinePlugins.enable = true;
|
||||||
|
byteCompileLua = lib.optionalAttrs (lib.hasSuffix "byte-compiled" name) {
|
||||||
|
enable = true;
|
||||||
|
plugins = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
extraPlugins = with pluginStubs; [
|
||||||
|
plugin1
|
||||||
|
plugin2
|
||||||
|
];
|
||||||
|
# Ensure that build.extraFiles is added to extraPlugins
|
||||||
|
wrapRc = true;
|
||||||
|
# Extra user files colliding with plugins
|
||||||
|
extraFiles = {
|
||||||
|
"lua/plugin1/init.lua".text = "return 1";
|
||||||
|
};
|
||||||
|
# Another form of user files
|
||||||
|
files = {
|
||||||
|
"lua/plugin2/init.lua" = {
|
||||||
|
extraConfigLua = "return 1";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
extraConfigLuaPost = ''
|
||||||
|
for _, file in ipairs({"lua/plugin1/init.lua", "lua/plugin2/init.lua"}) do
|
||||||
|
local paths_found = vim.api.nvim_get_runtime_file(file, true)
|
||||||
|
local num_found = #paths_found
|
||||||
|
|
||||||
|
-- Both plugin and user version are available
|
||||||
|
assert(num_found == 2, "expected exactly 2 versions of '" .. file .. "', got " .. num_found)
|
||||||
|
|
||||||
|
-- First found file is from build.extraFiles
|
||||||
|
assert(
|
||||||
|
paths_found[1]:find("${lib.getName config.build.extraFiles}", 1, true),
|
||||||
|
"expected first found '" .. file .. "' to be from build.extraFiles, got " .. paths_found[1]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
assertions = [
|
||||||
|
(expectOneStartPlugin config)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
//
|
||||||
|
# Test that standalonePlugins option works
|
||||||
|
# with or without byteCompileLua.enable = true
|
||||||
|
lib.genAttrs [ "standalone-plugins" "standalone-plugins-byte-compiled" ] (
|
||||||
|
name:
|
||||||
|
{ config, ... }:
|
||||||
|
let
|
||||||
|
standalonePlugins = [
|
||||||
|
# By plugin name
|
||||||
|
"plugin1"
|
||||||
|
# By package itself. Its dependency, plugin4, not in this list, so will be combined
|
||||||
|
pluginStubs.pluginWithDep4
|
||||||
|
# Dependency of other plugin
|
||||||
|
"plugin5"
|
||||||
|
# Both dependency and top-level plugin
|
||||||
|
"plugin3"
|
||||||
|
];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
performance = {
|
||||||
|
combinePlugins = {
|
||||||
|
enable = true;
|
||||||
|
inherit standalonePlugins;
|
||||||
|
};
|
||||||
|
byteCompileLua = lib.optionalAttrs (lib.hasSuffix "byte-compiled" name) {
|
||||||
|
enable = true;
|
||||||
|
plugins = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
extraPlugins = pluginStubs.pluginPack;
|
||||||
|
extraConfigLuaPost = ''
|
||||||
|
${pluginStubs.pluginChecks}
|
||||||
|
|
||||||
|
${lib.concatMapStringsSep "\n" (
|
||||||
|
name:
|
||||||
|
let
|
||||||
|
isStandalone = builtins.elem name (
|
||||||
|
map (x: if builtins.isString x then x else lib.getName x) standalonePlugins
|
||||||
|
);
|
||||||
|
expectedText = if isStandalone then "standalone" else "combined";
|
||||||
|
in
|
||||||
|
# lua
|
||||||
|
''
|
||||||
|
-- Check that ${name} plugin is ${expectedText}
|
||||||
|
local paths = vim.api.nvim_get_runtime_file("lua/${name}", true)
|
||||||
|
-- Plugins shouldn't be duplicated
|
||||||
|
assert(#paths == 1, "expected exactly 1 copy of '${name}' in runtime, got ", #paths)
|
||||||
|
-- Test if plugin is standalone. This matches directory name before '/lua/'.
|
||||||
|
local is_standalone = paths[1]:match("^(.+)/lua/"):find("${name}", 1, true) ~= nil
|
||||||
|
assert(
|
||||||
|
is_standalone == ${lib.nixvim.toLuaObject isStandalone},
|
||||||
|
"expected '${name}' to be ${expectedText}, found path: " .. paths[1]
|
||||||
|
)
|
||||||
|
''
|
||||||
|
) pluginStubs.pluginNames}
|
||||||
|
'';
|
||||||
|
assertions = [
|
||||||
|
# plugin-pack and 'standalonePlugins'
|
||||||
|
(expectNPlugins config "start" (builtins.length standalonePlugins + 1))
|
||||||
|
];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -90,7 +90,7 @@ let
|
||||||
end
|
end
|
||||||
return M
|
return M
|
||||||
'';
|
'';
|
||||||
# Create a simple rockspec manifiest
|
# Create a simple rockspec manifest
|
||||||
postPatch = ''
|
postPatch = ''
|
||||||
luarocks write-rockspec "${name}" "${version}" .
|
luarocks write-rockspec "${name}" "${version}" .
|
||||||
'';
|
'';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue