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:
Gaetan Lepage 2025-07-25 16:51:47 +02:00 committed by Gaétan Lepage
parent 2dd3e4c8fc
commit 16e3c175ec
3 changed files with 600 additions and 592 deletions

View file

@ -86,256 +86,236 @@ let
"numpy"
];
in
{
default =
{
config,
lib,
pkgs,
...
}:
let
writeLua = lib.nixvim.builders.writeLuaWith pkgs;
in
{
performance.byteCompileLua.enable = true;
# TODO: 2025-07-25 luajit2.1-lib[1-5]-0.0.1 failing to build
# Error: /build/init.lua/lib1-0.0.1-1.rockspec: Unknown field build_dependencies (using rockspec format 1.0)
lib.optionalAttrs false (
{
default =
{
config,
lib,
pkgs,
...
}:
let
writeLua = lib.nixvim.builders.writeLuaWith pkgs;
in
{
performance.byteCompileLua.enable = true;
extraFiles = {
# By text
"plugin/extra_file_text.lua".text = "vim.g.extra_file_text = true";
# By simple source derivation using buildCommand
"plugin/extra_file_source.lua".source =
writeLua "extra_file_source.lua" "vim.g.extra_file_source = true";
# By standard derivation, it needs to execute fixupPhase
"plugin/extra_file_drv.lua".source = pkgs.stdenvNoCC.mkDerivation {
name = "extra_file_drv.lua";
src = pkgs.emptyDirectory;
buildPhase = ''
echo "vim.g.extra_file_drv = true" > $out
extraFiles = {
# By text
"plugin/extra_file_text.lua".text = "vim.g.extra_file_text = true";
# By simple source derivation using buildCommand
"plugin/extra_file_source.lua".source =
writeLua "extra_file_source.lua" "vim.g.extra_file_source = true";
# By standard derivation, it needs to execute fixupPhase
"plugin/extra_file_drv.lua".source = pkgs.stdenvNoCC.mkDerivation {
name = "extra_file_drv.lua";
src = pkgs.emptyDirectory;
buildPhase = ''
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 = {
"plugin/file.lua" = {
globals.file_lua = true;
};
"plugin/file.vim" = {
globals.file_vimscript = true;
};
};
disabled = {
performance.byteCompileLua.enable = false;
extraFiles."plugin/test1.lua".text = "vim.opt.tabstop = 2";
files."plugin/test2.lua".opts.tabstop = 2;
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.
${isByteCompiledFun}
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 = {
performance.byteCompileLua.enable = false;
init-lua-disabled = {
performance.byteCompileLua = {
enable = true;
initLua = false;
};
extraFiles."plugin/test1.lua".text = "vim.opt.tabstop = 2";
extraConfigLuaPost = ''
${isByteCompiledFun}
files."plugin/test2.lua".opts.tabstop = 2;
extraPlugins = shortPluginList;
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;
-- vimrc is not byte compiled
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")
'';
};
extraConfigLuaPost = ''
${isByteCompiledFun}
configs-disabled = {
performance.byteCompileLua = {
enable = true;
configs = false;
};
-- vimrc is not byte compiled
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."plugin/test1.lua".text = "vim.opt.tabstop = 2";
configs-disabled = {
performance.byteCompileLua = {
enable = true;
configs = false;
files."plugin/test2.lua".opts.tabstop = 2;
extraConfigLuaPost = ''
${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 = ''
${isByteCompiledFun}
extraConfigLuaPost = ''
${isByteCompiledFun}
-- extraFiles
test_rtp_file("plugin/test1.lua", false)
-- files
test_rtp_file("plugin/test2.lua", false)
'';
};
${shortChecks}
nvim-runtime = {
performance.byteCompileLua = {
enable = true;
nvimRuntime = true;
-- 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)
'';
};
extraPlugins = shortPluginList;
extraLuaPackages = _: shortLuaList;
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.luaLib for extraLuaPackages
lua-lib-extra-lua-packages = {
performance.byteCompileLua = {
enable = true;
luaLib = true;
};
extraPlugins = pluginStubs.pluginPack;
extraLuaPackages = _: pluginStubs.libPack;
extraConfigLuaPost = ''
${pluginStubs.pluginChecks}
${pluginStubs.libChecks}
${isByteCompiledFun}
@ -343,96 +323,120 @@ in
${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 = {
# performance.byteCompileLua.luaLib for propagatedBuildInputs
lua-lib-propagated-build-inputs =
{ config, ... }:
{
performance.byteCompileLua = {
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 ++ [
# A plugin with invalid lua file
(pluginStubs.mkPlugin "invalid" {
postInstall = ''
mkdir $out/ftplugin
echo "if true then" >$out/ftplugin/invalid.lua
'';
})
];
combinePlugins.enable = lib.hasSuffix "combined" name;
};
extraConfigLuaPost = ''
${pluginStubs.pluginChecks}
extraPlugins = pluginStubs.pluginPack ++ [
# 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
${lib.concatMapStrings (name: ''
test_rtp_file("lua/${name}/init.lua", true)
test_rtp_file("plugin/${name}.lua", true)
'') pluginStubs.pluginNames}
${isByteCompiledFun}
-- Lua modules aren't byte-compiled
${lib.concatMapStrings (name: ''
test_lualib_file(require("${name}").name, false)
'') pluginStubs.libNames}
-- Plugins are byte-compiled
${lib.concatMapStrings (name: ''
test_rtp_file("lua/${name}/init.lua", true)
test_rtp_file("plugin/${name}.lua", true)
'') pluginStubs.pluginNames}
-- A plugin with invalid file
${pluginStubs.pluginChecksFor [ "invalid" ]}
-- invalid file exists, but isn't byte compiled
test_rtp_file("ftplugin/invalid.lua", false)
'';
})
-- Lua modules aren't byte-compiled
${lib.concatMapStrings (name: ''
test_lualib_file(require("${name}").name, 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)
'';
})
)

View file

@ -21,307 +21,311 @@ let
# Assertion that exactly one start plugin is defined in nvimPackage.packpathDirs
expectOneStartPlugin = config: expectNPlugins config "start" 1;
in
{
# Test basic functionality
default =
{ config, ... }:
{
performance.combinePlugins.enable = true;
extraPlugins = pluginStubs.pluginPack;
extraConfigLuaPost = ''
${pluginStubs.pluginChecks}
# TODO: 2025-07-25 luajit2.1-lib[1-5]-0.0.1 failing to build
# Error: /build/init.lua/lib1-0.0.1-1.rockspec: Unknown field build_dependencies (using rockspec format 1.0)
lib.optionalAttrs false (
{
# Test basic functionality
default =
{ config, ... }:
{
performance.combinePlugins.enable = true;
extraPlugins = pluginStubs.pluginPack;
extraConfigLuaPost = ''
${pluginStubs.pluginChecks}
-- No separate plugin entry in vim.api.nvim_list_runtime_paths()
${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
(
-- No separate plugin entry in vim.api.nvim_list_runtime_paths()
${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")
'';
};
}
//
# 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;
};
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)
];
};
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" (
# Test disabled option
disabled =
{ config, ... }:
{
performance.combinePlugins.enable = false;
extraPlugins = pluginStubs.pluginPack;
extraConfigLuaPost = 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}
-- 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
''
-- 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))
];
}
)
)

View file

@ -90,7 +90,7 @@ let
end
return M
'';
# Create a simple rockspec manifiest
# Create a simple rockspec manifest
postPatch = ''
luarocks write-rockspec "${name}" "${version}" .
'';