From 5127636f14bd7a8c608a4c6f4e3adfa046478ace Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Fri, 10 Mar 2023 10:23:24 +0100 Subject: [PATCH] tests/plugins: refactor --- flake.nix | 3 +- modules/autocmd.nix | 2 +- tests/checks.nix | 25 -- tests/default.nix | 16 + tests/fetch-tests.nix | 67 ++++ tests/flake.lock | 334 ------------------ tests/flake.nix | 318 ----------------- tests/plugins/default.nix | 23 -- tests/plugins/nvim-lsp.nix | 39 -- lib/check.nix => tests/test-derivation.nix | 28 +- .../example-configurations/issues.nix | 143 ++++++++ tests/test-sources/examples.nix | 12 + tests/test-sources/modules/autocmd.nix | 15 + tests/test-sources/modules/highlight.nix | 8 + tests/test-sources/modules/keymaps.nix | 5 + .../plugins/colorschemes/gruvbox.nix | 5 + .../plugins/colorschemes}/tokyonight.nix | 5 + .../plugins/completion}/lspkind.nix | 11 + .../plugins/completion}/nvim-cmp.nix | 0 .../plugins/languages}/rust-tools.nix | 0 .../plugins/languages}/sniprun.nix | 0 .../plugins/languages/treesitter.nix | 29 ++ tests/{ => test-sources}/plugins/null-ls.nix | 10 + .../plugins/nvim-lsp}/inc-rename.nix | 0 .../plugins/nvim-lsp/lsp-lines.nix | 5 + .../plugins/nvim-lsp/nvim-lsp.nix | 71 ++++ .../plugins/nvim-lsp}/trouble.nix | 9 + .../plugins/pluginmanagers}/packer.nix | 0 .../plugins/ui}/noice.nix | 0 .../plugins/utils}/barbar.nix | 0 .../plugins/utils}/neo-tree.nix | 0 .../plugins/utils}/netman.nix | 0 .../plugins/utils}/nvim-osc52.nix | 0 .../plugins/utils}/nvim-tree.nix | 0 tests/test-sources/plugins/utils/sniprun.nix | 46 +++ .../plugins/utils}/todo-comments.nix | 0 .../plugins/utils}/vim-bbye.nix | 0 37 files changed, 485 insertions(+), 744 deletions(-) delete mode 100644 tests/checks.nix create mode 100644 tests/default.nix create mode 100644 tests/fetch-tests.nix delete mode 100644 tests/flake.lock delete mode 100644 tests/flake.nix delete mode 100644 tests/plugins/default.nix delete mode 100644 tests/plugins/nvim-lsp.nix rename lib/check.nix => tests/test-derivation.nix (51%) create mode 100644 tests/test-sources/example-configurations/issues.nix create mode 100644 tests/test-sources/examples.nix create mode 100644 tests/test-sources/modules/autocmd.nix create mode 100644 tests/test-sources/modules/highlight.nix create mode 100644 tests/test-sources/modules/keymaps.nix create mode 100644 tests/test-sources/plugins/colorschemes/gruvbox.nix rename tests/{plugins => test-sources/plugins/colorschemes}/tokyonight.nix (90%) rename tests/{plugins => test-sources/plugins/completion}/lspkind.nix (69%) rename tests/{plugins => test-sources/plugins/completion}/nvim-cmp.nix (100%) rename tests/{plugins => test-sources/plugins/languages}/rust-tools.nix (100%) rename tests/{plugins => test-sources/plugins/languages}/sniprun.nix (100%) create mode 100644 tests/test-sources/plugins/languages/treesitter.nix rename tests/{ => test-sources}/plugins/null-ls.nix (71%) rename tests/{plugins => test-sources/plugins/nvim-lsp}/inc-rename.nix (100%) create mode 100644 tests/test-sources/plugins/nvim-lsp/lsp-lines.nix create mode 100644 tests/test-sources/plugins/nvim-lsp/nvim-lsp.nix rename tests/{plugins => test-sources/plugins/nvim-lsp}/trouble.nix (90%) rename tests/{plugins => test-sources/plugins/pluginmanagers}/packer.nix (100%) rename tests/{plugins => test-sources/plugins/ui}/noice.nix (100%) rename tests/{plugins => test-sources/plugins/utils}/barbar.nix (100%) rename tests/{plugins => test-sources/plugins/utils}/neo-tree.nix (100%) rename tests/{plugins => test-sources/plugins/utils}/netman.nix (100%) rename tests/{plugins => test-sources/plugins/utils}/nvim-osc52.nix (100%) rename tests/{plugins => test-sources/plugins/utils}/nvim-tree.nix (100%) create mode 100644 tests/test-sources/plugins/utils/sniprun.nix rename tests/{plugins => test-sources/plugins/utils}/todo-comments.nix (100%) rename tests/{plugins => test-sources/plugins/utils}/vim-bbye.nix (100%) diff --git a/flake.nix b/flake.nix index d92e4a336e..edd80292d5 100644 --- a/flake.nix +++ b/flake.nix @@ -67,8 +67,9 @@ extractRustAnalyzerPkg = pkgs.callPackage extractRustAnalyzer {}; in { checks = - (import ./tests/checks.nix { + (import ./tests { inherit pkgs; + inherit (pkgs) lib; makeNixvim = self.legacyPackages."${system}".makeNixvim; }) // { diff --git a/modules/autocmd.nix b/modules/autocmd.nix index 7a1c0f6d4d..08eae1f81a 100644 --- a/modules/autocmd.nix +++ b/modules/autocmd.nix @@ -57,7 +57,7 @@ with lib; let { event = [ "BufEnter" "BufWinEnter" ]; pattern = [ "*.c" "*.h" ]; - callback = { __raw = "function() print("This buffer enters") end"; }; + callback = { __raw = "function() print('This buffer enters') end"; }; } ''; diff --git a/tests/checks.nix b/tests/checks.nix deleted file mode 100644 index 13e136f084..0000000000 --- a/tests/checks.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ - makeNixvim, - pkgs, -} @ args: let - tests = import ./plugins {inherit (pkgs) lib;}; - check = import ../lib/check.nix args; - checkConfig = check.checkNvim; -in - # We attempt to build & execute all configurations - builtins.mapAttrs ( - name: config: let - testAttributes = - if builtins.hasAttr "tests" config - then config.tests - else { - dontRun = false; - }; - nvim = makeNixvim (pkgs.lib.attrsets.filterAttrs (n: _: n != "tests") config); - in - checkConfig { - inherit name nvim; - inherit (testAttributes) dontRun; - } - ) - tests diff --git a/tests/default.nix b/tests/default.nix new file mode 100644 index 0000000000..2f406d4faa --- /dev/null +++ b/tests/default.nix @@ -0,0 +1,16 @@ +{ + makeNixvim, + lib, + pkgs, +}: let + fetchTests = import ./fetch-tests.nix; + mkTestDerivation = import ./test-derivation.nix {inherit pkgs makeNixvim;}; + + # List of files containing configurations + testFiles = fetchTests { + inherit lib pkgs; + root = ./test-sources; + }; +in + # We attempt to build & execute all configurations + builtins.mapAttrs mkTestDerivation testFiles diff --git a/tests/fetch-tests.nix b/tests/fetch-tests.nix new file mode 100644 index 0000000000..893e10b690 --- /dev/null +++ b/tests/fetch-tests.nix @@ -0,0 +1,67 @@ +{ + root, + lib, + pkgs, +}: let + # Handle an entry from readDir and either extract the configuration if its a regular file, + # or continue to recurse if it's a directory. While recursing maintain a list of the traversed + # directories + handleEntry = relativePath: namespace: name: type: let + file = "${root}/${relativePath}/${name}"; + in + if type == "regular" + then [ + { + namespace = namespace ++ [(lib.strings.removeSuffix ".nix" name)]; + cases = import file; + } + ] + else parseDirectories file (namespace ++ [name]); + + # Recurse into all directories, extracting files as we find them. This returs a deeply nested + # list, where each non list element is a set of test cases. + parseDirectories = path: namespace: let + relativePath = lib.removePrefix "${root}" "${path}"; + + children = builtins.readDir path; + childrenFiltered = + lib.attrsets.filterAttrs (n: v: v != "symlink") children; + + childrenRecursed = + lib.attrsets.mapAttrsToList (handleEntry relativePath namespace) childrenFiltered; + in + childrenRecursed; + + # Remove the nesting + testsList = lib.lists.flatten (parseDirectories root []); + + testsListEvaluated = builtins.map ({ + cases, + namespace, + } @ args: + if builtins.isAttrs cases + then args + else { + # cases = cases {inherit pkgs;}; + cases = cases {inherit pkgs;}; + inherit namespace; + }) + testsList; + + # Take a list of test cases (i.e the content of a file) and prepare a test case that can be + # handled by mkTestDerivation + handleTestFile = { + namespace, + cases, + }: + lib.attrsets.mapAttrs' (case: config: { + name = lib.strings.concatStringsSep "-" (namespace ++ [case]); + value = config; + }) + cases; + + # Helper function that calls `//` for each attrset of a list + concatMany = list: lib.lists.foldr lib.mergeAttrs {} list; + # An attrset of 'test-name' -> 'test-config' +in + concatMany (builtins.map handleTestFile testsListEvaluated) diff --git a/tests/flake.lock b/tests/flake.lock deleted file mode 100644 index 1c97a1f147..0000000000 --- a/tests/flake.lock +++ /dev/null @@ -1,334 +0,0 @@ -{ - "nodes": { - "beautysh": { - "inputs": { - "nixpkgs": [ - "nixvim", - "nixpkgs" - ], - "poetry2nix": "poetry2nix", - "utils": "utils" - }, - "locked": { - "lastModified": 1669854260, - "narHash": "sha256-Z8NAL3g4i5LAhxveNGJhrVDHxIBbUf1lVIy/Thr2RMU=", - "owner": "lovesegfault", - "repo": "beautysh", - "rev": "d616eb8d9d05ee4fb33de9c5521d99c3f0695d52", - "type": "github" - }, - "original": { - "owner": "lovesegfault", - "repo": "beautysh", - "type": "github" - } - }, - "beautysh_2": { - "inputs": { - "nixpkgs": [ - "nixvim-stable", - "nixpkgs" - ], - "poetry2nix": "poetry2nix_2", - "utils": "utils_2" - }, - "locked": { - "lastModified": 1669854260, - "narHash": "sha256-Z8NAL3g4i5LAhxveNGJhrVDHxIBbUf1lVIy/Thr2RMU=", - "owner": "lovesegfault", - "repo": "beautysh", - "rev": "d616eb8d9d05ee4fb33de9c5521d99c3f0695d52", - "type": "github" - }, - "original": { - "owner": "lovesegfault", - "repo": "beautysh", - "type": "github" - } - }, - "build-ts": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1669771646, - "narHash": "sha256-IfH9zCq0+QpAB8D1ClhISfWcR59mSDsi91/2NW0RWfs=", - "owner": "pta2002", - "repo": "build-ts-grammar.nix", - "rev": "bba8a5b14a4632f25411dbf0fb01de69e999ce82", - "type": "github" - }, - "original": { - "owner": "pta2002", - "repo": "build-ts-grammar.nix", - "type": "github" - } - }, - "flake-utils": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_3": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_4": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "gleam": { - "flake": false, - "locked": { - "lastModified": 1672454845, - "narHash": "sha256-h/5SpMD725BasD2+5J0B7OCDzoWlDBGDm7ywTEYmQbk=", - "owner": "gleam-lang", - "repo": "tree-sitter-gleam", - "rev": "3eb2e1783f3bf6f85c16cdd150e2f256b2f6844e", - "type": "github" - }, - "original": { - "owner": "gleam-lang", - "repo": "tree-sitter-gleam", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1671108576, - "narHash": "sha256-6ggOL6KoaELNA1562tnPjtAnQ9SwsKRTgeuaXvPzCwI=", - "path": "/nix/store/iscn1qzhdwvb3mkr5kvsy9gvyhkdnzl3-source", - "rev": "0f5996b524c91677891a432cc99c7567c7c402b1", - "type": "path" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "nixpkgs-stable": { - "locked": { - "lastModified": 1672580127, - "narHash": "sha256-3lW3xZslREhJogoOkjeZtlBtvFMyxHku7I/9IVehhT8=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "0874168639713f547c05947c76124f78441ea46c", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-22.05", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1671108576, - "narHash": "sha256-6ggOL6KoaELNA1562tnPjtAnQ9SwsKRTgeuaXvPzCwI=", - "path": "/nix/store/iscn1qzhdwvb3mkr5kvsy9gvyhkdnzl3-source", - "rev": "0f5996b524c91677891a432cc99c7567c7c402b1", - "type": "path" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "nixpkgs_3": { - "locked": { - "lastModified": 1673606088, - "narHash": "sha256-wdYD41UwNwPhTdMaG0AIe7fE1bAdyHe6bB4HLUqUvck=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "37b97ae3dd714de9a17923d004a2c5b5543dfa6d", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "nixvim": { - "inputs": { - "beautysh": "beautysh", - "flake-utils": "flake-utils_3", - "nixpkgs": "nixpkgs_3" - }, - "locked": { - "lastModified": 0, - "narHash": "sha256-7N6OttwH7E7URRmQ79MacpMu4eSzxYlRgW06FOP/lWg=", - "path": "/nix/store/s8ql6s1cwxm1ah1pi4y6h4xv2mz2j4v1-source", - "type": "path" - }, - "original": { - "path": "/nix/store/s8ql6s1cwxm1ah1pi4y6h4xv2mz2j4v1-source", - "type": "path" - } - }, - "nixvim-stable": { - "inputs": { - "beautysh": "beautysh_2", - "flake-utils": "flake-utils_4", - "nixpkgs": [ - "nixpkgs-stable" - ] - }, - "locked": { - "lastModified": 0, - "narHash": "sha256-7N6OttwH7E7URRmQ79MacpMu4eSzxYlRgW06FOP/lWg=", - "path": "/nix/store/s8ql6s1cwxm1ah1pi4y6h4xv2mz2j4v1-source", - "type": "path" - }, - "original": { - "path": "/nix/store/s8ql6s1cwxm1ah1pi4y6h4xv2mz2j4v1-source", - "type": "path" - } - }, - "poetry2nix": { - "inputs": { - "flake-utils": [ - "nixvim", - "beautysh", - "utils" - ], - "nixpkgs": [ - "nixvim", - "beautysh", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1658665240, - "narHash": "sha256-/wkx7D7enyBPRjIkK0w7QxLQhzEkb3UxNQnjyc3FTUI=", - "owner": "nix-community", - "repo": "poetry2nix", - "rev": "8b8edc85d24661d5a6d0d71d6a7011f3e699780f", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "poetry2nix", - "type": "github" - } - }, - "poetry2nix_2": { - "inputs": { - "flake-utils": [ - "nixvim-stable", - "beautysh", - "utils" - ], - "nixpkgs": [ - "nixvim-stable", - "beautysh", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1658665240, - "narHash": "sha256-/wkx7D7enyBPRjIkK0w7QxLQhzEkb3UxNQnjyc3FTUI=", - "owner": "nix-community", - "repo": "poetry2nix", - "rev": "8b8edc85d24661d5a6d0d71d6a7011f3e699780f", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "poetry2nix", - "type": "github" - } - }, - "root": { - "inputs": { - "build-ts": "build-ts", - "flake-utils": "flake-utils_2", - "gleam": "gleam", - "nixpkgs": "nixpkgs_2", - "nixpkgs-stable": "nixpkgs-stable", - "nixvim": "nixvim", - "nixvim-stable": "nixvim-stable" - } - }, - "utils": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "utils_2": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/tests/flake.nix b/tests/flake.nix deleted file mode 100644 index 49800b54dd..0000000000 --- a/tests/flake.nix +++ /dev/null @@ -1,318 +0,0 @@ -{ - description = "A set of test configurations for nixvim"; - - inputs.flake-utils.url = "github:numtide/flake-utils"; - inputs.nixvim.url = "./.."; - - inputs.build-ts.url = "github:pta2002/build-ts-grammar.nix"; - inputs.gleam.url = "github:gleam-lang/tree-sitter-gleam"; - inputs.gleam.flake = false; - - inputs.nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-22.05"; - inputs.nixvim-stable = { - url = "./.."; - inputs.nixpkgs.follows = "nixpkgs-stable"; - }; - - outputs = { - self, - nixvim, - nixvim-stable, - nixpkgs, - flake-utils, - nixpkgs-stable, - build-ts, - gleam, - ... - }: - (flake-utils.lib.eachDefaultSystem - (system: let - pkgs = import nixpkgs {inherit system;}; - pkgs-stable = import nixpkgs-stable {inherit system;}; - build = nixvim.legacyPackages.${system}.makeNixvim; - build-stable = nixvim-stable.legacyPackages.${system}.makeNixvim; - in rec { - # A plain nixvim configuration - packages = { - plain = build {}; - - # Should print "Hello!" when starting up - hello = build { - extraConfigLua = "print(\"Hello!\")"; - }; - - simple-plugin = build { - extraPlugins = [pkgs.vimPlugins.vim-surround]; - }; - - gruvbox = build { - extraPlugins = [pkgs.vimPlugins.gruvbox]; - colorscheme = "gruvbox"; - }; - - gruvbox-module = build { - colorschemes.gruvbox.enable = true; - }; - - treesitter = build { - plugins.treesitter.enable = true; - }; - - treesitter-nonix = build { - plugins.treesitter = { - enable = true; - nixGrammars = false; - }; - }; - elixir-ls = build { - plugins.lsp.enable = true; - plugins.lsp.servers.elixirls.enable = true; - }; - - lsp-lines = build-stable { - plugins.lsp-lines.enable = true; - }; - - trouble = build { - plugins.lsp = { - enable = true; - servers.clangd.enable = true; - }; - - plugins.trouble.enable = true; - }; - - beautysh = build { - plugins.null-ls = { - enable = true; - sources.formatting.beautysh.enable = true; - }; - }; - - keymaps = build { - maps.normal."," = "echo \"test\""; - }; - - issue-40 = build-stable { - plugins = { - nix.enable = true; - nvim-autopairs.enable = true; - - lualine = { - enable = true; - - sectionSeparators = { - left = ""; - right = ""; - }; - - componentSeparators = { - left = ""; - right = ""; - }; - - theme = "auto"; - }; - - goyo = { - enable = true; - showLineNumbers = false; - }; - - lsp = { - enable = true; - servers = { - rust-analyzer.enable = true; - rnix-lsp.enable = true; - }; - }; - }; - - options = { - # Indentation - autoindent = true; - tabstop = 4; - shiftwidth = 4; - expandtab = true; - backspace = "indent,eol,start"; - - # Text - showmatch = true; - mouse = "a"; - number = true; - relativenumber = false; - ttyfast = true; - clipboard = "unnamedplus"; - - # Colors - background = "dark"; - termguicolors = true; - }; - }; - - issue-65 = build { - colorschemes.gruvbox = { - enable = true; - contrastLight = "hard"; - contrastDark = "hard"; - }; - - options = { - number = true; - shiftwidth = 2; - tabstop = 2; - guifont = "FiraCode\ Nerd\ Font\ Mono:h14"; - }; - - plugins = { - lsp = { - enable = true; - servers.rnix-lsp.enable = true; - servers.rust-analyzer.enable = true; - servers.jsonls.enable = true; - }; - - nvim-tree = { - enable = true; - openOnSetup = true; - openOnTab = true; - }; - - telescope = { - enable = true; - }; - - nvim-cmp = { - formatting = { - format = '' - require("lspkind").cmp_format({ - mode="symbol", - maxwidth = 50, - ellipsis_char = "..." - }) - ''; - }; - - auto_enable_sources = true; - snippet = { - expand = '' - function(args) - require("luasnip").lsp_expand(args.body) - end - ''; - }; - enable = true; - sources = [ - {name = "nvim_lsp";} - { - name = "luasnip"; - option = { - show_autosnippets = true; - }; - } - {name = "path";} - {name = "buffer";} - ]; - }; - barbar.enable = true; - }; - - globals.mapleader = " "; - extraPlugins = with pkgs.vimPlugins; [ - which-key-nvim - # leap-nvim - vim-flutter - plenary-nvim - fidget-nvim - luasnip - lspkind-nvim - ]; - - # extraConfigLua = (builtins.readFile ./nvim-extra-lua.lua); - }; - - issue-71 = build { - maps.normal."hb" = "lua require('gitsigns').blame_line{full=true}"; - }; - - lspkind = build { - plugins = { - lsp = { - enable = true; - servers.clangd.enable = true; - }; - nvim-cmp.enable = true; - lspkind.enable = true; - }; - }; - - highlight = build { - options.termguicolors = true; - highlight = { - Normal.fg = "#ff0000"; - }; - }; - - autoCmd = build { - autoCmd = [ - { - event = ["BufEnter" "BufWinEnter"]; - pattern = ["*.c" "*.h"]; - command = "echo 'Entering a C or C++ file'"; - } - { - event = "InsertEnter"; - command = "norm zz"; - } - ]; - }; - - ts-custom = build { - plugins.treesitter = { - enable = true; - nixGrammars = true; - grammarPackages = [ - (build-ts.lib.buildGrammar pkgs { - language = "gleam"; - version = "0.25.0"; - source = gleam; - }) - ]; - }; - }; - }; - })) - // { - nixosConfigurations.nixvim-machine = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ({pkgs, ...}: { - environment.systemPackages = [ - (nixvim.build pkgs {colorschemes.gruvbox.enable = true;}) - ]; - }) - ]; - }; - nixosConfigurations.container = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ({pkgs, ...}: { - boot.isContainer = true; - - # Let 'nixos-version --json' know about the Git revision - # of this flake. - system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev; - - imports = [ - nixvim.nixosModules.x86_64-linux.nixvim - ]; - - programs.nixvim = { - enable = true; - colorschemes.gruvbox.enable = true; - }; - }) - ]; - }; - }; -} diff --git a/tests/plugins/default.nix b/tests/plugins/default.nix deleted file mode 100644 index d748344471..0000000000 --- a/tests/plugins/default.nix +++ /dev/null @@ -1,23 +0,0 @@ -{lib}: let - # List of files containing configurations - pluginFiles = - builtins.filter (p: p != "default.nix") (builtins.attrNames (builtins.readDir ./.)); - - /* - Create a list of tests. The list is of the form: - [ { name = "-"; value = { ... }; } ] - */ - makePluginTests = pluginFile: let - pluginName = builtins.head (lib.strings.splitString "." pluginFile); - pluginConfigs = import (./. + "/${pluginFile}"); - in - lib.attrsets.mapAttrsToList (testName: testConfig: { - name = "${pluginName}-${testName}"; - value = testConfig; - }) - pluginConfigs; - - # A list of lists of test cases for each plugin - pluginTests = builtins.map makePluginTests pluginFiles; -in - builtins.listToAttrs (lib.lists.flatten pluginTests) diff --git a/tests/plugins/nvim-lsp.nix b/tests/plugins/nvim-lsp.nix deleted file mode 100644 index be70ad8a13..0000000000 --- a/tests/plugins/nvim-lsp.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ - empty = { - plugins.lsp.enable = true; - }; - - test = { - plugins.lsp = { - enable = true; - - keymaps = { - silent = true; - diagnostic = { - "k" = "goto_prev"; - "j" = "goto_next"; - }; - - lspBuf = { - "gd" = "definition"; - "gD" = "references"; - "gt" = "type_definition"; - "gi" = "implementation"; - "K" = "hover"; - }; - }; - - servers = { - bashls.enable = true; - clangd.enable = true; - nil_ls.enable = true; - rust-analyzer.enable = true; - pylsp = { - enable = true; - filetypes = ["python"]; - autostart = false; - }; - }; - }; - }; -} diff --git a/lib/check.nix b/tests/test-derivation.nix similarity index 51% rename from lib/check.nix rename to tests/test-derivation.nix index 35ee91bbcb..93139a0d60 100644 --- a/lib/check.nix +++ b/tests/test-derivation.nix @@ -1,5 +1,10 @@ -{pkgs, ...}: { - checkNvim = { +{ + pkgs, + makeNixvim, +}: let + # Create a nix derivation from a nixvim executable. + # The build phase simply consists in running the provided nvim binary. + mkTestDerivationFromNvim = { name, nvim, dontRun, @@ -32,4 +37,21 @@ mkdir $out ''; }; -} + + # Create a nix derivation from a nixvim configuration. + # The build phase simply consists in running neovim with the given configuration. + mkTestDerivation = name: config: let + testAttributes = + if builtins.hasAttr "tests" config + then config.tests + else { + dontRun = false; + }; + nvim = makeNixvim (pkgs.lib.attrsets.filterAttrs (n: _: n != "tests") config); + in + mkTestDerivationFromNvim { + inherit name nvim; + inherit (testAttributes) dontRun; + }; +in + mkTestDerivation diff --git a/tests/test-sources/example-configurations/issues.nix b/tests/test-sources/example-configurations/issues.nix new file mode 100644 index 0000000000..50087dcc11 --- /dev/null +++ b/tests/test-sources/example-configurations/issues.nix @@ -0,0 +1,143 @@ +{pkgs}: { + "40" = { + plugins = { + nix.enable = true; + nvim-autopairs.enable = true; + + lualine = { + enable = true; + + sectionSeparators = { + left = ""; + right = ""; + }; + + componentSeparators = { + left = ""; + right = ""; + }; + + theme = "auto"; + }; + + goyo = { + enable = true; + showLineNumbers = false; + }; + + lsp = { + enable = true; + servers = { + rust-analyzer.enable = true; + rnix-lsp.enable = true; + }; + }; + }; + + options = { + # Indentation + autoindent = true; + tabstop = 4; + shiftwidth = 4; + expandtab = true; + backspace = "indent,eol,start"; + + # Text + showmatch = true; + mouse = "a"; + number = true; + relativenumber = false; + ttyfast = true; + clipboard = "unnamedplus"; + + # Colors + background = "dark"; + termguicolors = true; + }; + }; + + "65" = { + colorschemes.gruvbox = { + enable = true; + contrastLight = "hard"; + contrastDark = "hard"; + }; + + options = { + number = true; + shiftwidth = 2; + tabstop = 2; + guifont = "FiraCode\ Nerd\ Font\ Mono:h14"; + }; + + plugins = { + lsp = { + enable = true; + servers.rnix-lsp.enable = true; + servers.rust-analyzer.enable = true; + servers.jsonls.enable = true; + }; + + nvim-tree = { + enable = true; + openOnSetup = true; + openOnTab = true; + }; + + telescope = { + enable = true; + }; + + nvim-cmp = { + formatting = { + format = '' + require("lspkind").cmp_format({ + mode="symbol", + maxwidth = 50, + ellipsis_char = "..." + }) + ''; + }; + + autoEnableSources = true; + snippet = { + expand.__raw = '' + function(args) + require("luasnip").lsp_expand(args.body) + end + ''; + }; + enable = true; + sources = [ + {name = "nvim_lsp";} + { + name = "luasnip"; + option = { + show_autosnippets = true; + }; + } + {name = "path";} + {name = "buffer";} + ]; + }; + barbar.enable = true; + }; + + globals.mapleader = " "; + extraPlugins = with pkgs.vimPlugins; [ + which-key-nvim + # leap-nvim + vim-flutter + plenary-nvim + fidget-nvim + luasnip + lspkind-nvim + ]; + + # extraConfigLua = (builtins.readFile ./nvim-extra-lua.lua); + }; + + "71" = { + maps.normal."hb" = "lua require('gitsigns').blame_line{full=true}"; + }; +} diff --git a/tests/test-sources/examples.nix b/tests/test-sources/examples.nix new file mode 100644 index 0000000000..82c2dcacb4 --- /dev/null +++ b/tests/test-sources/examples.nix @@ -0,0 +1,12 @@ +{pkgs}: { + plain = {}; + + simple-plugin = { + extraPlugins = [pkgs.vimPlugins.vim-surround]; + }; + + gruvbox-raw-method = { + extraPlugins = [pkgs.vimPlugins.gruvbox]; + colorscheme = "gruvbox"; + }; +} diff --git a/tests/test-sources/modules/autocmd.nix b/tests/test-sources/modules/autocmd.nix new file mode 100644 index 0000000000..89db8d6ba9 --- /dev/null +++ b/tests/test-sources/modules/autocmd.nix @@ -0,0 +1,15 @@ +{ + example = { + autoCmd = [ + { + event = ["BufEnter" "BufWinEnter"]; + pattern = ["*.c" "*.h"]; + callback = {__raw = "function() print('This buffer enters') end";}; + } + { + event = "InsertEnter"; + command = "norm zz"; + } + ]; + }; +} diff --git a/tests/test-sources/modules/highlight.nix b/tests/test-sources/modules/highlight.nix new file mode 100644 index 0000000000..f679dc3a3f --- /dev/null +++ b/tests/test-sources/modules/highlight.nix @@ -0,0 +1,8 @@ +{ + example = { + options.termguicolors = true; + highlight = { + Normal.fg = "#ff0000"; + }; + }; +} diff --git a/tests/test-sources/modules/keymaps.nix b/tests/test-sources/modules/keymaps.nix new file mode 100644 index 0000000000..5053e01837 --- /dev/null +++ b/tests/test-sources/modules/keymaps.nix @@ -0,0 +1,5 @@ +{ + example = { + maps.normal."," = "echo \"test\""; + }; +} diff --git a/tests/test-sources/plugins/colorschemes/gruvbox.nix b/tests/test-sources/plugins/colorschemes/gruvbox.nix new file mode 100644 index 0000000000..3d36e43017 --- /dev/null +++ b/tests/test-sources/plugins/colorschemes/gruvbox.nix @@ -0,0 +1,5 @@ +{ + empty = { + colorschemes.gruvbox.enable = true; + }; +} diff --git a/tests/plugins/tokyonight.nix b/tests/test-sources/plugins/colorschemes/tokyonight.nix similarity index 90% rename from tests/plugins/tokyonight.nix rename to tests/test-sources/plugins/colorschemes/tokyonight.nix index 0c01364efc..dec1fdeab3 100644 --- a/tests/plugins/tokyonight.nix +++ b/tests/test-sources/plugins/colorschemes/tokyonight.nix @@ -1,4 +1,9 @@ { + # Empty configuration + empty = { + colorschemes.tokyonight.enable = true; + }; + # All the upstream default options of tokyonight defaults = { colorschemes.tokyonight = { diff --git a/tests/plugins/lspkind.nix b/tests/test-sources/plugins/completion/lspkind.nix similarity index 69% rename from tests/plugins/lspkind.nix rename to tests/test-sources/plugins/completion/lspkind.nix index fb4ecbf84f..db7e781929 100644 --- a/tests/plugins/lspkind.nix +++ b/tests/test-sources/plugins/completion/lspkind.nix @@ -4,6 +4,17 @@ plugins.lspkind.enable = true; }; + example = { + plugins = { + lsp = { + enable = true; + servers.clangd.enable = true; + }; + nvim-cmp.enable = true; + lspkind.enable = true; + }; + }; + # All the upstream default options of lspkind defaults = { plugins.lspkind = { diff --git a/tests/plugins/nvim-cmp.nix b/tests/test-sources/plugins/completion/nvim-cmp.nix similarity index 100% rename from tests/plugins/nvim-cmp.nix rename to tests/test-sources/plugins/completion/nvim-cmp.nix diff --git a/tests/plugins/rust-tools.nix b/tests/test-sources/plugins/languages/rust-tools.nix similarity index 100% rename from tests/plugins/rust-tools.nix rename to tests/test-sources/plugins/languages/rust-tools.nix diff --git a/tests/plugins/sniprun.nix b/tests/test-sources/plugins/languages/sniprun.nix similarity index 100% rename from tests/plugins/sniprun.nix rename to tests/test-sources/plugins/languages/sniprun.nix diff --git a/tests/test-sources/plugins/languages/treesitter.nix b/tests/test-sources/plugins/languages/treesitter.nix new file mode 100644 index 0000000000..2b816e9e33 --- /dev/null +++ b/tests/test-sources/plugins/languages/treesitter.nix @@ -0,0 +1,29 @@ +{pkgs}: { + empty = { + plugins.treesitter.enable = true; + }; + + nonix = { + # TODO: See if we can build parsers (legacy way) + tests.dontRun = true; + plugins.treesitter = { + enable = true; + nixGrammars = false; + }; + }; + + # This needs a custom input + # custom = { + # plugins.treesitter = { + # enable = true; + # nixGrammars = true; + # grammarPackages = [ + # (build-ts.lib.buildGrammar pkgs { + # language = "gleam"; + # version = "0.25.0"; + # source = gleam; + # }) + # ]; + # }; + # }; +} diff --git a/tests/plugins/null-ls.nix b/tests/test-sources/plugins/null-ls.nix similarity index 71% rename from tests/plugins/null-ls.nix rename to tests/test-sources/plugins/null-ls.nix index 865c1f5922..cb38a2bd77 100644 --- a/tests/plugins/null-ls.nix +++ b/tests/test-sources/plugins/null-ls.nix @@ -4,6 +4,16 @@ plugins.null-ls.enable = true; }; + # Broken: + # error: The option `plugins.null-ls.sources.formatting.beautysh' does not exist. + # + # beautysh = { + # plugins.null-ls = { + # enable = true; + # sources.formatting.beautysh.enable = true; + # }; + # }; + default = { plugins.null-ls = { enable = true; diff --git a/tests/plugins/inc-rename.nix b/tests/test-sources/plugins/nvim-lsp/inc-rename.nix similarity index 100% rename from tests/plugins/inc-rename.nix rename to tests/test-sources/plugins/nvim-lsp/inc-rename.nix diff --git a/tests/test-sources/plugins/nvim-lsp/lsp-lines.nix b/tests/test-sources/plugins/nvim-lsp/lsp-lines.nix new file mode 100644 index 0000000000..aefc7b080e --- /dev/null +++ b/tests/test-sources/plugins/nvim-lsp/lsp-lines.nix @@ -0,0 +1,5 @@ +{ + empty = { + plugins.lsp-lines.enable = true; + }; +} diff --git a/tests/test-sources/plugins/nvim-lsp/nvim-lsp.nix b/tests/test-sources/plugins/nvim-lsp/nvim-lsp.nix new file mode 100644 index 0000000000..6b02fc7e33 --- /dev/null +++ b/tests/test-sources/plugins/nvim-lsp/nvim-lsp.nix @@ -0,0 +1,71 @@ +{ + empty = { + plugins.lsp.enable = true; + }; + + example = { + plugins.lsp = { + enable = true; + + keymaps = { + silent = true; + diagnostic = { + "k" = "goto_prev"; + "j" = "goto_next"; + }; + + lspBuf = { + "gd" = "definition"; + "gD" = "references"; + "gt" = "type_definition"; + "gi" = "implementation"; + "K" = "hover"; + }; + }; + + servers = { + bashls.enable = true; + clangd.enable = true; + nil_ls.enable = true; + rust-analyzer.enable = true; + pylsp = { + enable = true; + filetypes = ["python"]; + autostart = false; + }; + }; + }; + }; + + all-servers = { + plugins.lsp = { + enable = true; + + servers = { + astro.enable = true; + bashls.enable = true; + clangd.enable = true; + cssls.enable = true; + dartls.enable = true; + denols.enable = true; + eslint.enable = true; + elixirls.enable = true; + gopls.enable = true; + hls.enable = true; + html.enable = true; + jsonls.enable = true; + lua-ls.enable = true; + nil_ls.enable = true; + pylsp.enable = true; + pyright.enable = true; + rnix-lsp.enable = true; + rust-analyzer.enable = true; + tailwindcss.enable = true; + texlab.enable = true; + tsserver.enable = true; + vuels.enable = true; + # zls.enable = true; Broken as of 03/17/2023 + }; + }; + }; +} diff --git a/tests/plugins/trouble.nix b/tests/test-sources/plugins/nvim-lsp/trouble.nix similarity index 90% rename from tests/plugins/trouble.nix rename to tests/test-sources/plugins/nvim-lsp/trouble.nix index bf43d690e0..507588d964 100644 --- a/tests/plugins/trouble.nix +++ b/tests/test-sources/plugins/nvim-lsp/trouble.nix @@ -4,6 +4,15 @@ plugins.trouble.enable = true; }; + lsp = { + plugins.lsp = { + enable = true; + servers.clangd.enable = true; + }; + + plugins.trouble.enable = true; + }; + # All the upstream default options of trouble defaults = { plugins.trouble = { diff --git a/tests/plugins/packer.nix b/tests/test-sources/plugins/pluginmanagers/packer.nix similarity index 100% rename from tests/plugins/packer.nix rename to tests/test-sources/plugins/pluginmanagers/packer.nix diff --git a/tests/plugins/noice.nix b/tests/test-sources/plugins/ui/noice.nix similarity index 100% rename from tests/plugins/noice.nix rename to tests/test-sources/plugins/ui/noice.nix diff --git a/tests/plugins/barbar.nix b/tests/test-sources/plugins/utils/barbar.nix similarity index 100% rename from tests/plugins/barbar.nix rename to tests/test-sources/plugins/utils/barbar.nix diff --git a/tests/plugins/neo-tree.nix b/tests/test-sources/plugins/utils/neo-tree.nix similarity index 100% rename from tests/plugins/neo-tree.nix rename to tests/test-sources/plugins/utils/neo-tree.nix diff --git a/tests/plugins/netman.nix b/tests/test-sources/plugins/utils/netman.nix similarity index 100% rename from tests/plugins/netman.nix rename to tests/test-sources/plugins/utils/netman.nix diff --git a/tests/plugins/nvim-osc52.nix b/tests/test-sources/plugins/utils/nvim-osc52.nix similarity index 100% rename from tests/plugins/nvim-osc52.nix rename to tests/test-sources/plugins/utils/nvim-osc52.nix diff --git a/tests/plugins/nvim-tree.nix b/tests/test-sources/plugins/utils/nvim-tree.nix similarity index 100% rename from tests/plugins/nvim-tree.nix rename to tests/test-sources/plugins/utils/nvim-tree.nix diff --git a/tests/test-sources/plugins/utils/sniprun.nix b/tests/test-sources/plugins/utils/sniprun.nix new file mode 100644 index 0000000000..6e6da7fb2e --- /dev/null +++ b/tests/test-sources/plugins/utils/sniprun.nix @@ -0,0 +1,46 @@ +{ + empty = { + plugins.sniprun.enable = true; + }; + + default = { + plugins.sniprun = { + enable = true; + selectedInterpreters = []; + replEnable = []; + replDisable = []; + interpreterOptions = {}; + display = ["Classic" "VirtualTextOk"]; + liveDisplay = ["VirtualTextOk"]; + displayOptions = { + terminalWidth = 45; + notificationTimeout = 5; + }; + showNoOutput = ["Classic" "TempFloatingWindow"]; + snipruncolors = { + SniprunVirtualTextOk = { + bg = "#66eeff"; + fg = "#000000"; + ctermbg = "Cyan"; + ctermfg = "Black"; + }; + SniprunFloatingWinOk = { + fg = "#66eeff"; + ctermfg = "Cyan"; + }; + SniprunVirtualTextErr = { + bg = "#881515"; + fg = "#000000"; + ctermbg = "DarkRed"; + ctermfg = "Black"; + }; + SniprunFloatingWinErr = { + fg = "#881515"; + ctermfg = "DarkRed"; + }; + }; + liveModeToggle = "off"; + borders = "single"; + }; + }; +} diff --git a/tests/plugins/todo-comments.nix b/tests/test-sources/plugins/utils/todo-comments.nix similarity index 100% rename from tests/plugins/todo-comments.nix rename to tests/test-sources/plugins/utils/todo-comments.nix diff --git a/tests/plugins/vim-bbye.nix b/tests/test-sources/plugins/utils/vim-bbye.nix similarity index 100% rename from tests/plugins/vim-bbye.nix rename to tests/test-sources/plugins/utils/vim-bbye.nix