2.home-manager/tests/modules/programs/zsh/dotdir.nix
Austin Horstman 9ff467fbe7 tests/zsh: add more path test cases
Test the new lib file path function

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
2025-07-28 14:47:42 -05:00

62 lines
1.7 KiB
Nix

case:
{
config,
lib,
options,
...
}:
let
home = config.home.homeDirectory;
dotDir =
let
subDir = "subdir/subdir2";
in
if case == "absolute" then
"${home}/${subDir}"
else if case == "relative" then
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.";
absDotDir = lib.optionalString (!lib.hasPrefix home dotDir) "${home}/" + dotDir;
relDotDir = lib.removePrefix home dotDir;
in
{
config = {
programs.zsh = {
enable = true;
inherit dotDir;
};
test.stubs.zsh = { };
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[\"']\?"
# check that .zshenv in dotDir exports ZDOTDIR
assertFileRegex home-files/${relDotDir}/.zshenv \
"export ZDOTDIR=[\"']\?${absDotDir}[\"']\?"
'')
];
};
}