Skip to content

Commit

Permalink
treewide: stub tests (#6275)
Browse files Browse the repository at this point in the history
* ranger: stub tests

* alacritty: stub tests

* broot: stub tests

* zsh: stub tests

* vim-vint: stub tests
  • Loading branch information
thiagokokada authored Jan 8, 2025
1 parent 456e599 commit fcc4259
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 59 deletions.
2 changes: 1 addition & 1 deletion modules/programs/ranger.nix
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ in {
config = mkIf cfg.enable (mkMerge [
{
programs.ranger.finalPackage = cfg.package.overrideAttrs (oldAttrs: {
propagatedBuildInputs = oldAttrs.propagatedBuildInputs
propagatedBuildInputs = (oldAttrs.propagatedBuildInputs or [ ])
++ cfg.extraPackages;
});

Expand Down
2 changes: 1 addition & 1 deletion tests/modules/programs/alacritty/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
alacritty-example-settings = ./example-settings.nix;
alacritty-empty-settings = ./empty-settings.nix;
alacritty-merging-settings = ./settings-merging.nix;
alacritty-toml-config = ./toml_config.nix;
alacritty-toml-config = ./toml-config.nix;
}
2 changes: 2 additions & 0 deletions tests/modules/programs/alacritty/example-settings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
};
};

test.stubs = { alacritty = { }; };

nmt.script = ''
assertFileContent \
home-files/.config/alacritty/alacritty.toml \
Expand Down
2 changes: 2 additions & 0 deletions tests/modules/programs/alacritty/settings-merging.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
};
};

test.stubs = { alacritty = { }; };

nmt.script = ''
assertFileContent \
home-files/.config/alacritty/alacritty.toml \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
};
};

test.stubs = { alacritty = { }; };

nmt.script = ''
assertFileContent \
home-files/.config/alacritty/alacritty.toml \
Expand Down
5 changes: 5 additions & 0 deletions tests/modules/programs/broot/broot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
settings.modal = true;
};

tests.stubs = {
broot = { };
hjson = { };
};

nmt.script = ''
assertFileExists home-files/.config/broot/conf.toml
assertFileContains home-files/.config/broot/conf.toml 'modal = true'
Expand Down
2 changes: 2 additions & 0 deletions tests/modules/programs/ranger/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
];
};

test.stubs = { ranger = { }; };

nmt.script = ''
assertFileExists home-files/.config/ranger/rc.conf
assertFileContent home-files/.config/ranger/rc.conf \
Expand Down
4 changes: 3 additions & 1 deletion tests/modules/programs/vim-vint/basic-configuration.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, pkgs, lib, xdg, ... }:
{ ... }:

{
programs.vim-vint = {
Expand All @@ -19,6 +19,8 @@
};
};

test.stubs = { vim-vint = { }; };

