From 9ff467fbe7d42972068cfcfc9167838e7c66aabc Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Mon, 28 Jul 2025 08:57:14 -0500 Subject: [PATCH] tests/zsh: add more path test cases Test the new lib file path function Signed-off-by: Austin Horstman --- tests/modules/programs/zsh/default.nix | 3 ++ tests/modules/programs/zsh/dotdir.nix | 36 +++++++++++++-------- tests/modules/programs/zsh/history-path.nix | 34 ++++++++++++++++--- 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/tests/modules/programs/zsh/default.nix b/tests/modules/programs/zsh/default.nix index d3e3fdd4..bab5d892 100644 --- a/tests/modules/programs/zsh/default.nix +++ b/tests/modules/programs/zsh/default.nix @@ -4,10 +4,13 @@ zsh-dotdir-absolute = import ./dotdir.nix "absolute"; zsh-dotdir-default = import ./dotdir.nix "default"; zsh-dotdir-relative = import ./dotdir.nix "relative"; + zsh-dotdir-xdg-variable = import ./dotdir.nix "xdg-variable"; zsh-history-ignore-pattern = ./history-ignore-pattern.nix; zsh-history-path-absolute = import ./history-path.nix "absolute"; zsh-history-path-default = import ./history-path.nix "default"; zsh-history-path-relative = import ./history-path.nix "relative"; + zsh-history-path-xdg-variable = import ./history-path.nix "xdg-variable"; + zsh-history-path-zdotdir-variable = import ./history-path.nix "zdotdir-variable"; zsh-history-substring-search = ./history-substring-search.nix; zsh-plugins = ./plugins.nix; zsh-prezto = ./prezto.nix; diff --git a/tests/modules/programs/zsh/dotdir.nix b/tests/modules/programs/zsh/dotdir.nix index 0f4594cc..9df0d309 100644 --- a/tests/modules/programs/zsh/dotdir.nix +++ b/tests/modules/programs/zsh/dotdir.nix @@ -18,6 +18,8 @@ let subDir else if case == "default" then options.programs.zsh.dotDir.default + else if case == "xdg-variable" then + "\${XDG_CONFIG_HOME:-\$HOME/.config}/zsh" else abort "Test condition not provided."; @@ -33,20 +35,28 @@ in test.stubs.zsh = { }; - nmt.script = lib.concatStringsSep "\n" [ - # check dotDir entrypoint exists - "assertFileExists home-files/${relDotDir}/.zshenv" + nmt.script = + if case == "xdg-variable" then + '' + # For XDG variable case, check that shell variables are preserved in the generated shell code + # The fixed implementation should preserve variables without wrapping them in single quotes + assertFileContains home-files/.zshenv 'source ''${XDG_CONFIG_HOME:-''$HOME/.config}/zsh/.zshenv' + '' + else + lib.concatStringsSep "\n" [ + # check dotDir entrypoint exists + "assertFileExists home-files/${relDotDir}/.zshenv" - # for non-default dotDir only: - (lib.optionalString (case != "default") '' - # check .zshenv in homeDirectory sources .zshenv in dotDir - assertFileRegex home-files/.zshenv \ - "source [\"']\?${absDotDir}/.zshenv[\"']\?" + # for non-default dotDir only: + (lib.optionalString (case != "default") '' + # check .zshenv in homeDirectory sources .zshenv in dotDir + assertFileRegex home-files/.zshenv \ + "source [\"']\?${absDotDir}/.zshenv[\"']\?" - # check that .zshenv in dotDir exports ZDOTDIR - assertFileRegex home-files/${relDotDir}/.zshenv \ - "export ZDOTDIR=[\"']\?${absDotDir}[\"']\?" - '') - ]; + # check that .zshenv in dotDir exports ZDOTDIR + assertFileRegex home-files/${relDotDir}/.zshenv \ + "export ZDOTDIR=[\"']\?${absDotDir}[\"']\?" + '') + ]; }; } diff --git a/tests/modules/programs/zsh/history-path.nix b/tests/modules/programs/zsh/history-path.nix index 5db40534..86bd307b 100644 --- a/tests/modules/programs/zsh/history-path.nix +++ b/tests/modules/programs/zsh/history-path.nix @@ -1,5 +1,5 @@ case: -{ config, ... }: +{ config, lib, ... }: let homeDir = config.home.homeDirectory; @@ -20,22 +20,46 @@ let customHistRelPath else if case == "default" then defaultHistPath + else if case == "xdg-variable" then + "\${XDG_STATE_HOME:-\$HOME/.local/state}/zsh/history" + else if case == "zdotdir-variable" then + "\$ZDOTDIR/.zsh_history" else abort "Test condition not provided"; - expectedPath = if case == "default" then defaultHistPath else customHistAbsPath; + expectedPath = + if case == "default" then + defaultHistPath + else if case == "xdg-variable" then + "\${XDG_STATE_HOME:-\$HOME/.local/state}/zsh/history" + else if case == "zdotdir-variable" then + "\$ZDOTDIR/.zsh_history" + else + customHistAbsPath; in { config = { programs.zsh = { enable = true; history.path = testPath; + dotDir = lib.mkIf (case == "zdotdir-variable") "${homeDir}/.config/zsh"; }; test.stubs.zsh = { }; - nmt.script = '' - assertFileRegex home-files/.zshrc '^HISTFILE="${expectedPath}"$' - ''; + nmt.script = + if case == "xdg-variable" then + '' + assertFileContains home-files/.zshrc 'HISTFILE="''${XDG_STATE_HOME:-''$HOME/.local/state}/zsh/history"' + '' + else if case == "zdotdir-variable" then + '' + assertFileContains home-files/.config/zsh/.zshrc 'HISTFILE="$ZDOTDIR/.zsh_history"' + assertFileContains home-files/.config/zsh/.zshenv "export ZDOTDIR=${homeDir}/.config/zsh" + '' + else + '' + assertFileRegex home-files/.zshrc '^HISTFILE="${expectedPath}"$' + ''; }; }