From 7d4acd5a5b0a39994a7d338a93420196b9dcdd72 Mon Sep 17 00:00:00 2001 From: Will Ruggiano Date: Mon, 11 Mar 2024 23:45:12 -0600 Subject: [PATCH] feat: finally get a stupid simple test suite up and running --- .github/workflows/check.yaml | 18 +++ example/flake.lock | 107 +++++------------- example/flake.nix | 24 +++- .../spec/features_spec.lua | 15 +-- flake.nix | 13 --- 5 files changed, 71 insertions(+), 106 deletions(-) create mode 100644 .github/workflows/check.yaml rename spec/init.lua => example/spec/features_spec.lua (63%) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 0000000..18d5ea8 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,18 @@ +name: Build example and run tests + +on: + pull_request: + push: + branches: + - main + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v25 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - run: nix build ./example + - run: nix run ./example#test diff --git a/example/flake.lock b/example/flake.lock index 1cb78f4..5bdd789 100644 --- a/example/flake.lock +++ b/example/flake.lock @@ -21,11 +21,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1683560683, - "narHash": "sha256-XAygPMN5Xnk/W2c1aW0jyEa6lfMDZWlQgiNtmHXytPc=", + "lastModified": 1709336216, + "narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "006c75898cf814ef9497252b022e91c946ba8e17", + "rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2", "type": "github" }, "original": { @@ -39,11 +39,11 @@ "nixpkgs-lib": "nixpkgs-lib_2" }, "locked": { - "lastModified": 1674771137, - "narHash": "sha256-Zpk1GbEsYrqKmuIZkx+f+8pU0qcCYJoSUwNz1Zk+R00=", + "lastModified": 1709336216, + "narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "7c7a8bce3dffe71203dcd4276504d1cb49dfe05f", + "rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2", "type": "github" }, "original": { @@ -53,21 +53,6 @@ } }, "flake-utils": { - "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { "locked": { "lastModified": 1667395993, "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", @@ -120,41 +105,19 @@ "type": "github" } }, - "neovim": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - }, - "locked": { - "dir": "contrib", - "lastModified": 1664910906, - "narHash": "sha256-3m0SawPJcCnKGO6cWbX+iha3+0jhSgd45wJfHqAdy1o=", - "owner": "neovim", - "repo": "neovim", - "rev": "6abb48105135ce3ae7eda22334f8104c5ddf20ce", - "type": "github" - }, - "original": { - "dir": "contrib", - "owner": "neovim", - "repo": "neovim", - "type": "github" - } - }, "neovim-nix": { "inputs": { "flake-parts": "flake-parts_2", "lazy-nvim": "lazy-nvim", - "neovim": "neovim", - "nixpkgs": "nixpkgs_2", + "nixpkgs": "nixpkgs", "pre-commit-nix": "pre-commit-nix" }, "locked": { - "lastModified": 1682901168, - "narHash": "sha256-qMZsmeuaMY6r6tC+q23+cZjpJU1UPFiAWLorPHdO5zE=", + "lastModified": 1710213054, + "narHash": "sha256-ZwA6pVXv/1a/cz28zRi4+qYVMv5YS0JDeJM7tbtvcJA=", "owner": "willruggiano", "repo": "neovim.nix", - "rev": "bbab29e0d361427e50daeb08795791b6c2267edb", + "rev": "286fcc88160eea5b97a1573562b7a9590885a90a", "type": "github" }, "original": { @@ -165,16 +128,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1662019588, - "narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=", + "lastModified": 1706683685, + "narHash": "sha256-FtPPshEpxH/ewBOsdKBNhlsL2MLEFv1hEnQ19f/bFsQ=", "owner": "nixos", "repo": "nixpkgs", - "rev": "2da64a81275b68fdad38af669afeda43d401e94b", + "rev": "5ad9903c16126a7d949101687af0aa589b1d7d3d", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-unstable", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } @@ -182,11 +145,11 @@ "nixpkgs-lib": { "locked": { "dir": "lib", - "lastModified": 1682879489, - "narHash": "sha256-sASwo8gBt7JDnOOstnps90K1wxmVfyhsTPPNTGBPjjg=", + "lastModified": 1709237383, + "narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "da45bf6ec7bbcc5d1e14d3795c025199f28e0de0", + "rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8", "type": "github" }, "original": { @@ -200,11 +163,11 @@ "nixpkgs-lib_2": { "locked": { "dir": "lib", - "lastModified": 1672350804, - "narHash": "sha256-jo6zkiCabUBn3ObuKXHGqqORUMH27gYDIFFfLq5P4wg=", + "lastModified": 1709237383, + "narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "677ed08a50931e38382dbef01cba08a8f7eac8f6", + "rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8", "type": "github" }, "original": { @@ -232,22 +195,6 @@ } }, "nixpkgs_2": { - "locked": { - "lastModified": 1664847737, - "narHash": "sha256-Wxl0CtRH3Vo8+qEZ/PbCcx+9D8wEEi56tJPmROum2ss=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "de80d1d04ee691279e1302a1128c082bbda3ab01", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_3": { "locked": { "lastModified": 1671271357, "narHash": "sha256-xRJdLbWK4v2SewmSStYrcLa0YGJpleufl44A19XSW8k=", @@ -263,13 +210,13 @@ "type": "github" } }, - "nixpkgs_4": { + "nixpkgs_3": { "locked": { - "lastModified": 1684585791, - "narHash": "sha256-lYPboblKrchmbkGMoAcAivomiOscZCjtGxxTSCY51SM=", + "lastModified": 1710159071, + "narHash": "sha256-CT0WKgcmlcWZPZL/sSSICN/Vbm4Of0ZDgxc0GFf6sYU=", "owner": "nixos", "repo": "nixpkgs", - "rev": "eea79d584eff53bf7a76aeb63f8845da6d386129", + "rev": "0fbcc4b2e8571f4af39be41752581ea09dd9ab06", "type": "github" }, "original": { @@ -282,9 +229,9 @@ "pre-commit-nix": { "inputs": { "flake-compat": "flake-compat", - "flake-utils": "flake-utils_2", + "flake-utils": "flake-utils", "gitignore": "gitignore", - "nixpkgs": "nixpkgs_3", + "nixpkgs": "nixpkgs_2", "nixpkgs-stable": "nixpkgs-stable" }, "locked": { @@ -305,7 +252,7 @@ "inputs": { "flake-parts": "flake-parts", "neovim-nix": "neovim-nix", - "nixpkgs": "nixpkgs_4" + "nixpkgs": "nixpkgs_3" } } }, diff --git a/example/flake.nix b/example/flake.nix index 8caaca3..47062e5 100644 --- a/example/flake.nix +++ b/example/flake.nix @@ -27,9 +27,13 @@ lazy = { settings = { - disabled_plugins = [ - "gzip" - ]; + performance.rtp = { + disabled_plugins = [ + "gzip" + "matchit" + "netrwPlugin" + ]; + }; }; plugins = { example = { @@ -39,14 +43,13 @@ priority = 1000; dependencies = { lfs = let - package = pkgs.luajitPackages.lfs; + package = pkgs.luajitPackages.luafilesystem; in { inherit package; init = pkgs.writeTextFile { name = "lfs.lua"; text = '' return function() - -- TODO: It'd be nice to detect this automatically package.cpath = package.cpath .. ";" .. "${package}/lib/lua/5.1/?.so" end ''; @@ -63,7 +66,16 @@ }; }; - packages.default = config.neovim.final; + packages = { + default = config.neovim.final; + test = pkgs.writeShellApplication { + name = "neovim-nix-spec"; + runtimeInputs = [config.neovim.final]; + text = '' + nvim --headless -c "PlenaryBustedDirectory ${./.}/spec { init = '${config.neovim.build.initlua}' }" + ''; + }; + }; }; }; } diff --git a/spec/init.lua b/example/spec/features_spec.lua similarity index 63% rename from spec/init.lua rename to example/spec/features_spec.lua index e1f6f3b..a2f901a 100644 --- a/spec/init.lua +++ b/example/spec/features_spec.lua @@ -1,28 +1,29 @@ describe("neovim", function() it("(env) sets environment variables", function() - assert.equal("true", vim.env.BUILT_WITH_NEOVIM_NIX) + assert.equal("1", vim.env.BUILT_WITH_NEOVIM_NIX) end) it("(paths) adds to PATH", function() - assert.is_executable "stylua" + assert.equal(1, vim.fn.executable "stylua") end) describe("lazy", function() it("(settings) disables builtin plugins", function() - assert.is_true(vim.fn.exists "loaded_gzip" == 0) + assert.equal(0, vim.fn.exists "loaded_gzip") + assert.equal(0, vim.fn.exists "loaded_matchit") + assert.equal(0, vim.fn.exists "loaded_netrwPlugin") end) describe("plugins", function() local _, example = pcall(require, "example") it("() adds plugins", function() - assert.is_table(package.loaded.example) assert.is_function(example.say_hello) end) it("(dependencies) adds plugin dependencies", function() - assert.is_table(package.loaded.lfs) - assert.is_table(package.loaded.plenary) + assert.is_table(require "lfs") + assert.is_table(require "plenary") end) it("(config) configures plugins", function() @@ -30,7 +31,7 @@ describe("neovim", function() end) it("(paths) add plugin specific paths to PATH", function() - assert.is_executable "luacheck" + assert.equal(1, vim.fn.executable "luacheck") end) end) end) diff --git a/flake.nix b/flake.nix index b905066..0b471ed 100644 --- a/flake.nix +++ b/flake.nix @@ -7,18 +7,6 @@ lazy-nvim.url = "github:folke/lazy.nvim"; lazy-nvim.flake = false; pre-commit-nix.url = "github:cachix/pre-commit-hooks.nix"; - - # FIXME: This would be nice, and also a test of sorts - # example = { - # url = "path:./example"; - # inputs = { - # # FIXME: override for a non-existent input 'nixpkgs' - # # nixpkgs.follows = "nixpkgs"; - # flake-parts.follows = "flake-parts"; - # # FIXME: override for a non-existent input 'neovim-nix' - # # neovim-nix.follows = "self"; - # }; - # }; }; outputs = { @@ -55,7 +43,6 @@ formatter = pkgs.alejandra; packages = { - # example = inputs'.example.packages.default; utils = pkgs.callPackage ./utils.nix {}; };