From fcc4259cdbcb76138b48ed36b4f41c521910db0d Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 8 Jan 2025 15:24:04 +0000 Subject: [PATCH] treewide: stub tests (#6275) * ranger: stub tests * alacritty: stub tests * broot: stub tests * zsh: stub tests * vim-vint: stub tests --- modules/programs/ranger.nix | 2 +- tests/modules/programs/alacritty/default.nix | 2 +- .../programs/alacritty/example-settings.nix | 2 ++ .../programs/alacritty/settings-merging.nix | 2 ++ .../{toml_config.nix => toml-config.nix} | 2 ++ tests/modules/programs/broot/broot.nix | 5 +++++ .../modules/programs/ranger/configuration.nix | 2 ++ .../programs/vim-vint/basic-configuration.nix | 4 +++- .../programs/zsh/history-ignore-pattern.nix | 7 ++---- .../programs/zsh/history-path-new-custom.nix | 8 +++---- .../programs/zsh/history-path-new-default.nix | 8 +++---- .../programs/zsh/history-path-old-custom.nix | 8 +++---- .../programs/zsh/history-path-old-default.nix | 8 +++---- .../programs/zsh/history-substring-search.nix | 8 +++---- tests/modules/programs/zsh/prezto.nix | 17 +++----------- .../programs/zsh/session-variables.nix | 8 +++---- .../programs/zsh/syntax-highlighting.nix | 8 +++---- tests/modules/programs/zsh/zsh-abbr.nix | 4 ++-- tests/modules/programs/zsh/zsh-stubs.nix | 22 +++++++++++++++++++ 19 files changed, 68 insertions(+), 59 deletions(-) rename tests/modules/programs/alacritty/{toml_config.nix => toml-config.nix} (94%) create mode 100644 tests/modules/programs/zsh/zsh-stubs.nix diff --git a/modules/programs/ranger.nix b/modules/programs/ranger.nix index 63d33fad319d..378db5f3b596 100644 --- a/modules/programs/ranger.nix +++ b/modules/programs/ranger.nix @@ -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; }); diff --git a/tests/modules/programs/alacritty/default.nix b/tests/modules/programs/alacritty/default.nix index e5445439d730..7f70628b2e35 100644 --- a/tests/modules/programs/alacritty/default.nix +++ b/tests/modules/programs/alacritty/default.nix @@ -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; } diff --git a/tests/modules/programs/alacritty/example-settings.nix b/tests/modules/programs/alacritty/example-settings.nix index c8ecb206c8ea..ccda3b2c5706 100644 --- a/tests/modules/programs/alacritty/example-settings.nix +++ b/tests/modules/programs/alacritty/example-settings.nix @@ -20,6 +20,8 @@ }; }; + test.stubs = { alacritty = { }; }; + nmt.script = '' assertFileContent \ home-files/.config/alacritty/alacritty.toml \ diff --git a/tests/modules/programs/alacritty/settings-merging.nix b/tests/modules/programs/alacritty/settings-merging.nix index e08c96ebc833..1d47b77a6745 100644 --- a/tests/modules/programs/alacritty/settings-merging.nix +++ b/tests/modules/programs/alacritty/settings-merging.nix @@ -28,6 +28,8 @@ }; }; + test.stubs = { alacritty = { }; }; + nmt.script = '' assertFileContent \ home-files/.config/alacritty/alacritty.toml \ diff --git a/tests/modules/programs/alacritty/toml_config.nix b/tests/modules/programs/alacritty/toml-config.nix similarity index 94% rename from tests/modules/programs/alacritty/toml_config.nix rename to tests/modules/programs/alacritty/toml-config.nix index 7094f9a9ddbc..8235d44c2927 100644 --- a/tests/modules/programs/alacritty/toml_config.nix +++ b/tests/modules/programs/alacritty/toml-config.nix @@ -25,6 +25,8 @@ }; }; + test.stubs = { alacritty = { }; }; + nmt.script = '' assertFileContent \ home-files/.config/alacritty/alacritty.toml \ diff --git a/tests/modules/programs/broot/broot.nix b/tests/modules/programs/broot/broot.nix index 17577f6f7e39..8bb7c02c40b4 100644 --- a/tests/modules/programs/broot/broot.nix +++ b/tests/modules/programs/broot/broot.nix @@ -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' diff --git a/tests/modules/programs/ranger/configuration.nix b/tests/modules/programs/ranger/configuration.nix index 5d534e49c140..90541ac32a20 100644 --- a/tests/modules/programs/ranger/configuration.nix +++ b/tests/modules/programs/ranger/configuration.nix @@ -31,6 +31,8 @@ ]; }; + test.stubs = { ranger = { }; }; + nmt.script = '' assertFileExists home-files/.config/ranger/rc.conf assertFileContent home-files/.config/ranger/rc.conf \ diff --git a/tests/modules/programs/vim-vint/basic-configuration.nix b/tests/modules/programs/vim-vint/basic-configuration.nix index 59bfafa5a718..2e538f37f486 100644 --- a/tests/modules/programs/vim-vint/basic-configuration.nix +++ b/tests/modules/programs/vim-vint/basic-configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, xdg, ... }: +{ ... }: { programs.vim-vint = { @@ -19,6 +19,8 @@ }; }; + test.stubs = { vim-vint = { }; }; + nmt.script = '' assertFileContent home-files/.config/.vintrc.yaml ${ ./basic-configuration.yaml diff --git a/tests/modules/programs/zsh/history-ignore-pattern.nix b/tests/modules/programs/zsh/history-ignore-pattern.nix index 68be58fe8656..49865e84668e 100644 --- a/tests/modules/programs/zsh/history-ignore-pattern.nix +++ b/tests/modules/programs/zsh/history-ignore-pattern.nix @@ -1,9 +1,8 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ ... }: { imports = [ + ./zsh-stubs.nix ({ ... }: { config.programs.zsh.history.ignorePatterns = [ "echo *" ]; }) ({ ... }: { config.programs.zsh.history.ignorePatterns = [ "rm *" ]; }) ]; @@ -11,8 +10,6 @@ with lib; config = { programs.zsh.enable = true; - test.stubs.zsh = { }; - nmt.script = '' assertFileContains home-files/.zshrc "HISTORY_IGNORE='(echo *|rm *)'" ''; diff --git a/tests/modules/programs/zsh/history-path-new-custom.nix b/tests/modules/programs/zsh/history-path-new-custom.nix index 1a691f1ca6c7..ee6deb88396d 100644 --- a/tests/modules/programs/zsh/history-path-new-custom.nix +++ b/tests/modules/programs/zsh/history-path-new-custom.nix @@ -1,8 +1,8 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ ... }: { + imports = [ ./zsh-stubs.nix ]; + config = { home.stateVersion = "20.03"; programs.zsh = { @@ -10,8 +10,6 @@ with lib; history.path = "$HOME/some/directory/zsh_history"; }; - test.stubs.zsh = { }; - nmt.script = '' assertFileRegex home-files/.zshrc '^HISTFILE="$HOME/some/directory/zsh_history"$' ''; diff --git a/tests/modules/programs/zsh/history-path-new-default.nix b/tests/modules/programs/zsh/history-path-new-default.nix index 06fe88d06ca3..3ead97597f0d 100644 --- a/tests/modules/programs/zsh/history-path-new-default.nix +++ b/tests/modules/programs/zsh/history-path-new-default.nix @@ -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"$' ''; diff --git a/tests/modules/programs/zsh/history-path-old-custom.nix b/tests/modules/programs/zsh/history-path-old-custom.nix index 42a85d00472f..25a2babf5c19 100644 --- a/tests/modules/programs/zsh/history-path-old-custom.nix +++ b/tests/modules/programs/zsh/history-path-old-custom.nix @@ -1,8 +1,8 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ ... }: { + imports = [ ./zsh-stubs.nix ]; + config = { home.stateVersion = "19.09"; programs.zsh = { @@ -10,8 +10,6 @@ with lib; history.path = "some/directory/zsh_history"; }; - test.stubs.zsh = { }; - nmt.script = '' assertFileRegex home-files/.zshrc '^HISTFILE="$HOME/some/directory/zsh_history"$' ''; diff --git a/tests/modules/programs/zsh/history-path-old-default.nix b/tests/modules/programs/zsh/history-path-old-default.nix index 490a2715d8fa..b988ddb62c4f 100644 --- a/tests/modules/programs/zsh/history-path-old-default.nix +++ b/tests/modules/programs/zsh/history-path-old-default.nix @@ -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"$' ''; diff --git a/tests/modules/programs/zsh/history-substring-search.nix b/tests/modules/programs/zsh/history-substring-search.nix index 10560b9fa69f..a5f28b724f47 100644 --- a/tests/modules/programs/zsh/history-substring-search.nix +++ b/tests/modules/programs/zsh/history-substring-search.nix @@ -1,8 +1,8 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ ... }: { + imports = [ ./zsh-stubs.nix ]; + config = { programs.zsh = { enable = true; @@ -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$" diff --git a/tests/modules/programs/zsh/prezto.nix b/tests/modules/programs/zsh/prezto.nix index 922112ef9e9d..7ce60906301a 100644 --- a/tests/modules/programs/zsh/prezto.nix +++ b/tests/modules/programs/zsh/prezto.nix @@ -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 diff --git a/tests/modules/programs/zsh/session-variables.nix b/tests/modules/programs/zsh/session-variables.nix index f6f795f79c88..45c63d236158 100644 --- a/tests/modules/programs/zsh/session-variables.nix +++ b/tests/modules/programs/zsh/session-variables.nix @@ -1,8 +1,8 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ config, ... }: { + imports = [ ./zsh-stubs.nix ]; + config = { programs.zsh = { enable = true; @@ -13,8 +13,6 @@ with lib; }; }; - test.stubs.zsh = { }; - nmt.script = '' assertFileExists home-files/.zshenv assertFileRegex home-files/.zshenv 'export V1="v1"' diff --git a/tests/modules/programs/zsh/syntax-highlighting.nix b/tests/modules/programs/zsh/syntax-highlighting.nix index 052b228bd989..2bd581473a76 100644 --- a/tests/modules/programs/zsh/syntax-highlighting.nix +++ b/tests/modules/programs/zsh/syntax-highlighting.nix @@ -1,8 +1,8 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ pkgs, ... }: { + imports = [ ./zsh-stubs.nix ]; + config = { programs.zsh = { enable = true; @@ -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)" diff --git a/tests/modules/programs/zsh/zsh-abbr.nix b/tests/modules/programs/zsh/zsh-abbr.nix index 7e8370d00a3f..f08345e05bc0 100644 --- a/tests/modules/programs/zsh/zsh-abbr.nix +++ b/tests/modules/programs/zsh/zsh-abbr.nix @@ -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 diff --git a/tests/modules/programs/zsh/zsh-stubs.nix b/tests/modules/programs/zsh/zsh-stubs.nix new file mode 100644 index 000000000000..d9e275aab19b --- /dev/null +++ b/tests/modules/programs/zsh/zsh-stubs.nix @@ -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 = { }; + }; +}