tests/modules/performance/byte-compile-lua: test with stub plugins

To reduce unexpected breakages due to changes in nixpkgs, replace the
tested plugins with specially crafted stub plugins.
This commit is contained in:
Stanislav Asunkin 2025-04-30 21:34:01 +03:00
parent 5b47c65705
commit d7475dd0fa

View file

@ -22,6 +22,47 @@ let
end end
end end
''; '';
# Stub plugin built with mkDerivation
stubDrvPlugin = pkgs.stdenvNoCC.mkDerivation {
name = "stub_drv_plugin";
src = pkgs.emptyDirectory;
buildPhase = ''
mkdir -p "$out/lua/$name"
echo "return '$name'" >"$out/lua/$name/init.lua"
mkdir $out/plugin
echo "_G['$name'] = true" >"$out/plugin/$name.lua"
echo "let g:$name = 1" >"$out/plugin/$name.vim"
'';
dependencies = [ stubBuildCommandPlugin ];
};
# Stub plugin built with buildCommand with python dependency
stubBuildCommandPlugin = pkgs.writeTextFile {
name = "stub_build_command_plugin";
text = ''
return "stub_build_command_plugin"
'';
destination = "/lua/stub_build_command_plugin/init.lua";
derivationArgs = {
dependencies = [ stubDependentPlugin ];
passthru.python3Dependencies = ps: [ ps.pyyaml ];
};
};
# Dependent stub plugin
stubDependentPlugin = pkgs.writeTextFile {
name = "stub_dependent_plugin";
text = ''
return "stub_dependent_plugin"
'';
destination = "/lua/stub_dependent_plugin/init.lua";
};
# Stub plugin with an invalid lua file
stubInvalidFilePlugin = pkgs.runCommand "stub_invalid_file_plugin" { } ''
mkdir -p "$out/lua/$name"
echo "return '$name'" >"$out/lua/$name/init.lua"
mkdir "$out/ftplugin"
echo "if true then" >"$out/ftplugin/invalid.lua"
'';
in in
{ {
default = default =
@ -74,7 +115,7 @@ in
}; };
}; };
extraPlugins = [ pkgs.vimPlugins.nvim-lspconfig ]; extraPlugins = [ stubDrvPlugin ];
extraConfigLua = '' extraConfigLua = ''
-- The test will search for this string in nixvim-print-init output: VALIDATING_STRING. -- The test will search for this string in nixvim-print-init output: VALIDATING_STRING.
@ -82,36 +123,38 @@ in
''; '';
# Using plugin for the test code to avoid infinite recursion # Using plugin for the test code to avoid infinite recursion
extraFiles."plugin/test.lua".text = '' extraFiles."plugin/test.lua".text =
${isByteCompiledFun} # lua
''
${isByteCompiledFun}
-- vimrc is byte compiled -- vimrc is byte compiled
local init = vim.env.MYVIMRC or vim.fn.getscriptinfo({name = "init.lua"})[1].name 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(is_byte_compiled(init), "MYVIMRC is expected to be byte compiled, but it's not")
-- nixvim-print-init prints text -- nixvim-print-init prints text
local init_content = vim.fn.system("${lib.getExe config.build.printInitPackage}") 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") assert(init_content:find("VALIDATING_STRING"), "nixvim-print-init's output is byte compiled")
-- lua extraFiles are byte compiled -- lua extraFiles are byte compiled
test_rtp_file("plugin/file_text.lua", true) test_rtp_file("plugin/file_text.lua", true)
test_rtp_file("plugin/file_source.lua", true) test_rtp_file("plugin/file_source.lua", true)
test_rtp_file("plugin/file_drv.lua", true) test_rtp_file("plugin/file_drv.lua", true)
test_rtp_file("plugin/file_path.lua", true) test_rtp_file("plugin/file_path.lua", true)
test_rtp_file("plugin/file_string.lua", true) test_rtp_file("plugin/file_string.lua", true)
test_rtp_file("plugin/file_drv_string.lua", true) test_rtp_file("plugin/file_drv_string.lua", true)
test_rtp_file("plugin/test.vim", false) test_rtp_file("plugin/test.vim", false)
test_rtp_file("plugin/test.json", false) test_rtp_file("plugin/test.json", false)
test_rtp_file("test.txt", false) test_rtp_file("test.txt", false)
-- lua files are byte compiled -- lua files are byte compiled
test_rtp_file("plugin/file.lua", true) test_rtp_file("plugin/file.lua", true)
test_rtp_file("plugin/file.vim", false) test_rtp_file("plugin/file.vim", false)
-- Plugins and neovim runtime aren't byte compiled by default -- Plugins and neovim runtime aren't byte compiled by default
test_rtp_file("lua/vim/lsp.lua", false) test_rtp_file("lua/vim/lsp.lua", false)
test_rtp_file("lua/lspconfig.lua", false) test_rtp_file("lua/stub_drv_plugin/init.lua", false)
''; '';
}; };
@ -128,7 +171,7 @@ in
files."plugin/test2.lua".opts.tabstop = 2; files."plugin/test2.lua".opts.tabstop = 2;
extraPlugins = [ pkgs.vimPlugins.nvim-lspconfig ]; extraPlugins = [ stubDrvPlugin ];
extraConfigLua = '' extraConfigLua = ''
-- The test will search for this string in nixvim-print-init output: VALIDATING_STRING. -- The test will search for this string in nixvim-print-init output: VALIDATING_STRING.
@ -136,27 +179,29 @@ in
''; '';
# Using plugin for the test code to avoid infinite recursion # Using plugin for the test code to avoid infinite recursion
extraFiles."plugin/test.lua".text = '' extraFiles."plugin/test.lua".text =
${isByteCompiledFun} # lua
''
${isByteCompiledFun}
-- vimrc -- vimrc
local init = vim.env.MYVIMRC or vim.fn.getscriptinfo({name = "init.lua"})[1].name 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") assert(not is_byte_compiled(init), "MYVIMRC is not expected to be byte compiled, but it is")
-- nixvim-print-init prints text -- nixvim-print-init prints text
local init_content = vim.fn.system("${lib.getExe config.build.printInitPackage}") 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") assert(init_content:find("VALIDATING_STRING"), "nixvim-print-init's output is byte compiled")
-- Nothing is byte compiled -- Nothing is byte compiled
-- extraFiles -- extraFiles
test_rtp_file("plugin/test1.lua", false) test_rtp_file("plugin/test1.lua", false)
-- files -- files
test_rtp_file("plugin/test2.lua", false) test_rtp_file("plugin/test2.lua", false)
-- Plugins -- Plugins
test_rtp_file("lua/lspconfig.lua", false) test_rtp_file("lua/stub_drv_plugin/init.lua", false)
-- Neovim runtime -- Neovim runtime
test_rtp_file("lua/vim/lsp.lua", false) test_rtp_file("lua/vim/lsp.lua", false)
''; '';
}; };
@ -202,8 +247,7 @@ in
}; };
extraPlugins = [ extraPlugins = [
# Python 3 dependencies stubBuildCommandPlugin
(pkgs.vimPlugins.nvim-lspconfig.overrideAttrs { passthru.python3Dependencies = ps: [ ps.pyyaml ]; })
]; ];
extraConfigLuaPost = '' extraConfigLuaPost = ''
@ -246,51 +290,38 @@ in
combinePlugins.enable = pkgs.lib.hasSuffix "combined" name; combinePlugins.enable = pkgs.lib.hasSuffix "combined" name;
}; };
extraPlugins = with pkgs.vimPlugins; [ extraPlugins = [
nvim-lspconfig # Depends on stubBuildCommandPlugin -> stubDependentPlugin
# Depends on nui-nvim stubDrvPlugin
noice-nvim # Plugin with invalid
# buildCommand plugin with python3 dependency stubInvalidFilePlugin
((pkgs.writeTextDir "/plugin/test.lua" "vim.opt.tabstop = 2").overrideAttrs {
passthru.python3Dependencies = ps: [ ps.pyyaml ];
})
# Plugin with invalid lua file tests/indent/lua/cond.lua (should be ignored)
nvim-treesitter
]; ];
extraConfigLuaPost = '' extraConfigLuaPost = ''
${isByteCompiledFun} ${isByteCompiledFun}
-- Plugins are loadable -- Plugins are loadable
require("lspconfig") require("stub_drv_plugin")
require("noice") require("stub_build_command_plugin")
require("nui.popup") require("stub_dependent_plugin")
require("nvim-treesitter") require("stub_invalid_file_plugin")
-- Python modules are importable -- Python modules are importable
vim.cmd.py3("import yaml") vim.cmd.py3("import yaml")
-- nvim-lspconfig -- stubDrvPlugin
test_rtp_file("lua/lspconfig.lua", true) test_rtp_file("lua/stub_drv_plugin/init.lua", true)
test_rtp_file("lua/lspconfig/configs/nixd.lua", true) test_rtp_file("plugin/stub_drv_plugin.lua", true)
test_rtp_file("plugin/lspconfig.lua", true) test_rtp_file("plugin/stub_drv_plugin.vim", false)
test_rtp_file("doc/lspconfig.txt", false)
-- noice-nvim -- stubBuildCommandPlugin
test_rtp_file("lua/noice/init.lua", true) test_rtp_file("lua/stub_build_command_plugin/init.lua", true)
test_rtp_file("lua/noice/config/init.lua", true)
test_rtp_file("doc/noice.nvim.txt", false)
-- Dependency of noice-nvim (nui-nvim) -- stubDependentPlugin
test_rtp_file("lua/nui/popup/init.lua", true) test_rtp_file("lua/stub_dependent_plugin/init.lua", true)
-- Test plugin -- stubInvalidFilePlugin
test_rtp_file("plugin/test.lua", true) test_rtp_file("lua/stub_invalid_file_plugin/init.lua", true)
test_rtp_file("ftplugin/invalid.lua", false)
-- nvim-treesitter
test_rtp_file("lua/nvim-treesitter/health.lua", true)
test_rtp_file("lua/nvim-treesitter/install.lua", true)
test_rtp_file("plugin/nvim-treesitter.lua", true)
test_rtp_file("queries/nix/highlights.scm", false)
''; '';
}) })