tests: remove special treatment of module

Since we no longer need to extract `tests.dontRun` from an attrset, we
no longer need the "special" `module` attr.
This commit is contained in:
Matt Sturgeon 2024-08-20 00:54:50 +01:00
parent 7b2a6cd9e6
commit 123a55ed6f
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
14 changed files with 266 additions and 285 deletions

View file

@ -25,7 +25,7 @@ let
[ [
{ {
name = "main"; name = "main";
case = builtins.removeAttrs config.programs.nixvim [ module = builtins.removeAttrs config.programs.nixvim [
# This is not available to standalone modules, only HM & NixOS Modules # This is not available to standalone modules, only HM & NixOS Modules
"enable" "enable"
# This is purely an example, it does not reflect a real usage # This is purely an example, it does not reflect a real usage
@ -41,17 +41,12 @@ lib.pipe (testFiles ++ [ exampleFiles ]) [
(builtins.map ( (builtins.map (
file: file:
let let
# The test case can either be the actual definition,
# or a child attr named `module`.
prepareModule = case: if lib.isFunction case then case else case.module or case;
mkTest = mkTest =
{ name, case }: { name, module }:
{ {
inherit name; inherit name;
path = mkTestDerivationFromNixvimModule { path = mkTestDerivationFromNixvimModule {
inherit name; inherit name module;
module = prepareModule case;
pkgs = pkgsUnfree; pkgs = pkgsUnfree;
}; };
}; };

View file

@ -64,7 +64,7 @@ let
{ namespace, cases }: { namespace, cases }:
{ {
name = lib.strings.concatStringsSep "-" namespace; name = lib.strings.concatStringsSep "-" namespace;
cases = lib.mapAttrsToList (name: case: { inherit case name; }) cases; cases = lib.mapAttrsToList (name: module: { inherit module name; }) cases;
}; };
in in
# A list of the form [ { name = "..."; modules = [ /* test cases */ ]; } ] # A list of the form [ { name = "..."; modules = [ /* test cases */ ]; } ]

View file

@ -15,9 +15,7 @@ let
}; };
in in
{ {
top-level = { top-level = module;
inherit module;
};
files-module = { files-module = {
files."libtest.lua" = module; files."libtest.lua" = module;

View file

@ -39,7 +39,7 @@
}; };
}; };
default-empty.module = default-empty =
{ config, ... }: { config, ... }:
{ {
files.test = { }; files.test = { };

View file

@ -1,6 +1,6 @@
{ {
# Test that nothing is configured by default # Test that nothing is configured by default
default.module = default =
{ config, lib, ... }: { config, lib, ... }:
{ {
files."files_test.lua" = { }; files."files_test.lua" = { };
@ -18,7 +18,7 @@
}; };
# Test Lua loader enabled # Test Lua loader enabled
enabled.module = enabled =
{ config, lib, ... }: { config, lib, ... }:
{ {
luaLoader.enable = true; luaLoader.enable = true;
@ -38,7 +38,7 @@
}; };
# Test Lua loader disabled # Test Lua loader disabled
disabled.module = disabled =
{ config, lib, ... }: { config, lib, ... }:
{ {
luaLoader.enable = false; luaLoader.enable = false;

View file

@ -6,7 +6,7 @@
}; };
# Test that all extraConfigs are present in output # Test that all extraConfigs are present in output
all-configs.module = all-configs =
{ {
config, config,
pkgs, pkgs,
@ -64,7 +64,7 @@
++ mkConfigAssertions "test.vim" config.files."test.vim".content; ++ mkConfigAssertions "test.vim" config.files."test.vim".content;
}; };
files-default-empty.module = files-default-empty =
{ config, helpers, ... }: { config, helpers, ... }:
{ {
files = { files = {

View file

@ -24,7 +24,7 @@ let
''; '';
in in
{ {
default.module = default =
{ config, ... }: { config, ... }:
{ {
performance.byteCompileLua.enable = true; performance.byteCompileLua.enable = true;
@ -107,7 +107,7 @@ in
}; };
disabled.module = disabled =
{ config, ... }: { config, ... }:
{ {
performance.byteCompileLua.enable = false; performance.byteCompileLua.enable = false;

View file

@ -9,7 +9,7 @@ let
in in
{ {
# Test basic functionality # Test basic functionality
default.module = default =
{ config, ... }: { config, ... }:
{ {
performance.combinePlugins.enable = true; performance.combinePlugins.enable = true;
@ -40,7 +40,7 @@ in
}; };
# Test disabled option # Test disabled option
disabled.module = disabled =
{ config, ... }: { config, ... }:
{ {
performance.combinePlugins.enable = false; performance.combinePlugins.enable = false;
@ -57,7 +57,7 @@ in
}; };
# Test that plugin dependencies are handled # Test that plugin dependencies are handled
dependencies.module = dependencies =
{ config, ... }: { config, ... }:
{ {
performance.combinePlugins.enable = true; performance.combinePlugins.enable = true;
@ -84,7 +84,7 @@ in
}; };
# Test that pathsToLink option works # Test that pathsToLink option works
paths-to-link.module = paths-to-link =
{ config, ... }: { config, ... }:
{ {
performance.combinePlugins = { performance.combinePlugins = {
@ -112,7 +112,7 @@ in
}; };
# Test that plugin python3 dependencies are handled # Test that plugin python3 dependencies are handled
python-dependencies.module = python-dependencies =
{ config, ... }: { config, ... }:
{ {
performance.combinePlugins.enable = true; performance.combinePlugins.enable = true;
@ -139,7 +139,7 @@ in
}; };
# Test that optional plugins are handled # Test that optional plugins are handled
optional-plugins.module = optional-plugins =
{ config, ... }: { config, ... }:
{ {
performance.combinePlugins.enable = true; performance.combinePlugins.enable = true;
@ -197,7 +197,7 @@ in
}; };
# Test that plugin configs are handled # Test that plugin configs are handled
configs.module = configs =
{ config, ... }: { config, ... }:
{ {
performance.combinePlugins.enable = true; performance.combinePlugins.enable = true;
@ -240,7 +240,7 @@ in
}; };
# Test that config.filesPlugin is not combined # Test that config.filesPlugin is not combined
files-plugin.module = files-plugin =
{ config, ... }: { config, ... }:
{ {
performance.combinePlugins.enable = true; performance.combinePlugins.enable = true;
@ -310,7 +310,7 @@ in
}; };
# Test that standalonePlugins option works # Test that standalonePlugins option works
standalone-plugins.module = standalone-plugins =
{ config, ... }: { config, ... }:
{ {
performance.combinePlugins = { performance.combinePlugins = {

View file

@ -1,41 +1,39 @@
{ pkgs, ... }: { pkgs, ... }:
{ {
all-sources = { all-sources =
module = { config, ... }:
{ config, ... }: {
{ plugins = {
plugins = { copilot-lua = {
copilot-lua = { enable = true;
enable = true;
panel.enabled = false; panel.enabled = false;
suggestion.enabled = false; suggestion.enabled = false;
}; };
cmp = { cmp = {
enable = true; enable = true;
settings.sources = settings.sources =
with pkgs.lib; with pkgs.lib;
let let
disabledSources = [ disabledSources = [
# We do not provide the required HF_API_KEY environment variable. # We do not provide the required HF_API_KEY environment variable.
"cmp_ai" "cmp_ai"
# Triggers the warning complaining about treesitter highlighting being disabled # Triggers the warning complaining about treesitter highlighting being disabled
"otter" "otter"
] ++ optional (pkgs.stdenv.hostPlatform.system == "aarch64-linux") "cmp_tabnine"; ] ++ optional (pkgs.stdenv.hostPlatform.system == "aarch64-linux") "cmp_tabnine";
in in
pipe config.cmpSourcePlugins [ pipe config.cmpSourcePlugins [
# All known source names # All known source names
attrNames attrNames
# Filter out disabled sources # Filter out disabled sources
(filter (name: !(elem name disabledSources))) (filter (name: !(elem name disabledSources)))
# Convert names to source attributes # Convert names to source attributes
(map (name: { (map (name: {
inherit name; inherit name;
})) }))
]; ];
};
}; };
}; };
}; };
} }

View file

@ -3,23 +3,21 @@
plugins.coq-nvim.enable = true; plugins.coq-nvim.enable = true;
}; };
nixvim-defaults = { nixvim-defaults =
module = { pkgs, ... }:
{ pkgs, ... }: {
{ plugins.coq-nvim = {
plugins.coq-nvim = { # It seems that the plugin has issues being executed in the same derivation
# It seems that the plugin has issues being executed in the same derivation enable = !(pkgs.stdenv.isDarwin && pkgs.stdenv.isx86_64);
enable = !(pkgs.stdenv.isDarwin && pkgs.stdenv.isx86_64);
settings = { settings = {
xdg = true; xdg = true;
auto_start = true; auto_start = true;
keymap.recommended = true; keymap.recommended = true;
completion.always = true; completion.always = true;
};
}; };
}; };
}; };
artifacts = { artifacts = {
plugins.coq-nvim = { plugins.coq-nvim = {

View file

@ -98,71 +98,69 @@
}; };
}; };
with-sources = { with-sources =
module = {
{ config,
config, options,
options, lib,
lib, pkgs,
pkgs, ...
... }:
}: {
{ plugins.none-ls = {
plugins.none-ls = { # sandbox-exec: pattern serialization length 159032 exceeds maximum (65535)
# sandbox-exec: pattern serialization length 159032 exceeds maximum (65535) enable = !pkgs.stdenv.isDarwin;
enable = !pkgs.stdenv.isDarwin;
sources = sources =
let let
disabled = disabled =
[ [
# As of 2024-03-22, pkgs.d2 is broken # As of 2024-03-22, pkgs.d2 is broken
# TODO: re-enable this test when fixed # TODO: re-enable this test when fixed
"d2_fmt" "d2_fmt"
# TODO: can this be re-enabled? # TODO: can this be re-enabled?
"yamlfix" "yamlfix"
] ]
++ (lib.optionals (pkgs.stdenv.isDarwin && pkgs.stdenv.isx86_64) [ ++ (lib.optionals (pkgs.stdenv.isDarwin && pkgs.stdenv.isx86_64) [
# As of 2024-03-27, pkgs.graalvm-ce (a dependency of pkgs.clj-kondo) is broken on x86_64-darwin # As of 2024-03-27, pkgs.graalvm-ce (a dependency of pkgs.clj-kondo) is broken on x86_64-darwin
# TODO: re-enable this test when fixed # TODO: re-enable this test when fixed
"clj_kondo" "clj_kondo"
]) ])
++ (lib.optionals pkgs.stdenv.isDarwin [ ++ (lib.optionals pkgs.stdenv.isDarwin [
# As of 2024-05-22, python311Packages.k5test (one of ansible-lint's dependenvies) is broken on darwin # As of 2024-05-22, python311Packages.k5test (one of ansible-lint's dependenvies) is broken on darwin
# TODO: re-enable this test when fixed # TODO: re-enable this test when fixed
"ansible_lint" "ansible_lint"
"clazy" "clazy"
"gdformat" "gdformat"
"gdlint" "gdlint"
"haml_lint" "haml_lint"
# As of 2024-06-29, pkgs.rubyfmt is broken on darwin # As of 2024-06-29, pkgs.rubyfmt is broken on darwin
# TODO: re-enable this test when fixed # TODO: re-enable this test when fixed
"rubyfmt" "rubyfmt"
"verilator" "verilator"
"verible_verilog_format" "verible_verilog_format"
]) ])
++ (lib.optionals pkgs.stdenv.isAarch64 [ ++ (lib.optionals pkgs.stdenv.isAarch64 [
"semgrep" "semgrep"
"smlfmt" "smlfmt"
# As of 2024-03-11, swift-format is broken on aarch64 # As of 2024-03-11, swift-format is broken on aarch64
# TODO: re-enable this test when fixed # TODO: re-enable this test when fixed
"swift_format" "swift_format"
]); ]);
in in
# Enable every none-ls source that has an option # Enable every none-ls source that has an option
lib.mapAttrs (
_:
lib.mapAttrs ( lib.mapAttrs (
_: sourceName: opts:
lib.mapAttrs ( {
sourceName: opts: # Enable unless disabled above
{ enable = !(lib.elem sourceName disabled);
# Enable unless disabled above }
enable = !(lib.elem sourceName disabled); # Some sources have a package option with no default
} // lib.optionalAttrs (opts ? package && !(opts.package ? default)) { package = null; }
# Some sources have a package option with no default )
// lib.optionalAttrs (opts ? package && !(opts.package ? default)) { package = null; } ) options.plugins.none-ls.sources;
)
) options.plugins.none-ls.sources;
};
}; };
}; };
} }

View file

@ -26,145 +26,141 @@ in
}; };
# single-plugin and priority of plugins.lz-n.settings to globals.lz-n # single-plugin and priority of plugins.lz-n.settings to globals.lz-n
example-single-plugin = { example-single-plugin =
module = { pkgs, lib, ... }:
{ pkgs, lib, ... }: {
{ extraPlugins = optionalPlugins [ pkgs.vimPlugins.neo-tree-nvim ];
extraPlugins = optionalPlugins [ pkgs.vimPlugins.neo-tree-nvim ];
plugins.lz-n = { plugins.lz-n = {
enable = true; enable = true;
settings = { settings = {
load = lib.mkDefault "vim.cmd.packadd"; load = lib.mkDefault "vim.cmd.packadd";
};
plugins = [
# enabled, on keys as rawLua
{
__unkeyed-1 = "neo-tree.nvim";
enabled = ''
function()
return true
end
'';
keys = [
{
__unkeyed-1 = "<leader>ft";
__unkeyed-2 = "<CMD>Neotree toggle<CR>";
desc = "NeoTree toggle";
}
];
after = # lua
''
function()
require("neo-tree").setup()
end
'';
}
];
}; };
}; plugins = [
}; # enabled, on keys as rawLua
{
example-multiple-plugin = { __unkeyed-1 = "neo-tree.nvim";
module = enabled = ''
{ pkgs, lib, ... }: function()
{ return true
extraPlugins = end
with pkgs.vimPlugins; '';
[ onedarker-nvim ] keys = [
++ (optionalPlugins [ {
neo-tree-nvim __unkeyed-1 = "<leader>ft";
dial-nvim __unkeyed-2 = "<CMD>Neotree toggle<CR>";
vimtex desc = "NeoTree toggle";
telescope-nvim }
nvim-biscuits ];
crates-nvim after = # lua
]); ''
plugins.treesitter.enable = true;
plugins.lz-n = {
enable = true;
plugins = [
# enabled, on keys
{
__unkeyed-1 = "neo-tree.nvim";
enabled = ''
function() function()
return true require("neo-tree").setup()
end end
''; '';
keys = [ }
{ ];
__unkeyed-1 = "<leader>ft"; };
__unkeyed-2 = "<CMD>Neotree toggle<CR>"; };
desc = "NeoTree toggle";
} example-multiple-plugin =
]; { pkgs, lib, ... }:
after = # lua {
'' extraPlugins =
function() with pkgs.vimPlugins;
require("neo-tree").setup() [ onedarker-nvim ]
end ++ (optionalPlugins [
''; neo-tree-nvim
} dial-nvim
# on keys as list of str and rawLua vimtex
{ telescope-nvim
__unkeyed-1 = "dial.nvim"; nvim-biscuits
keys = [ crates-nvim
"<C-a>" ]);
{ __raw = "{ '<C-x>'; mode = 'n' }"; }
]; plugins.treesitter.enable = true;
}
# beforeAll, before, on filetype plugins.lz-n = {
{ enable = true;
__unkeyed-1 = "vimtex"; plugins = [
ft = [ "plaintex" ]; # enabled, on keys
beforeAll = # lua {
'' __unkeyed-1 = "neo-tree.nvim";
function() enabled = ''
vim.g.vimtex_compiler_method = "latexrun" function()
end return true
''; end
before = # lua '';
'' keys = [
function() {
vim.g.vimtex_compiler_method = "latexmk" __unkeyed-1 = "<leader>ft";
end __unkeyed-2 = "<CMD>Neotree toggle<CR>";
''; desc = "NeoTree toggle";
} }
# On event ];
{ after = # lua
__unkeyed-1 = "nvim-biscuits"; ''
event.__raw = "{ 'BufEnter *.lua' }";
after.__raw = ''
function() function()
require('nvim-biscuits').setup({}) require("neo-tree").setup()
end end
''; '';
} }
# On command no setup function, priority # on keys as list of str and rawLua
{ {
__unkeyed-1 = "telescope.nvim"; __unkeyed-1 = "dial.nvim";
cmd = [ "Telescope" ]; keys = [
priority = 500; "<C-a>"
} { __raw = "{ '<C-x>'; mode = 'n' }"; }
# On colorschme ];
{ }
__unkeyed-1 = "onedarker.nvim"; # beforeAll, before, on filetype
colorscheme = [ "onedarker" ]; {
} __unkeyed-1 = "vimtex";
# raw value ft = [ "plaintex" ];
{ beforeAll = # lua
__raw = '' ''
{ function()
"crates.nvim", vim.g.vimtex_compiler_method = "latexrun"
ft = "toml", end
}
''; '';
} before = # lua
]; ''
}; function()
vim.g.vimtex_compiler_method = "latexmk"
end
'';
}
# On event
{
__unkeyed-1 = "nvim-biscuits";
event.__raw = "{ 'BufEnter *.lua' }";
after.__raw = ''
function()
require('nvim-biscuits').setup({})
end
'';
}
# On command no setup function, priority
{
__unkeyed-1 = "telescope.nvim";
cmd = [ "Telescope" ];
priority = 500;
}
# On colorschme
{
__unkeyed-1 = "onedarker.nvim";
colorscheme = [ "onedarker" ];
}
# raw value
{
__raw = ''
{
"crates.nvim",
ft = "toml",
}
'';
}
];
}; };
}; };
} }

View file

@ -18,18 +18,16 @@
}; };
}; };
combine-plugins.module = combine-plugins = {
{ config, ... }: plugins.telescope.enable = true;
{
plugins.telescope.enable = true;
performance.combinePlugins.enable = true; performance.combinePlugins.enable = true;
extraConfigLuaPost = # lua extraConfigLuaPost = # lua
'' ''
-- I don't know how run telescope properly in test environment, -- I don't know how run telescope properly in test environment,
-- so just check that files exist -- so just check that files exist
assert(vim.api.nvim_get_runtime_file("data/memes/planets/earth", false)[1], "telescope planets aren't found in runtime") assert(vim.api.nvim_get_runtime_file("data/memes/planets/earth", false)[1], "telescope planets aren't found in runtime")
''; '';
}; };
} }

View file

@ -26,7 +26,7 @@
}; };
}; };
check-alias.module = check-alias =
{ config, ... }: { config, ... }:
{ {
assertions = [ assertions = [