mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
tests/direnv: refactor tests
Consolidate and increase testing scope. Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
63994b71d2
commit
8320333a45
10 changed files with 114 additions and 124 deletions
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
programs.bash.enable = true;
|
|
||||||
programs.direnv.enable = true;
|
|
||||||
|
|
||||||
nmt.script = ''
|
|
||||||
assertFileExists home-files/.bashrc
|
|
||||||
assertFileRegex \
|
|
||||||
home-files/.bashrc \
|
|
||||||
'eval "\$(@direnv@/bin/direnv hook bash)"'
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
106
tests/modules/programs/direnv/basic-config.nix
Normal file
106
tests/modules/programs/direnv/basic-config.nix
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
{ config, pkgs, ... }:
|
||||||
|
let
|
||||||
|
expectedContent = "something important";
|
||||||
|
in
|
||||||
|
{
|
||||||
|
programs = {
|
||||||
|
direnv = {
|
||||||
|
enable = true;
|
||||||
|
silent = true;
|
||||||
|
|
||||||
|
enableBashIntegration = true;
|
||||||
|
enableNushellIntegration = true;
|
||||||
|
enableZshIntegration = true;
|
||||||
|
|
||||||
|
mise = {
|
||||||
|
enable = true;
|
||||||
|
package = config.lib.test.mkStubPackage { name = "mise"; };
|
||||||
|
};
|
||||||
|
|
||||||
|
nix-direnv = {
|
||||||
|
enable = true;
|
||||||
|
package = config.lib.test.mkStubPackage {
|
||||||
|
buildScript = ''
|
||||||
|
mkdir -p $out/share/nix-direnv/
|
||||||
|
echo "use_nix" >> $out/share/nix-direnv/direnvrc
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
stdlib = expectedContent;
|
||||||
|
|
||||||
|
config = {
|
||||||
|
global = {
|
||||||
|
hide_env_diff = true;
|
||||||
|
};
|
||||||
|
whitelist = {
|
||||||
|
prefix = [ "/home/user/projects" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
bash.enable = true;
|
||||||
|
fish.enable = true;
|
||||||
|
nushell.enable = true;
|
||||||
|
zsh.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script =
|
||||||
|
let
|
||||||
|
nushellConfigFile =
|
||||||
|
if pkgs.stdenv.isDarwin && !config.xdg.enable then
|
||||||
|
"home-files/Library/Application Support/nushell/config.nu"
|
||||||
|
else
|
||||||
|
"home-files/.config/nushell/config.nu";
|
||||||
|
in
|
||||||
|
# Bash
|
||||||
|
''
|
||||||
|
# Test basic bash integration
|
||||||
|
assertFileExists home-files/.bashrc
|
||||||
|
assertFileRegex \
|
||||||
|
home-files/.bashrc \
|
||||||
|
'eval "\$(@direnv@/bin/direnv hook bash)"'
|
||||||
|
|
||||||
|
|
||||||
|
# Test nushell integration
|
||||||
|
assertFileExists "${nushellConfigFile}"
|
||||||
|
assertFileRegex "${nushellConfigFile}" '@direnv@/bin/direnv export json'
|
||||||
|
|
||||||
|
# Test creates config file
|
||||||
|
assertFileExists home-files/.config/direnv/direnv.toml
|
||||||
|
assertFileContent \
|
||||||
|
home-files/.config/direnv/direnv.toml \
|
||||||
|
${./toml-config-expected.toml}
|
||||||
|
|
||||||
|
assertFileExists home-files/.config/direnv/lib/hm-nix-direnv.sh
|
||||||
|
assertFileRegex home-files/.config/direnv/lib/hm-nix-direnv.sh \
|
||||||
|
'use_nix'
|
||||||
|
|
||||||
|
assertFileRegex \
|
||||||
|
home-files/.config/direnv/direnvrc \
|
||||||
|
'${expectedContent}'
|
||||||
|
# Test bash integration
|
||||||
|
assertFileRegex home-files/.bashrc \
|
||||||
|
'eval.*direnv hook bash'
|
||||||
|
|
||||||
|
# Test zsh integration
|
||||||
|
assertFileRegex home-files/.zshrc \
|
||||||
|
'eval.*direnv hook zsh'
|
||||||
|
|
||||||
|
# Test fish integration (enabled by default)
|
||||||
|
assertFileRegex home-files/.config/fish/config.fish \
|
||||||
|
'direnv hook fish.*source'
|
||||||
|
|
||||||
|
# Test nushell integration
|
||||||
|
assertFileRegex "${nushellConfigFile}" \
|
||||||
|
'direnv export json'
|
||||||
|
assertFileRegex "${nushellConfigFile}" \
|
||||||
|
'load-env'
|
||||||
|
|
||||||
|
# Test mise integration creates library file
|
||||||
|
assertFileExists home-files/.config/direnv/lib/hm-mise.sh
|
||||||
|
assertFileRegex home-files/.config/direnv/lib/hm-mise.sh \
|
||||||
|
'mise direnv activate'
|
||||||
|
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,3 @@
|
||||||
{
|
{
|
||||||
direnv-bash = ./bash.nix;
|
direnv = ./basic-config.nix;
|
||||||
direnv-mise = ./mise.nix;
|
|
||||||
direnv-nix-direnv = ./nix-direnv.nix;
|
|
||||||
direnv-nushell = ./nushell.nix;
|
|
||||||
direnv-stdlib = ./stdlib.nix;
|
|
||||||
direnv-stdlib-and-nix-direnv = ./stdlib-and-nix-direnv.nix;
|
|
||||||
direnv-silent = ./silent.nix;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
{ config, ... }:
|
|
||||||
|
|
||||||
{
|
|
||||||
programs.bash.enable = true;
|
|
||||||
programs.direnv = {
|
|
||||||
enable = true;
|
|
||||||
mise = {
|
|
||||||
enable = true;
|
|
||||||
package = config.lib.test.mkStubPackage { name = "mise"; };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
nmt.script = ''
|
|
||||||
assertFileExists home-files/.bashrc
|
|
||||||
assertFileExists home-files/.config/direnv/lib/hm-mise.sh
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
{ realPkgs, ... }:
|
|
||||||
|
|
||||||
{
|
|
||||||
programs.bash.enable = true;
|
|
||||||
programs.direnv.enable = true;
|
|
||||||
programs.direnv.nix-direnv.enable = true;
|
|
||||||
|
|
||||||
nixpkgs.overlays = [ (_: _: { inherit (realPkgs) nix-direnv; }) ];
|
|
||||||
|
|
||||||
nmt.script = ''
|
|
||||||
assertFileExists home-files/.bashrc
|
|
||||||
assertFileExists home-files/.config/direnv/lib/hm-nix-direnv.sh
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
{ pkgs, config, ... }:
|
|
||||||
|
|
||||||
{
|
|
||||||
programs.nushell.enable = true;
|
|
||||||
programs.direnv.enable = true;
|
|
||||||
|
|
||||||
nmt.script =
|
|
||||||
let
|
|
||||||
configFile =
|
|
||||||
if pkgs.stdenv.isDarwin && !config.xdg.enable then
|
|
||||||
"home-files/Library/Application Support/nushell/config.nu"
|
|
||||||
else
|
|
||||||
"home-files/.config/nushell/config.nu";
|
|
||||||
in
|
|
||||||
''
|
|
||||||
assertFileExists "${configFile}"
|
|
||||||
assertFileRegex "${configFile}" '@direnv@/bin/direnv export json'
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
{ pkgs, ... }:
|
|
||||||
{
|
|
||||||
programs.bash.enable = true;
|
|
||||||
programs.direnv = {
|
|
||||||
enable = true;
|
|
||||||
silent = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
nmt.script = ''
|
|
||||||
assertFileExists home-files/.config/direnv/direnv.toml
|
|
||||||
assertFileContent \
|
|
||||||
home-files/.config/direnv/direnv.toml \
|
|
||||||
${pkgs.writeText "direnv.toml" ''
|
|
||||||
[global]
|
|
||||||
log_filter = "^$"
|
|
||||||
log_format = "-"
|
|
||||||
''}
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
{ realPkgs, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
expectedContent = "something important";
|
|
||||||
in
|
|
||||||
{
|
|
||||||
programs.bash.enable = true;
|
|
||||||
programs.direnv.enable = true;
|
|
||||||
programs.direnv.nix-direnv.enable = true;
|
|
||||||
programs.direnv.stdlib = expectedContent;
|
|
||||||
|
|
||||||
nixpkgs.overlays = [ (_: _: { inherit (realPkgs) nix-direnv; }) ];
|
|
||||||
|
|
||||||
nmt.script = ''
|
|
||||||
assertFileExists home-files/.bashrc
|
|
||||||
assertFileExists home-files/.config/direnv/lib/hm-nix-direnv.sh
|
|
||||||
assertFileRegex \
|
|
||||||
home-files/.config/direnv/direnvrc \
|
|
||||||
'${expectedContent}'
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
let
|
|
||||||
expectedContent = "something important";
|
|
||||||
in
|
|
||||||
{
|
|
||||||
programs.bash.enable = true;
|
|
||||||
programs.direnv.enable = true;
|
|
||||||
programs.direnv.stdlib = expectedContent;
|
|
||||||
|
|
||||||
nmt.script = ''
|
|
||||||
assertPathNotExists home-files/.config/direnv/lib/hm-nix-direnv.sh
|
|
||||||
assertFileExists home-files/.bashrc
|
|
||||||
assertFileRegex \
|
|
||||||
home-files/.config/direnv/direnvrc \
|
|
||||||
'${expectedContent}'
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
7
tests/modules/programs/direnv/toml-config-expected.toml
Normal file
7
tests/modules/programs/direnv/toml-config-expected.toml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
[global]
|
||||||
|
hide_env_diff = true
|
||||||
|
log_filter = "^$"
|
||||||
|
log_format = "-"
|
||||||
|
|
||||||
|
[whitelist]
|
||||||
|
prefix = ["/home/user/projects"]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue