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

[poc] tests/plugins: test package options #2121

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
73 changes: 65 additions & 8 deletions tests/test-sources/plugins/bufferlines/bufferline.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
{ lib, pkgs, ... }:
{
empty = {
plugins.bufferline.enable = true;
};
empty =
{ config, ... }:
{
plugins.bufferline.enable = true;

assertions = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make more sense to test the package existence in our existing empty test cases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's nice to keep the "empty" case simple.

Maybe we should consider adding test.runNvim = false to these assertion-based tests though, since we don't actually need to run neovim if all we care about is the assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, don't need to waste processing time that way if it's just evaluation time testing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes me think we could do with a test.build toggle to completely disable building finalPackage, although we'd probably still want to ensure it is evaluated somehow (just not built)

{
assertion =
config.extraPlugins != [ ]
&& lib.any (
x: lib.trace "${x.pname or ""}" x.pname or null == "bufferline.nvim"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking on noogle, there's also lib.getName, although I think that could fail when encountering submodule-type plugin definitions...

) config.extraPlugins;
message = "bufferline package wasn't found when it was expected";
}
{
assertion =
config.extraPlugins != [ ]
&& lib.any (
x: lib.trace "${x.pname or ""}" x.pname or null == "nvim-web-devicons"
) config.extraPlugins;
message = "nvim-web-devicons package wasn't found when it was expected";
}
];
};

example = {
plugins.bufferline = {
Expand Down Expand Up @@ -124,10 +146,45 @@
};
};

no-packages = {
plugins.bufferline = {
enable = true;
iconsPackage = null;
no-packages =
{ config, ... }:
{
plugins.bufferline = {
enable = true;
iconsPackage = null;
};

assertions = [
{
assertion = lib.all (
x: lib.trace "${x.pname or ""}" x.pname or null != "nvim-web-devicons"
) config.extraPlugins;
message = "nvim-web-devicons package was found when it wasn't expected";
}
];
};

package-overrides =
{ config, ... }:
{
plugins.bufferline = {
enable = true;
iconsPackage = pkgs.vimPlugins.mini-nvim;
};

assertions = [
{
assertion =
config.extraPlugins != [ ]
&& lib.any (x: lib.trace "${x.pname or ""}" x.pname or null == "mini.nvim") config.extraPlugins;
message = "mini-nvim package wasn't found when it was expected";
}
{
assertion = lib.all (
x: lib.trace "${x.pname or ""}" x.pname or null != "nvim-web-devicons"
) config.extraPlugins;
message = "nvim-web-devicons package was found when it wasn't expected";
}
];
};
};
}
12 changes: 11 additions & 1 deletion tests/test-sources/plugins/pluginmanagers/packer.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ lib, pkgs, ... }:
{
# Empty configuration
empty = {
Expand Down Expand Up @@ -136,10 +137,19 @@
};
};

no-packages = {
no-packages = cfg: {
plugins.packer = {
enable = true;
gitPackage = null;
};

assertions = [
{
assertion = lib.all (
x: lib.trace "${x.pname or ""}" x.pname or null != "git"
) cfg.config.extraPackages;
message = "A git package found when it wasn't expected";
}
];
};
}