Skip to content

Commit

Permalink
tests: Implement a way to test nixvim (nix-community#199)
Browse files Browse the repository at this point in the history
The tests can be executed using `nix flake check`, they check that
modules can be built, and they execute in neovim without any errors.

This commit only implements tests for tokyonight-nvim upstream defaults
  • Loading branch information
traxys authored Feb 28, 2023
1 parent 9286738 commit abc2d19
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
};
extractRustAnalyzerPkg = pkgs.callPackage extractRustAnalyzer {};
in {
checks = import ./tests/checks.nix {
inherit pkgs;
makeNixvim = self.legacyPackages."${system}".makeNixvim;
};
packages = {
docs = pkgs.callPackage (import ./docs.nix) {
modules = nixvimModules;
Expand Down
36 changes: 36 additions & 0 deletions tests/checks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
makeNixvim,
pkgs,
}: let
tests = import ./plugins {inherit (pkgs) lib;};
in
# We attempt to build & execute all configurations
builtins.mapAttrs (
name: config: let
nvim = makeNixvim config;
in
pkgs.stdenv.mkDerivation {
name = name;

nativeBuildInputs = [nvim];

dontUnpack = true;
# We need to set HOME because neovim will try to create some files
#
# Because neovim does not return an exitcode when quitting we need to check if there are
# errors on stderr
buildPhase = ''
output=$(HOME=$(realpath .) nvim -mn --headless "+q" 2>&1 >/dev/null)
if [[ -n $output ]]; then
echo "ERROR: $output"
exit 1
fi
'';

# If we don't do this nix is not happy
installPhase = ''
mkdir $out
'';
}
)
tests
23 changes: 23 additions & 0 deletions tests/plugins/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{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 = "<plugin>-<test_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)
31 changes: 31 additions & 0 deletions tests/plugins/tokyonight.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
# All the upstream default options of tokyonight
defaults = {
colorschemes.tokyonight = {
enable = true;

style = "storm";
# Not implemented
# lightStyle = "day";
transparent = false;
terminalColors = true;
styles = {
comments = {italic = true;};
keywords = {italic = true;};
functions = {};
variables = {};
sidebars = "dark";
floats = "dark";
};
sidebars = ["qf" "help"];
dayBrightness = 0.3;
hideInactiveStatusline = false;
dimInactive = false;
lualineBold = false;
# Not implemented
# onColors = {__raw = "function(colors) end";};
# Not implemented
# onHighlights = {__raw = "function(colors) end";};
};
};
}

0 comments on commit abc2d19

Please sign in to comment.