nmt.script = ''
assertFileContent home-files/.config/.vintrc.yaml ${
./basic-configuration.yaml
Expand Down
7 changes: 2 additions & 5 deletions tests/modules/programs/zsh/history-ignore-pattern.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
{ config, lib, pkgs, ... }:

with lib;
{ ... }:

{
imports = [
./zsh-stubs.nix
({ ... }: { config.programs.zsh.history.ignorePatterns = [ "echo *" ]; })
({ ... }: { config.programs.zsh.history.ignorePatterns = [ "rm *" ]; })
];

config = {
programs.zsh.enable = true;

test.stubs.zsh = { };

nmt.script = ''
assertFileContains home-files/.zshrc "HISTORY_IGNORE='(echo *|rm *)'"
'';
Expand Down
8 changes: 3 additions & 5 deletions tests/modules/programs/zsh/history-path-new-custom.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{ config, lib, pkgs, ... }:

with lib;
{ ... }:

{
imports = [ ./zsh-stubs.nix ];

config = {
home.stateVersion = "20.03";
programs.zsh = {
enable = true;
history.path = "$HOME/some/directory/zsh_history";
};

test.stubs.zsh = { };

nmt.script = ''
assertFileRegex home-files/.zshrc '^HISTFILE="$HOME/some/directory/zsh_history"$'
'';
Expand Down
8 changes: 3 additions & 5 deletions tests/modules/programs/zsh/history-path-new-default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{ config, lib, pkgs, ... }:

with lib;
{ ... }:

{
imports = [ ./zsh-stubs.nix ];

config = {
home.stateVersion = "20.03";
programs.zsh.enable = true;

test.stubs.zsh = { };

nmt.script = ''
assertFileRegex home-files/.zshrc '^HISTFILE="$HOME/.zsh_history"$'
'';
Expand Down
8 changes: 3 additions & 5 deletions tests/modules/programs/zsh/history-path-old-custom.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{ config, lib, pkgs, ... }:

with lib;
{ ... }:

{
imports = [ ./zsh-stubs.nix ];

config = {
home.stateVersion = "19.09";
programs.zsh = {
enable = true;
history.path = "some/directory/zsh_history";
};

test.stubs.zsh = { };

nmt.script = ''
assertFileRegex home-files/.zshrc '^HISTFILE="$HOME/some/directory/zsh_history"$'
'';
Expand Down
8 changes: 3 additions & 5 deletions tests/modules/programs/zsh/history-path-old-default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{ config, lib, pkgs, ... }:

with lib;
{ ... }:

{
imports = [ ./zsh-stubs.nix ];

config = {
home.stateVersion = "19.03";
programs.zsh.enable = true;

test.stubs.zsh = { };

nmt.script = ''
assertFileRegex home-files/.zshrc '^HISTFILE="$HOME/.zsh_history"$'
'';
Expand Down
8 changes: 3 additions & 5 deletions tests/modules/programs/zsh/history-substring-search.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ config, lib, pkgs, ... }:

with lib;
{ ... }:

{
imports = [ ./zsh-stubs.nix ];

config = {
programs.zsh = {
enable = true;
Expand All @@ -13,8 +13,6 @@ with lib;
};
};

test.stubs.zsh = { };

# Written with regex to ensure we don't end up missing newlines in the future
nmt.script = ''
assertFileRegex home-files/.zshrc "^bindkey \"\^\[\[B\" history-substring-search-down$"
Expand Down
17 changes: 3 additions & 14 deletions tests/modules/programs/zsh/prezto.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
{ config, lib, pkgs, ... }:

with lib;
{ ... }:

{
programs.zsh.prezto.enable = true;
imports = [ ./zsh-stubs.nix ];

test.stubs.zsh-prezto = {
outPath = null;
buildScript = ''
mkdir -p $out/share/zsh-prezto/runcoms
echo '# zprofile' > $out/share/zsh-prezto/runcoms/zprofile
echo '# zlogin' > $out/share/zsh-prezto/runcoms/zlogin
echo '# zlogout' > $out/share/zsh-prezto/runcoms/zlogout
echo '# zshenv' > $out/share/zsh-prezto/runcoms/zshenv
'';
};
programs.zsh.prezto.enable = true;

nmt.script = ''
assertFileExists home-files/.zpreztorc
Expand Down
8 changes: 3 additions & 5 deletions tests/modules/programs/zsh/session-variables.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ config, lib, pkgs, ... }:

with lib;
{ config, ... }:

{
imports = [ ./zsh-stubs.nix ];

config = {
programs.zsh = {
enable = true;
Expand All @@ -13,8 +13,6 @@ with lib;
};
};

test.stubs.zsh = { };

nmt.script = ''
assertFileExists home-files/.zshenv
assertFileRegex home-files/.zshenv 'export V1="v1"'
Expand Down
8 changes: 3 additions & 5 deletions tests/modules/programs/zsh/syntax-highlighting.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ config, lib, pkgs, ... }:

with lib;
{ pkgs, ... }:

{
imports = [ ./zsh-stubs.nix ];

config = {
programs.zsh = {
enable = true;
Expand All @@ -15,8 +15,6 @@ with lib;
};
};

test.stubs.zsh = { };

nmt.script = ''
assertFileContains home-files/.zshrc "source ${pkgs.hello}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
assertFileContains home-files/.zshrc "ZSH_HIGHLIGHT_HIGHLIGHTERS+=(brackets pattern cursor)"
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/programs/zsh/zsh-abbr.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ ... }:

{
imports = [ ./zsh-stubs.nix ];

programs.zsh.zsh-abbr = {
enable = true;
abbreviations = { ga = "git add"; };
};

test.stubs.zsh-abbr = { };

nmt.script = ''
abbreviations=home-files/.config/zsh-abbr/user-abbreviations
Expand Down
22 changes: 22 additions & 0 deletions tests/modules/programs/zsh/zsh-stubs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ ... }:

{
test.stubs = {
hello = { };
nix-zsh-completions = { };
zsh = { };
zsh-abbr = { };
zsh-history-substring-search = { };
zsh-prezto = {
outPath = null;
buildScript = ''
mkdir -p $out/share/zsh-prezto/runcoms
echo '# zprofile' > $out/share/zsh-prezto/runcoms/zprofile
echo '# zlogin' > $out/share/zsh-prezto/runcoms/zlogin
echo '# zlogout' > $out/share/zsh-prezto/runcoms/zlogout
echo '# zshenv' > $out/share/zsh-prezto/runcoms/zshenv
'';
};
zsh-syntax-highlighting = { };
};
}

0 comments on commit fcc4259

Please sign in to comment.