From 123a55ed6f8ae2daec76af5a0ee7e495ccb7e884 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 20 Aug 2024 00:54:50 +0100 Subject: [PATCH] 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. --- tests/default.nix | 11 +- tests/fetch-tests.nix | 2 +- tests/test-sources/extended-lib.nix | 4 +- tests/test-sources/modules/filetypes.nix | 2 +- tests/test-sources/modules/lua-loader.nix | 6 +- tests/test-sources/modules/output.nix | 4 +- .../modules/performance/byte-compile-lua.nix | 4 +- .../modules/performance/combine-plugins.nix | 18 +- .../plugins/completion/cmp-all-sources.nix | 66 +++-- tests/test-sources/plugins/completion/coq.nix | 26 +- tests/test-sources/plugins/none-ls.nix | 126 +++++---- .../plugins/pluginmanagers/lz-n.nix | 258 +++++++++--------- .../plugins/telescope/default.nix | 22 +- tests/test-sources/plugins/utils/firenvim.nix | 2 +- 14 files changed, 266 insertions(+), 285 deletions(-) diff --git a/tests/default.nix b/tests/default.nix index 27faca17..ff17d7fd 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -25,7 +25,7 @@ let [ { 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 "enable" # This is purely an example, it does not reflect a real usage @@ -41,17 +41,12 @@ lib.pipe (testFiles ++ [ exampleFiles ]) [ (builtins.map ( file: 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 = - { name, case }: + { name, module }: { inherit name; path = mkTestDerivationFromNixvimModule { - inherit name; - module = prepareModule case; + inherit name module; pkgs = pkgsUnfree; }; }; diff --git a/tests/fetch-tests.nix b/tests/fetch-tests.nix index ea37a669..6b26928e 100644 --- a/tests/fetch-tests.nix +++ b/tests/fetch-tests.nix @@ -64,7 +64,7 @@ let { namespace, cases }: { name = lib.strings.concatStringsSep "-" namespace; - cases = lib.mapAttrsToList (name: case: { inherit case name; }) cases; + cases = lib.mapAttrsToList (name: module: { inherit module name; }) cases; }; in # A list of the form [ { name = "..."; modules = [ /* test cases */ ]; } ] diff --git a/tests/test-sources/extended-lib.nix b/tests/test-sources/extended-lib.nix index 5d410686..9093ba08 100644 --- a/tests/test-sources/extended-lib.nix +++ b/tests/test-sources/extended-lib.nix @@ -15,9 +15,7 @@ let }; in { - top-level = { - inherit module; - }; + top-level = module; files-module = { files."libtest.lua" = module; diff --git a/tests/test-sources/modules/filetypes.nix b/tests/test-sources/modules/filetypes.nix index 34e3b81f..3e0ad530 100644 --- a/tests/test-sources/modules/filetypes.nix +++ b/tests/test-sources/modules/filetypes.nix @@ -39,7 +39,7 @@ }; }; - default-empty.module = + default-empty = { config, ... }: { files.test = { }; diff --git a/tests/test-sources/modules/lua-loader.nix b/tests/test-sources/modules/lua-loader.nix index 0aaa450c..367e9ed0 100644 --- a/tests/test-sources/modules/lua-loader.nix +++ b/tests/test-sources/modules/lua-loader.nix @@ -1,6 +1,6 @@ { # Test that nothing is configured by default - default.module = + default = { config, lib, ... }: { files."files_test.lua" = { }; @@ -18,7 +18,7 @@ }; # Test Lua loader enabled - enabled.module = + enabled = { config, lib, ... }: { luaLoader.enable = true; @@ -38,7 +38,7 @@ }; # Test Lua loader disabled - disabled.module = + disabled = { config, lib, ... }: { luaLoader.enable = false; diff --git a/tests/test-sources/modules/output.nix b/tests/test-sources/modules/output.nix index 4d835b27..24295dec 100644 --- a/tests/test-sources/modules/output.nix +++ b/tests/test-sources/modules/output.nix @@ -6,7 +6,7 @@ }; # Test that all extraConfigs are present in output - all-configs.module = + all-configs = { config, pkgs, @@ -64,7 +64,7 @@ ++ mkConfigAssertions "test.vim" config.files."test.vim".content; }; - files-default-empty.module = + files-default-empty = { config, helpers, ... }: { files = { diff --git a/tests/test-sources/modules/performance/byte-compile-lua.nix b/tests/test-sources/modules/performance/byte-compile-lua.nix index 3ed29450..e0dd61e3 100644 --- a/tests/test-sources/modules/performance/byte-compile-lua.nix +++ b/tests/test-sources/modules/performance/byte-compile-lua.nix @@ -24,7 +24,7 @@ let ''; in { - default.module = + default = { config, ... }: { performance.byteCompileLua.enable = true; @@ -107,7 +107,7 @@ in }; - disabled.module = + disabled = { config, ... }: { performance.byteCompileLua.enable = false; diff --git a/tests/test-sources/modules/performance/combine-plugins.nix b/tests/test-sources/modules/performance/combine-plugins.nix index 6290bdfe..6fca8bd8 100644 --- a/tests/test-sources/modules/performance/combine-plugins.nix +++ b/tests/test-sources/modules/performance/combine-plugins.nix @@ -9,7 +9,7 @@ let in { # Test basic functionality - default.module = + default = { config, ... }: { performance.combinePlugins.enable = true; @@ -40,7 +40,7 @@ in }; # Test disabled option - disabled.module = + disabled = { config, ... }: { performance.combinePlugins.enable = false; @@ -57,7 +57,7 @@ in }; # Test that plugin dependencies are handled - dependencies.module = + dependencies = { config, ... }: { performance.combinePlugins.enable = true; @@ -84,7 +84,7 @@ in }; # Test that pathsToLink option works - paths-to-link.module = + paths-to-link = { config, ... }: { performance.combinePlugins = { @@ -112,7 +112,7 @@ in }; # Test that plugin python3 dependencies are handled - python-dependencies.module = + python-dependencies = { config, ... }: { performance.combinePlugins.enable = true; @@ -139,7 +139,7 @@ in }; # Test that optional plugins are handled - optional-plugins.module = + optional-plugins = { config, ... }: { performance.combinePlugins.enable = true; @@ -197,7 +197,7 @@ in }; # Test that plugin configs are handled - configs.module = + configs = { config, ... }: { performance.combinePlugins.enable = true; @@ -240,7 +240,7 @@ in }; # Test that config.filesPlugin is not combined - files-plugin.module = + files-plugin = { config, ... }: { performance.combinePlugins.enable = true; @@ -310,7 +310,7 @@ in }; # Test that standalonePlugins option works - standalone-plugins.module = + standalone-plugins = { config, ... }: { performance.combinePlugins = { diff --git a/tests/test-sources/plugins/completion/cmp-all-sources.nix b/tests/test-sources/plugins/completion/cmp-all-sources.nix index 5de73d5c..b46f7295 100644 --- a/tests/test-sources/plugins/completion/cmp-all-sources.nix +++ b/tests/test-sources/plugins/completion/cmp-all-sources.nix @@ -1,41 +1,39 @@ { pkgs, ... }: { - all-sources = { - module = - { config, ... }: - { - plugins = { - copilot-lua = { - enable = true; + all-sources = + { config, ... }: + { + plugins = { + copilot-lua = { + enable = true; - panel.enabled = false; - suggestion.enabled = false; - }; + panel.enabled = false; + suggestion.enabled = false; + }; - cmp = { - enable = true; - settings.sources = - with pkgs.lib; - let - disabledSources = [ - # We do not provide the required HF_API_KEY environment variable. - "cmp_ai" - # Triggers the warning complaining about treesitter highlighting being disabled - "otter" - ] ++ optional (pkgs.stdenv.hostPlatform.system == "aarch64-linux") "cmp_tabnine"; - in - pipe config.cmpSourcePlugins [ - # All known source names - attrNames - # Filter out disabled sources - (filter (name: !(elem name disabledSources))) - # Convert names to source attributes - (map (name: { - inherit name; - })) - ]; - }; + cmp = { + enable = true; + settings.sources = + with pkgs.lib; + let + disabledSources = [ + # We do not provide the required HF_API_KEY environment variable. + "cmp_ai" + # Triggers the warning complaining about treesitter highlighting being disabled + "otter" + ] ++ optional (pkgs.stdenv.hostPlatform.system == "aarch64-linux") "cmp_tabnine"; + in + pipe config.cmpSourcePlugins [ + # All known source names + attrNames + # Filter out disabled sources + (filter (name: !(elem name disabledSources))) + # Convert names to source attributes + (map (name: { + inherit name; + })) + ]; }; }; - }; + }; } diff --git a/tests/test-sources/plugins/completion/coq.nix b/tests/test-sources/plugins/completion/coq.nix index 5bb37f05..893fd9d7 100644 --- a/tests/test-sources/plugins/completion/coq.nix +++ b/tests/test-sources/plugins/completion/coq.nix @@ -3,23 +3,21 @@ plugins.coq-nvim.enable = true; }; - nixvim-defaults = { - module = - { pkgs, ... }: - { - plugins.coq-nvim = { - # It seems that the plugin has issues being executed in the same derivation - enable = !(pkgs.stdenv.isDarwin && pkgs.stdenv.isx86_64); + nixvim-defaults = + { pkgs, ... }: + { + plugins.coq-nvim = { + # It seems that the plugin has issues being executed in the same derivation + enable = !(pkgs.stdenv.isDarwin && pkgs.stdenv.isx86_64); - settings = { - xdg = true; - auto_start = true; - keymap.recommended = true; - completion.always = true; - }; + settings = { + xdg = true; + auto_start = true; + keymap.recommended = true; + completion.always = true; }; }; - }; + }; artifacts = { plugins.coq-nvim = { diff --git a/tests/test-sources/plugins/none-ls.nix b/tests/test-sources/plugins/none-ls.nix index 9a13dcc8..edd7516d 100644 --- a/tests/test-sources/plugins/none-ls.nix +++ b/tests/test-sources/plugins/none-ls.nix @@ -98,71 +98,69 @@ }; }; - with-sources = { - module = - { - config, - options, - lib, - pkgs, - ... - }: - { - plugins.none-ls = { - # sandbox-exec: pattern serialization length 159032 exceeds maximum (65535) - enable = !pkgs.stdenv.isDarwin; + with-sources = + { + config, + options, + lib, + pkgs, + ... + }: + { + plugins.none-ls = { + # sandbox-exec: pattern serialization length 159032 exceeds maximum (65535) + enable = !pkgs.stdenv.isDarwin; - sources = - let - disabled = - [ - # As of 2024-03-22, pkgs.d2 is broken - # TODO: re-enable this test when fixed - "d2_fmt" - # TODO: can this be re-enabled? - "yamlfix" - ] - ++ (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 - # TODO: re-enable this test when fixed - "clj_kondo" - ]) - ++ (lib.optionals pkgs.stdenv.isDarwin [ - # As of 2024-05-22, python311Packages.k5test (one of ansible-lint's dependenvies) is broken on darwin - # TODO: re-enable this test when fixed - "ansible_lint" - "clazy" - "gdformat" - "gdlint" - "haml_lint" - # As of 2024-06-29, pkgs.rubyfmt is broken on darwin - # TODO: re-enable this test when fixed - "rubyfmt" - "verilator" - "verible_verilog_format" - ]) - ++ (lib.optionals pkgs.stdenv.isAarch64 [ - "semgrep" - "smlfmt" - # As of 2024-03-11, swift-format is broken on aarch64 - # TODO: re-enable this test when fixed - "swift_format" - ]); - in - # Enable every none-ls source that has an option + sources = + let + disabled = + [ + # As of 2024-03-22, pkgs.d2 is broken + # TODO: re-enable this test when fixed + "d2_fmt" + # TODO: can this be re-enabled? + "yamlfix" + ] + ++ (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 + # TODO: re-enable this test when fixed + "clj_kondo" + ]) + ++ (lib.optionals pkgs.stdenv.isDarwin [ + # As of 2024-05-22, python311Packages.k5test (one of ansible-lint's dependenvies) is broken on darwin + # TODO: re-enable this test when fixed + "ansible_lint" + "clazy" + "gdformat" + "gdlint" + "haml_lint" + # As of 2024-06-29, pkgs.rubyfmt is broken on darwin + # TODO: re-enable this test when fixed + "rubyfmt" + "verilator" + "verible_verilog_format" + ]) + ++ (lib.optionals pkgs.stdenv.isAarch64 [ + "semgrep" + "smlfmt" + # As of 2024-03-11, swift-format is broken on aarch64 + # TODO: re-enable this test when fixed + "swift_format" + ]); + in + # Enable every none-ls source that has an option + lib.mapAttrs ( + _: lib.mapAttrs ( - _: - lib.mapAttrs ( - sourceName: opts: - { - # 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; } - ) - ) options.plugins.none-ls.sources; - }; + sourceName: opts: + { + # 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; } + ) + ) options.plugins.none-ls.sources; }; - }; + }; } diff --git a/tests/test-sources/plugins/pluginmanagers/lz-n.nix b/tests/test-sources/plugins/pluginmanagers/lz-n.nix index 654670ea..1796f8d3 100644 --- a/tests/test-sources/plugins/pluginmanagers/lz-n.nix +++ b/tests/test-sources/plugins/pluginmanagers/lz-n.nix @@ -26,145 +26,141 @@ in }; # single-plugin and priority of plugins.lz-n.settings to globals.lz-n - example-single-plugin = { - module = - { pkgs, lib, ... }: - { - extraPlugins = optionalPlugins [ pkgs.vimPlugins.neo-tree-nvim ]; + example-single-plugin = + { pkgs, lib, ... }: + { + extraPlugins = optionalPlugins [ pkgs.vimPlugins.neo-tree-nvim ]; - plugins.lz-n = { - enable = true; - settings = { - 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 = "ft"; - __unkeyed-2 = "Neotree toggle"; - desc = "NeoTree toggle"; - } - ]; - after = # lua - '' - function() - require("neo-tree").setup() - end - ''; - } - ]; + plugins.lz-n = { + enable = true; + settings = { + load = lib.mkDefault "vim.cmd.packadd"; }; - }; - }; - - example-multiple-plugin = { - module = - { pkgs, lib, ... }: - { - extraPlugins = - with pkgs.vimPlugins; - [ onedarker-nvim ] - ++ (optionalPlugins [ - neo-tree-nvim - dial-nvim - vimtex - telescope-nvim - nvim-biscuits - crates-nvim - ]); - - plugins.treesitter.enable = true; - - plugins.lz-n = { - enable = true; - plugins = [ - # enabled, on keys - { - __unkeyed-1 = "neo-tree.nvim"; - enabled = '' + plugins = [ + # enabled, on keys as rawLua + { + __unkeyed-1 = "neo-tree.nvim"; + enabled = '' + function() + return true + end + ''; + keys = [ + { + __unkeyed-1 = "ft"; + __unkeyed-2 = "Neotree toggle"; + desc = "NeoTree toggle"; + } + ]; + after = # lua + '' function() - return true + require("neo-tree").setup() end ''; - keys = [ - { - __unkeyed-1 = "ft"; - __unkeyed-2 = "Neotree toggle"; - desc = "NeoTree toggle"; - } - ]; - after = # lua - '' - function() - require("neo-tree").setup() - end - ''; - } - # on keys as list of str and rawLua - { - __unkeyed-1 = "dial.nvim"; - keys = [ - "" - { __raw = "{ ''; mode = 'n' }"; } - ]; - } - # beforeAll, before, on filetype - { - __unkeyed-1 = "vimtex"; - ft = [ "plaintex" ]; - beforeAll = # lua - '' - function() - vim.g.vimtex_compiler_method = "latexrun" - end - ''; - before = # lua - '' - function() - vim.g.vimtex_compiler_method = "latexmk" - end - ''; - } - # On event - { - __unkeyed-1 = "nvim-biscuits"; - event.__raw = "{ 'BufEnter *.lua' }"; - after.__raw = '' + } + ]; + }; + }; + + example-multiple-plugin = + { pkgs, lib, ... }: + { + extraPlugins = + with pkgs.vimPlugins; + [ onedarker-nvim ] + ++ (optionalPlugins [ + neo-tree-nvim + dial-nvim + vimtex + telescope-nvim + nvim-biscuits + crates-nvim + ]); + + plugins.treesitter.enable = true; + + plugins.lz-n = { + enable = true; + plugins = [ + # enabled, on keys + { + __unkeyed-1 = "neo-tree.nvim"; + enabled = '' + function() + return true + end + ''; + keys = [ + { + __unkeyed-1 = "ft"; + __unkeyed-2 = "Neotree toggle"; + desc = "NeoTree toggle"; + } + ]; + after = # lua + '' function() - require('nvim-biscuits').setup({}) + require("neo-tree").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", - } + } + # on keys as list of str and rawLua + { + __unkeyed-1 = "dial.nvim"; + keys = [ + "" + { __raw = "{ ''; mode = 'n' }"; } + ]; + } + # beforeAll, before, on filetype + { + __unkeyed-1 = "vimtex"; + ft = [ "plaintex" ]; + beforeAll = # lua + '' + function() + vim.g.vimtex_compiler_method = "latexrun" + 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", + } + ''; + } + ]; }; - }; + }; } diff --git a/tests/test-sources/plugins/telescope/default.nix b/tests/test-sources/plugins/telescope/default.nix index 15d27607..5b40bdce 100644 --- a/tests/test-sources/plugins/telescope/default.nix +++ b/tests/test-sources/plugins/telescope/default.nix @@ -18,18 +18,16 @@ }; }; - combine-plugins.module = - { config, ... }: - { - plugins.telescope.enable = true; + combine-plugins = { + plugins.telescope.enable = true; - performance.combinePlugins.enable = true; + performance.combinePlugins.enable = true; - extraConfigLuaPost = # lua - '' - -- I don't know how run telescope properly in test environment, - -- 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") - ''; - }; + extraConfigLuaPost = # lua + '' + -- I don't know how run telescope properly in test environment, + -- 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") + ''; + }; } diff --git a/tests/test-sources/plugins/utils/firenvim.nix b/tests/test-sources/plugins/utils/firenvim.nix index 029264b2..f82303d8 100644 --- a/tests/test-sources/plugins/utils/firenvim.nix +++ b/tests/test-sources/plugins/utils/firenvim.nix @@ -26,7 +26,7 @@ }; }; - check-alias.module = + check-alias = { config, ... }: { assertions = [