Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: finally get a stupid simple test suite up and running #4

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -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
107 changes: 27 additions & 80 deletions example/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions example/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@

lazy = {
settings = {
disabled_plugins = [
"gzip"
];
performance.rtp = {
disabled_plugins = [
"gzip"
"matchit"
"netrwPlugin"
];
};
};
plugins = {
example = {
Expand All @@ -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
'';
Expand All @@ -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}' }"
'';
};
};
};
};
}
15 changes: 8 additions & 7 deletions spec/init.lua → example/spec/features_spec.lua
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
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("(<name>) 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()
assert.is_true(vim.g.loaded_example)
end)

it("(paths) add plugin specific paths to PATH", function()
assert.is_executable "luacheck"
assert.equal(1, vim.fn.executable "luacheck")
end)
end)
end)
Expand Down
13 changes: 0 additions & 13 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -55,7 +43,6 @@
formatter = pkgs.alejandra;

packages = {
# example = inputs'.example.packages.default;
utils = pkgs.callPackage ./utils.nix {};
};

Expand Down