1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

fish: add some tests

- If a function is defined, check that the function file exists and
  that the contents matches a given string.

- If no functions exists, the functions folder should not exist.

- Verify plugin functionality.
This commit is contained in:
Ryan Orendorff 2019-09-30 00:11:36 -07:00 committed by Robert Helgesson
parent 108259925a
commit 111011b2c2
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
5 changed files with 118 additions and 0 deletions

View file

@ -29,6 +29,7 @@ import nmt {
./modules/programs/alacritty
./modules/programs/bash
./modules/programs/browserpass
./modules/programs/fish
./modules/programs/git
./modules/programs/gpg
./modules/programs/mbsync

View file

@ -0,0 +1,5 @@
{
fish-functions = ./functions.nix;
fish-no-functions = ./no-functions.nix;
fish-plugins = ./plugins.nix;
}

View file

@ -0,0 +1,32 @@
{ config, lib, pkgs, ... }:
with lib;
let
func = pkgs.writeText "func.fish" ''
function func
echo "Hello"
end
'';
in {
config = {
programs.fish = {
enable = true;
functions = { func = ''echo "Hello"''; };
};
nmt = {
description =
"if fish.function is set, check file exists and contents match";
script = ''
assertFileExists home-files/.config/fish/functions/func.fish
echo ${func}
assertFileContent home-files/.config/fish/functions/func.fish ${func}
'';
};
};
}

View file

@ -0,0 +1,22 @@
{ config, lib, ... }:
with lib;
{
config = {
programs.fish = {
enable = true;
functions = { };
};
nmt = {
description =
"if fish.functions is blank, the functions folder should not exist.";
script = ''
assertPathNotExists home-files/.config/fish/functions
'';
};
};
}

View file

@ -0,0 +1,58 @@
{ config, lib, pkgs, ... }:
with lib;
let
fooPluginSrc = pkgs.writeText "fooPluginSrc" "";
generatedConfdFile = pkgs.writeText "plugin-foo.fish" ''
# Plugin foo
set -l plugin_dir ${fooPluginSrc}
# Set paths to import plugin components
if test -d $plugin_dir"/functions"
set fish_function_path $fish_function_path[1] $plugin_dir"/functions" $fish_function_path[2..-1]
end
if test -d $plugin_dir"/completions"
set fish_complete_path $fish_function_path[1] $plugin_dir"/completions" $fish_complete_path[2..-1]
end
# Source initialization code if it exists.
if test -d $plugin_dir"/conf.d"
source $plugin_dir"/conf.d/*.fish"
end
if test -f $plugin_dir"/key_bindings.fish"
source $plugin_dir"/key_bindings.fish"
end
if test -f $plugin_dir"/init.fish"
source $plugin_dir"/init.fish"
end
'';
in {
config = {
programs.fish = {
enable = true;
plugins = [{
name = "foo";
src = fooPluginSrc;
}];
};
nmt = {
description =
"if fish.plugins set, check conf.d file exists and contents match";
script = ''
assertDirectoryExists home-files/.config/fish/conf.d
assertFileExists home-files/.config/fish/conf.d/plugin-foo.fish
assertFileContent home-files/.config/fish/conf.d/plugin-foo.fish ${generatedConfdFile}
'';
};
};
}